diff --git a/examples/toybox/bow/bow.js b/examples/toybox/bow/bow.js index 44fe33bb31..c04bb7a72c 100644 --- a/examples/toybox/bow/bow.js +++ b/examples/toybox/bow/bow.js @@ -540,6 +540,7 @@ var arrowProperties = { collisionsWillMove: true, ignoreForCollisions: false, + collisionMask: "static,dynamic,otherAvatar", // workaround: not with kinematic --> no collision with bow velocity: releaseVelocity, gravity: ARROW_GRAVITY, lifetime: 10, @@ -612,4 +613,4 @@ }; return new Bow(); -}); \ No newline at end of file +}); diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 4c4786c6a2..c89f764ecb 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1600,7 +1600,7 @@ void Application::paintGL() { Stats::getInstance()->setRenderDetails(renderArgs._details); // Reset the gpu::Context Stages // Back to the default framebuffer; - gpu::doInBatch(renderArgs._context, [=](gpu::Batch& batch) { + gpu::doInBatch(renderArgs._context, [&](gpu::Batch& batch) { batch.resetStages(); }); } @@ -3102,63 +3102,70 @@ void Application::update(float deltaTime) { if (_physicsEnabled) { PerformanceTimer perfTimer("physics"); - - static VectorOfMotionStates motionStates; - _entitySimulation.getObjectsToRemoveFromPhysics(motionStates); - _physicsEngine->removeObjects(motionStates); - - getEntities()->getTree()->withWriteLock([&] { - _entitySimulation.getObjectsToAddToPhysics(motionStates); - _physicsEngine->addObjects(motionStates); - - }); - getEntities()->getTree()->withWriteLock([&] { - _entitySimulation.getObjectsToChange(motionStates); - VectorOfMotionStates stillNeedChange = _physicsEngine->changeObjects(motionStates); - _entitySimulation.setObjectsToChange(stillNeedChange); - }); - - _entitySimulation.applyActionChanges(); - AvatarManager* avatarManager = DependencyManager::get().data(); - avatarManager->getObjectsToRemoveFromPhysics(motionStates); - _physicsEngine->removeObjects(motionStates); - avatarManager->getObjectsToAddToPhysics(motionStates); - _physicsEngine->addObjects(motionStates); - avatarManager->getObjectsToChange(motionStates); - _physicsEngine->changeObjects(motionStates); - myAvatar->prepareForPhysicsSimulation(); - _physicsEngine->forEachAction([&](EntityActionPointer action) { - action->prepareForPhysicsSimulation(); - }); + { + PerformanceTimer perfTimer("updateStates)"); + static VectorOfMotionStates motionStates; + _entitySimulation.getObjectsToRemoveFromPhysics(motionStates); + _physicsEngine->removeObjects(motionStates); - getEntities()->getTree()->withWriteLock([&] { - _physicsEngine->stepSimulation(); - }); - - if (_physicsEngine->hasOutgoingChanges()) { getEntities()->getTree()->withWriteLock([&] { - _entitySimulation.handleOutgoingChanges(_physicsEngine->getOutgoingChanges(), _physicsEngine->getSessionID()); - avatarManager->handleOutgoingChanges(_physicsEngine->getOutgoingChanges()); + _entitySimulation.getObjectsToAddToPhysics(motionStates); + _physicsEngine->addObjects(motionStates); + + }); + getEntities()->getTree()->withWriteLock([&] { + _entitySimulation.getObjectsToChange(motionStates); + VectorOfMotionStates stillNeedChange = _physicsEngine->changeObjects(motionStates); + _entitySimulation.setObjectsToChange(stillNeedChange); }); - auto collisionEvents = _physicsEngine->getCollisionEvents(); - avatarManager->handleCollisionEvents(collisionEvents); + _entitySimulation.applyActionChanges(); - _physicsEngine->dumpStatsIfNecessary(); + avatarManager->getObjectsToRemoveFromPhysics(motionStates); + _physicsEngine->removeObjects(motionStates); + avatarManager->getObjectsToAddToPhysics(motionStates); + _physicsEngine->addObjects(motionStates); + avatarManager->getObjectsToChange(motionStates); + _physicsEngine->changeObjects(motionStates); - if (!_aboutToQuit) { - PerformanceTimer perfTimer("entities"); - // Collision events (and their scripts) must not be handled when we're locked, above. (That would risk - // deadlock.) - _entitySimulation.handleCollisionEvents(collisionEvents); - // NOTE: the getEntities()->update() call below will wait for lock - // and will simulate entity motion (the EntityTree has been given an EntitySimulation). - getEntities()->update(); // update the models... + myAvatar->prepareForPhysicsSimulation(); + _physicsEngine->forEachAction([&](EntityActionPointer action) { + action->prepareForPhysicsSimulation(); + }); + } + { + PerformanceTimer perfTimer("stepSimulation"); + getEntities()->getTree()->withWriteLock([&] { + _physicsEngine->stepSimulation(); + }); + } + { + PerformanceTimer perfTimer("havestChanges"); + if (_physicsEngine->hasOutgoingChanges()) { + getEntities()->getTree()->withWriteLock([&] { + _entitySimulation.handleOutgoingChanges(_physicsEngine->getOutgoingChanges(), _physicsEngine->getSessionID()); + avatarManager->handleOutgoingChanges(_physicsEngine->getOutgoingChanges()); + }); + + auto collisionEvents = _physicsEngine->getCollisionEvents(); + avatarManager->handleCollisionEvents(collisionEvents); + + _physicsEngine->dumpStatsIfNecessary(); + + if (!_aboutToQuit) { + PerformanceTimer perfTimer("entities"); + // Collision events (and their scripts) must not be handled when we're locked, above. (That would risk + // deadlock.) + _entitySimulation.handleCollisionEvents(collisionEvents); + // NOTE: the getEntities()->update() call below will wait for lock + // and will simulate entity motion (the EntityTree has been given an EntitySimulation). + getEntities()->update(); // update the models... + } + + myAvatar->harvestResultsFromPhysicsSimulation(deltaTime); } - - myAvatar->harvestResultsFromPhysicsSimulation(deltaTime); } } @@ -3514,7 +3521,7 @@ int Application::getBoundaryLevelAdjust() const { } PickRay Application::computePickRay(float x, float y) const { - vec2 pickPoint{ x, y }; + vec2 pickPoint { x, y }; PickRay result; if (isHMDMode()) { getApplicationCompositor().computeHmdPickRay(pickPoint, result.origin, result.direction); @@ -3611,7 +3618,7 @@ namespace render { PerformanceTimer perfTimer("worldBox"); auto& batch = *args->_batch; - DependencyManager::get()->bindSimpleProgram(batch); + DependencyManager::get()->bindSimpleProgram(batch); renderWorldBox(batch); } } @@ -3635,10 +3642,15 @@ public: render::ItemID BackgroundRenderData::_item = 0; namespace render { - template <> const ItemKey payloadGetKey(const BackgroundRenderData::Pointer& stuff) { return ItemKey::Builder::background(); } - template <> const Item::Bound payloadGetBound(const BackgroundRenderData::Pointer& stuff) { return Item::Bound(); } - template <> void payloadRender(const BackgroundRenderData::Pointer& background, RenderArgs* args) { + template <> const ItemKey payloadGetKey(const BackgroundRenderData::Pointer& stuff) { + return ItemKey::Builder::background(); + } + template <> const Item::Bound payloadGetBound(const BackgroundRenderData::Pointer& stuff) { + return Item::Bound(); + } + + template <> void payloadRender(const BackgroundRenderData::Pointer& background, RenderArgs* args) { Q_ASSERT(args->_batch); gpu::Batch& batch = *args->_batch; @@ -3646,20 +3658,18 @@ namespace render { auto skyStage = DependencyManager::get()->getSkyStage(); auto backgroundMode = skyStage->getBackgroundMode(); - if (backgroundMode == model::SunSkyStage::NO_BACKGROUND) { - // this line intentionally left blank - } else { - if (backgroundMode == model::SunSkyStage::SKY_BOX) { + switch (backgroundMode) { + case model::SunSkyStage::SKY_BOX: { auto skybox = skyStage->getSkybox(); if (skybox && skybox->getCubemap() && skybox->getCubemap()->isDefined()) { PerformanceTimer perfTimer("skybox"); skybox->render(batch, *(args->_viewFrustum)); - } else { - // If no skybox texture is available, render the SKY_DOME while it loads - backgroundMode = model::SunSkyStage::SKY_DOME; + break; } + // If no skybox texture is available, render the SKY_DOME while it loads } - if (backgroundMode == model::SunSkyStage::SKY_DOME) { + // fall through to next case + case model::SunSkyStage::SKY_DOME: { if (Menu::getInstance()->isOptionChecked(MenuOption::Stars)) { PerformanceTimer perfTimer("stars"); PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), @@ -3725,6 +3735,11 @@ namespace render { } } + break; + case model::SunSkyStage::NO_BACKGROUND: + default: + // this line intentionally left blank + break; } } } diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 3d97d48f90..4983983c02 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -25,7 +25,6 @@ #include #include -#include #include #include #include @@ -96,28 +95,27 @@ void renderWorldBox(gpu::Batch& batch) { geometryCache->renderLine(batch, glm::vec3(-HALF_TREE_SCALE, 0.0f, HALF_TREE_SCALE), glm::vec3(HALF_TREE_SCALE, 0.0f, HALF_TREE_SCALE), GREY); - auto deferredLighting = DependencyManager::get(); - - deferredLighting->renderWireCubeInstance(batch, Transform(), GREY4); + + geometryCache->renderWireCubeInstance(batch, Transform(), GREY4); // Draw meter markers along the 3 axis to help with measuring things const float MARKER_DISTANCE = 1.0f; const float MARKER_RADIUS = 0.05f; transform = Transform().setScale(MARKER_RADIUS); - deferredLighting->renderSolidSphereInstance(batch, transform, RED); + geometryCache->renderSolidSphereInstance(batch, transform, RED); transform = Transform().setTranslation(glm::vec3(MARKER_DISTANCE, 0.0f, 0.0f)).setScale(MARKER_RADIUS); - deferredLighting->renderSolidSphereInstance(batch, transform, RED); + geometryCache->renderSolidSphereInstance(batch, transform, RED); transform = Transform().setTranslation(glm::vec3(0.0f, MARKER_DISTANCE, 0.0f)).setScale(MARKER_RADIUS); - deferredLighting->renderSolidSphereInstance(batch, transform, GREEN); + geometryCache->renderSolidSphereInstance(batch, transform, GREEN); transform = Transform().setTranslation(glm::vec3(0.0f, 0.0f, MARKER_DISTANCE)).setScale(MARKER_RADIUS); - deferredLighting->renderSolidSphereInstance(batch, transform, BLUE); + geometryCache->renderSolidSphereInstance(batch, transform, BLUE); transform = Transform().setTranslation(glm::vec3(MARKER_DISTANCE, 0.0f, MARKER_DISTANCE)).setScale(MARKER_RADIUS); - deferredLighting->renderSolidSphereInstance(batch, transform, GREY); + geometryCache->renderSolidSphereInstance(batch, transform, GREY); } // Return a random vector of average length 1 diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 4f19b33abf..7cde674e52 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -331,7 +331,6 @@ void Avatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition) { if (glm::distance(DependencyManager::get()->getMyAvatar()->getPosition(), getPosition()) < 10.0f) { auto geometryCache = DependencyManager::get(); - auto deferredLighting = DependencyManager::get(); // render pointing lasers glm::vec3 laserColor = glm::vec3(1.0f, 0.0f, 1.0f); @@ -359,7 +358,7 @@ void Avatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition) { pointerTransform.setTranslation(position); pointerTransform.setRotation(rotation); batch.setModelTransform(pointerTransform); - deferredLighting->bindSimpleProgram(batch); + geometryCache->bindSimpleProgram(batch); geometryCache->renderLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, laserLength, 0.0f), laserColor); } } @@ -383,7 +382,7 @@ void Avatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition) { pointerTransform.setTranslation(position); pointerTransform.setRotation(rotation); batch.setModelTransform(pointerTransform); - deferredLighting->bindSimpleProgram(batch); + geometryCache->bindSimpleProgram(batch); geometryCache->renderLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, laserLength, 0.0f), laserColor); } } @@ -457,7 +456,7 @@ void Avatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition) { Transform transform; transform.setTranslation(position); transform.postScale(INDICATOR_RADIUS); - DependencyManager::get()->renderSolidSphereInstance(batch, transform, LOOK_AT_INDICATOR_COLOR); + DependencyManager::get()->renderSolidSphereInstance(batch, transform, LOOK_AT_INDICATOR_COLOR); } // If the avatar is looking at me, indicate that they are @@ -485,7 +484,7 @@ void Avatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition) { eyeDiameter = DEFAULT_EYE_DIAMETER; } - DependencyManager::get()->renderSolidSphereInstance(batch, + DependencyManager::get()->renderSolidSphereInstance(batch, Transform(transform).postScale(eyeDiameter * getUniformScale() / 2.0f + RADIUS_INCREMENT), glm::vec4(LOOKING_AT_ME_COLOR, alpha)); @@ -495,7 +494,7 @@ void Avatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition) { if (eyeDiameter == 0.0f) { eyeDiameter = DEFAULT_EYE_DIAMETER; } - DependencyManager::get()->renderSolidSphereInstance(batch, + DependencyManager::get()->renderSolidSphereInstance(batch, Transform(transform).postScale(eyeDiameter * getUniformScale() / 2.0f + RADIUS_INCREMENT), glm::vec4(LOOKING_AT_ME_COLOR, alpha)); @@ -655,7 +654,7 @@ void Avatar::renderBillboard(RenderArgs* renderArgs) { gpu::Batch& batch = *renderArgs->_batch; PROFILE_RANGE_BATCH(batch, __FUNCTION__); batch.setResourceTexture(0, _billboardTexture->getGPUTexture()); - DependencyManager::get()->bindSimpleProgram(batch, true); + DependencyManager::get()->bindSimpleProgram(batch, true); DependencyManager::get()->renderQuad(batch, topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, glm::vec4(1.0f, 1.0f, 1.0f, 1.0f)); } @@ -791,7 +790,7 @@ void Avatar::renderDisplayName(gpu::Batch& batch, const ViewFrustum& frustum, co { PROFILE_RANGE_BATCH(batch, __FUNCTION__":renderBevelCornersRect"); - DependencyManager::get()->bindSimpleProgram(batch, false, true, true, true); + DependencyManager::get()->bindSimpleProgram(batch, false, true, true, true); DependencyManager::get()->renderBevelCornersRect(batch, left, bottom, width, height, bevelDistance, backgroundColor); } diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index fe03d22f0b..fba5e1ab13 100644 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -14,7 +14,6 @@ #include #include -#include #include "Avatar.h" #include "AvatarManager.h" @@ -61,7 +60,7 @@ void Hand::renderHandTargets(RenderArgs* renderArgs, bool isMine) { transform.setTranslation(position); transform.setRotation(palm.getRotation()); transform.postScale(SPHERE_RADIUS); - DependencyManager::get()->renderSolidSphereInstance(batch, transform, grayColor); + DependencyManager::get()->renderSolidSphereInstance(batch, transform, grayColor); // draw a green sphere at the old "finger tip" transform = Transform(); @@ -69,7 +68,7 @@ void Hand::renderHandTargets(RenderArgs* renderArgs, bool isMine) { transform.setTranslation(position); transform.setRotation(palm.getRotation()); transform.postScale(SPHERE_RADIUS); - DependencyManager::get()->renderSolidSphereInstance(batch, transform, greenColor); + DependencyManager::get()->renderSolidSphereInstance(batch, transform, greenColor); } } diff --git a/interface/src/avatar/Head.cpp b/interface/src/avatar/Head.cpp index aa2d268f3d..61bc5c861e 100644 --- a/interface/src/avatar/Head.cpp +++ b/interface/src/avatar/Head.cpp @@ -11,8 +11,6 @@ #include #include -#include -#include #include #include @@ -451,12 +449,11 @@ void Head::renderLookatVectors(RenderArgs* renderArgs, glm::vec3 leftEyePosition batch.setModelTransform(transform); // FIXME: THe line width of 2.0f is not supported anymore, we ll need a workaround - auto deferredLighting = DependencyManager::get(); - deferredLighting->bindSimpleProgram(batch); - - auto geometryCache = DependencyManager::get(); glm::vec4 startColor(0.2f, 0.2f, 0.2f, 1.0f); glm::vec4 endColor(1.0f, 1.0f, 1.0f, 0.0f); + + auto geometryCache = DependencyManager::get(); + geometryCache->bindSimpleProgram(batch); geometryCache->renderLine(batch, leftEyePosition, lookatPosition, startColor, endColor, _leftEyeLookAtID); geometryCache->renderLine(batch, rightEyePosition, lookatPosition, startColor, endColor, _rightEyeLookAtID); } @@ -466,9 +463,9 @@ void Head::renderLookatTarget(RenderArgs* renderArgs, glm::vec3 lookatPosition) auto transform = Transform{}; transform.setTranslation(lookatPosition); - auto deferredLighting = DependencyManager::get(); + auto geometryCache = DependencyManager::get(); const float LOOK_AT_TARGET_RADIUS = 0.075f; transform.postScale(LOOK_AT_TARGET_RADIUS); const glm::vec4 LOOK_AT_TARGET_COLOR = { 0.8f, 0.0f, 0.0f, 0.75f }; - deferredLighting->renderSolidSphereInstance(batch, transform, LOOK_AT_TARGET_COLOR); + geometryCache->renderSolidSphereInstance(batch, transform, LOOK_AT_TARGET_COLOR); } diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index a5303b401a..b1688b8f9e 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -1708,24 +1708,6 @@ void MyAvatar::updateMotionBehaviorFromMenu() { _characterController.setEnabled(menu->isOptionChecked(MenuOption::EnableCharacterController)); } -//Gets the tip position for the laser pointer -glm::vec3 MyAvatar::getLaserPointerTipPosition(const PalmData* palm) { - glm::vec3 direction = glm::normalize(palm->getTipPosition() - palm->getPosition()); - - glm::vec3 position = palm->getPosition(); - //scale the position with the avatar - scaleVectorRelativeToPosition(position); - - - glm::vec3 result; - const auto& compositor = qApp->getApplicationCompositor(); - if (compositor.calculateRayUICollisionPoint(position, direction, result)) { - return result; - } - - return palm->getPosition(); -} - void MyAvatar::clearDriveKeys() { for (int i = 0; i < MAX_DRIVE_KEYS; ++i) { _driveKeys[i] = 0.0f; diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 8c4bbcbba0..33d307f5c2 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -214,10 +214,6 @@ public: void clearScriptableSettings(); - /// Renders a laser pointer for UI picking - - glm::vec3 getLaserPointerTipPosition(const PalmData* palm); - float getBoomLength() const { return _boomLength; } void setBoomLength(float boomLength) { _boomLength = boomLength; } diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index 3cd74afb81..b7a154851f 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include "Application.h" @@ -347,11 +346,10 @@ void SkeletonModel::computeBoundingShape() { void SkeletonModel::renderBoundingCollisionShapes(gpu::Batch& batch, float scale, float alpha) { auto geometryCache = DependencyManager::get(); - auto deferredLighting = DependencyManager::get(); // draw a blue sphere at the capsule top point glm::vec3 topPoint = _translation + getRotation() * (scale * (_boundingCapsuleLocalOffset + (0.5f * _boundingCapsuleHeight) * Vectors::UNIT_Y)); - deferredLighting->renderSolidSphereInstance(batch, + geometryCache->renderSolidSphereInstance(batch, Transform().setTranslation(topPoint).postScale(scale * _boundingCapsuleRadius), glm::vec4(0.6f, 0.6f, 0.8f, alpha)); @@ -359,14 +357,14 @@ void SkeletonModel::renderBoundingCollisionShapes(gpu::Batch& batch, float scale glm::vec3 bottomPoint = topPoint - glm::vec3(0.0f, scale * _boundingCapsuleHeight, 0.0f); glm::vec3 axis = topPoint - bottomPoint; - deferredLighting->renderSolidSphereInstance(batch, + geometryCache->renderSolidSphereInstance(batch, Transform().setTranslation(bottomPoint).postScale(scale * _boundingCapsuleRadius), glm::vec4(0.8f, 0.8f, 0.6f, alpha)); // draw a green cylinder between the two points glm::vec3 origin(0.0f); batch.setModelTransform(Transform().setTranslation(bottomPoint)); - deferredLighting->bindSimpleProgram(batch); + geometryCache->bindSimpleProgram(batch); Avatar::renderJointConnectingCone(batch, origin, axis, scale * _boundingCapsuleRadius, scale * _boundingCapsuleRadius, glm::vec4(0.6f, 0.8f, 0.6f, alpha)); } diff --git a/interface/src/scripting/HMDScriptingInterface.cpp b/interface/src/scripting/HMDScriptingInterface.cpp index 28d358fa39..ab53e6912a 100644 --- a/interface/src/scripting/HMDScriptingInterface.cpp +++ b/interface/src/scripting/HMDScriptingInterface.cpp @@ -27,10 +27,9 @@ QScriptValue HMDScriptingInterface::getHUDLookAtPosition2D(QScriptContext* conte MyAvatar* myAvatar = DependencyManager::get()->getMyAvatar(); glm::vec3 sphereCenter = myAvatar->getDefaultEyePosition(); glm::vec3 direction = glm::inverse(myAvatar->getOrientation()) * (hudIntersection - sphereCenter); - glm::quat rotation = ::rotationBetween(glm::vec3(0.0f, 0.0f, -1.0f), direction); - glm::vec3 eulers = ::safeEulerAngles(rotation); - return qScriptValueFromValue(engine, qApp->getApplicationCompositor() - .sphericalToOverlay(glm::vec2(eulers.y, -eulers.x))); + glm::vec2 polar = glm::vec2(glm::atan(direction.x, -direction.z), glm::asin(direction.y)) * -1.0f; + auto overlayPos = qApp->getApplicationCompositor().sphericalToOverlay(polar); + return qScriptValueFromValue(engine, overlayPos); } return QScriptValue::NullValue; } @@ -44,14 +43,6 @@ QScriptValue HMDScriptingInterface::getHUDLookAtPosition3D(QScriptContext* conte return QScriptValue::NullValue; } -void HMDScriptingInterface::toggleMagnifier() { - qApp->getApplicationCompositor().toggleMagnifier(); -} - -bool HMDScriptingInterface::getMagnifier() const { - return qApp->getApplicationCompositor().hasMagnifier(); -} - bool HMDScriptingInterface::getHUDLookAtPosition3D(glm::vec3& result) const { Camera* camera = qApp->getCamera(); glm::vec3 position = camera->getPosition(); diff --git a/interface/src/scripting/HMDScriptingInterface.h b/interface/src/scripting/HMDScriptingInterface.h index b803cc7801..f07350605f 100644 --- a/interface/src/scripting/HMDScriptingInterface.h +++ b/interface/src/scripting/HMDScriptingInterface.h @@ -23,7 +23,6 @@ class QScriptEngine; class HMDScriptingInterface : public AbstractHMDScriptingInterface, public Dependency { Q_OBJECT - Q_PROPERTY(bool magnifier READ getMagnifier) Q_PROPERTY(glm::vec3 position READ getPosition) Q_PROPERTY(glm::quat orientation READ getOrientation) public: @@ -31,11 +30,8 @@ public: static QScriptValue getHUDLookAtPosition2D(QScriptContext* context, QScriptEngine* engine); static QScriptValue getHUDLookAtPosition3D(QScriptContext* context, QScriptEngine* engine); -public slots: - void toggleMagnifier(); private: - bool getMagnifier() const; // Get the position of the HMD glm::vec3 getPosition() const; diff --git a/interface/src/ui/ApplicationCompositor.cpp b/interface/src/ui/ApplicationCompositor.cpp index abc3520c83..5f14d446ff 100644 --- a/interface/src/ui/ApplicationCompositor.cpp +++ b/interface/src/ui/ApplicationCompositor.cpp @@ -117,8 +117,6 @@ ApplicationCompositor::ApplicationCompositor() : auto geometryCache = DependencyManager::get(); _reticleQuad = geometryCache->allocateID(); - _magnifierQuad = geometryCache->allocateID(); - _magnifierBorder = geometryCache->allocateID(); auto entityScriptingInterface = DependencyManager::get(); connect(entityScriptingInterface.data(), &EntityScriptingInterface::hoverEnterEntity, [=](const EntityItemID& entityItemID, const MouseEvent& event) { @@ -202,7 +200,7 @@ void ApplicationCompositor::displayOverlayTexture(RenderArgs* renderArgs) { updateTooltips(); //Handle fading and deactivation/activation of UI - gpu::doInBatch(renderArgs->_context, [=](gpu::Batch& batch) { + gpu::doInBatch(renderArgs->_context, [&](gpu::Batch& batch) { auto geometryCache = DependencyManager::get(); @@ -231,25 +229,6 @@ void ApplicationCompositor::displayOverlayTexture(RenderArgs* renderArgs) { }); } - -vec2 ApplicationCompositor::getPolarCoordinates(const PalmData& palm) const { - MyAvatar* myAvatar = DependencyManager::get()->getMyAvatar(); - glm::vec3 tip = myAvatar->getLaserPointerTipPosition(&palm); - glm::vec3 relativePos = myAvatar->getDefaultEyePosition(); - glm::quat rotation = myAvatar->getOrientation(); - if (Menu::getInstance()->isOptionChecked(MenuOption::StandingHMDSensorMode)) { - relativePos = _modelTransform.getTranslation(); - rotation = _modelTransform.getRotation(); - } - glm::vec3 tipDirection = tip - relativePos; - tipDirection = glm::inverse(rotation) * tipDirection; - // Normalize for trig functions - tipDirection = glm::normalize(tipDirection); - // Convert to polar coordinates - glm::vec2 polar(glm::atan(tipDirection.x, -tipDirection.z), glm::asin(tipDirection.y)); - return polar; -} - // Draws the FBO texture for Oculus rift. void ApplicationCompositor::displayOverlayTextureHmd(RenderArgs* renderArgs, int eye) { PROFILE_RANGE(__FUNCTION__); @@ -270,7 +249,7 @@ void ApplicationCompositor::displayOverlayTextureHmd(RenderArgs* renderArgs, int auto geometryCache = DependencyManager::get(); - gpu::doInBatch(renderArgs->_context, [=](gpu::Batch& batch) { + gpu::doInBatch(renderArgs->_context, [&](gpu::Batch& batch) { geometryCache->useSimpleDrawPipeline(batch); batch.setResourceTexture(0, overlayFramebuffer->getRenderBuffer(0)); @@ -345,36 +324,6 @@ void ApplicationCompositor::computeHmdPickRay(glm::vec2 cursorPos, glm::vec3& or direction = glm::normalize(worldSpaceIntersection - worldSpaceHeadPosition); } -//Caculate the click location using one of the sixense controllers. Scale is not applied -QPoint ApplicationCompositor::getPalmClickLocation(const PalmData *palm) const { - QPoint rv; - auto canvasSize = qApp->getCanvasSize(); - if (qApp->isHMDMode()) { - glm::vec2 polar = getPolarCoordinates(*palm); - glm::vec2 point = sphericalToScreen(-polar); - rv.rx() = point.x; - rv.ry() = point.y; - } else { - MyAvatar* myAvatar = DependencyManager::get()->getMyAvatar(); - glm::mat4 projection; - qApp->getDisplayViewFrustum()->evalProjectionMatrix(projection); - glm::quat invOrientation = glm::inverse(myAvatar->getOrientation()); - glm::vec3 eyePos = myAvatar->getDefaultEyePosition(); - glm::vec3 tip = myAvatar->getLaserPointerTipPosition(palm); - glm::vec3 tipPos = invOrientation * (tip - eyePos); - - glm::vec4 clipSpacePos = glm::vec4(projection * glm::vec4(tipPos, 1.0f)); - glm::vec3 ndcSpacePos; - if (clipSpacePos.w != 0) { - ndcSpacePos = glm::vec3(clipSpacePos) / clipSpacePos.w; - } - - rv.setX(((ndcSpacePos.x + 1.0f) / 2.0f) * canvasSize.x); - rv.setY((1.0f - ((ndcSpacePos.y + 1.0f) / 2.0f)) * canvasSize.y); - } - return rv; -} - //Finds the collision point of a world space ray bool ApplicationCompositor::calculateRayUICollisionPoint(const glm::vec3& position, const glm::vec3& direction, glm::vec3& result) const { MyAvatar* myAvatar = DependencyManager::get()->getMyAvatar(); @@ -498,27 +447,6 @@ void ApplicationCompositor::drawSphereSection(gpu::Batch& batch) { batch.drawIndexed(gpu::TRIANGLES, _hemiIndexCount); } -glm::vec2 ApplicationCompositor::directionToSpherical(const glm::vec3& direction) { - glm::vec2 result; - // Compute yaw - glm::vec3 normalProjection = glm::normalize(glm::vec3(direction.x, 0.0f, direction.z)); - result.x = glm::acos(glm::dot(IDENTITY_FRONT, normalProjection)); - if (glm::dot(IDENTITY_RIGHT, normalProjection) > 0.0f) { - result.x = -glm::abs(result.x); - } else { - result.x = glm::abs(result.x); - } - // Compute pitch - result.y = angleBetween(IDENTITY_UP, direction) - PI_OVER_TWO; - - return result; -} - -glm::vec3 ApplicationCompositor::sphericalToDirection(const glm::vec2& sphericalPos) { - glm::quat rotation(glm::vec3(sphericalPos.y, sphericalPos.x, 0.0f)); - return rotation * IDENTITY_FRONT; -} - glm::vec2 ApplicationCompositor::screenToSpherical(const glm::vec2& screenPos) { auto screenSize = qApp->getCanvasSize(); glm::vec2 result; diff --git a/interface/src/ui/ApplicationCompositor.h b/interface/src/ui/ApplicationCompositor.h index 5f023adaef..8476782550 100644 --- a/interface/src/ui/ApplicationCompositor.h +++ b/interface/src/ui/ApplicationCompositor.h @@ -43,20 +43,15 @@ public: void displayOverlayTexture(RenderArgs* renderArgs); void displayOverlayTextureHmd(RenderArgs* renderArgs, int eye); - QPoint getPalmClickLocation(const PalmData *palm) const; bool calculateRayUICollisionPoint(const glm::vec3& position, const glm::vec3& direction, glm::vec3& result) const; - bool hasMagnifier() const { return _magnifier; } - void toggleMagnifier() { _magnifier = !_magnifier; } - float getHmdUIAngularSize() const { return _hmdUIAngularSize; } void setHmdUIAngularSize(float hmdUIAngularSize) { _hmdUIAngularSize = hmdUIAngularSize; } // Converter from one frame of reference to another. // Frame of reference: - // Direction: Ray that represents the spherical values // Screen: Position on the screen (x,y) - // Spherical: Pitch and yaw that gives the position on the sphere we project on (yaw,pitch) + // Spherical: Polar coordinates that gives the position on the sphere we project on (yaw,pitch) // Overlay: Position on the overlay (x,y) // (x,y) in Overlay are similar than (x,y) in Screen except they can be outside of the bound of te screen. // This allows for picking outside of the screen projection in 3D. @@ -80,8 +75,6 @@ public: float getAlpha() const { return _alpha; } void setAlpha(float alpha) { _alpha = alpha; } - static glm::vec2 directionToSpherical(const glm::vec3 & direction); - static glm::vec3 sphericalToDirection(const glm::vec2 & sphericalPos); static glm::vec2 screenToSpherical(const glm::vec2 & screenPos); static glm::vec2 sphericalToScreen(const glm::vec2 & sphericalPos); @@ -92,8 +85,6 @@ private: void drawSphereSection(gpu::Batch& batch); void updateTooltips(); - vec2 getPolarCoordinates(const PalmData& palm) const; - // Support for hovering and tooltips static EntityItemID _noItemId; EntityItemID _hoverItemId { _noItemId }; @@ -101,31 +92,22 @@ private: QString _hoverItemDescription; quint64 _hoverItemEnterUsecs { 0 }; - float _hmdUIAngularSize = DEFAULT_HMD_UI_ANGULAR_SIZE; - float _textureFov{ glm::radians(DEFAULT_HMD_UI_ANGULAR_SIZE) }; - float _textureAspectRatio{ 1.0f }; - int _hemiVerticesID{ GeometryCache::UNKNOWN_ID }; + float _hmdUIAngularSize { DEFAULT_HMD_UI_ANGULAR_SIZE }; + float _textureFov { glm::radians(DEFAULT_HMD_UI_ANGULAR_SIZE) }; + float _textureAspectRatio { 1.0f }; + int _hemiVerticesID { GeometryCache::UNKNOWN_ID }; - bool _magnifier{ true }; - - float _alpha{ 1.0f }; - float _prevAlpha{ 1.0f }; - float _fadeInAlpha{ true }; - float _oculusUIRadius{ 1.0f }; + float _alpha { 1.0f }; + float _prevAlpha { 1.0f }; + float _fadeInAlpha { true }; + float _oculusUIRadius { 1.0f }; QMap _cursors; int _reticleQuad; - int _magnifierQuad; - int _magnifierBorder; - int _previousBorderWidth{ -1 }; - int _previousBorderHeight{ -1 }; - - glm::vec3 _previousMagnifierBottomLeft; - glm::vec3 _previousMagnifierBottomRight; - glm::vec3 _previousMagnifierTopLeft; - glm::vec3 _previousMagnifierTopRight; + int _previousBorderWidth { -1 }; + int _previousBorderHeight { -1 }; Transform _modelTransform; Transform _cameraBaseTransform; diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 9259478d46..43966553de 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include #include @@ -70,7 +69,7 @@ void ApplicationOverlay::renderOverlay(RenderArgs* renderArgs) { } // Execute the batch into our framebuffer - doInBatch(renderArgs->_context, [=](gpu::Batch& batch) { + doInBatch(renderArgs->_context, [&](gpu::Batch& batch) { renderArgs->_batch = &batch; int width = _overlayFramebuffer->getWidth(); diff --git a/interface/src/ui/overlays/Circle3DOverlay.cpp b/interface/src/ui/overlays/Circle3DOverlay.cpp index 0b7da72d58..bbb9addc3d 100644 --- a/interface/src/ui/overlays/Circle3DOverlay.cpp +++ b/interface/src/ui/overlays/Circle3DOverlay.cpp @@ -10,7 +10,6 @@ #include "Circle3DOverlay.h" -#include #include #include @@ -106,7 +105,7 @@ void Circle3DOverlay::render(RenderArgs* args) { auto transform = _transform; transform.postScale(glm::vec3(getDimensions(), 1.0f)); batch.setModelTransform(transform); - DependencyManager::get()->bindSimpleProgram(batch, false, false); + DependencyManager::get()->bindSimpleProgram(batch, false, false); // for our overlay, is solid means we draw a ring between the inner and outer radius of the circle, otherwise // we just draw a line... diff --git a/interface/src/ui/overlays/Cube3DOverlay.cpp b/interface/src/ui/overlays/Cube3DOverlay.cpp index 3ad887ca65..7688bce985 100644 --- a/interface/src/ui/overlays/Cube3DOverlay.cpp +++ b/interface/src/ui/overlays/Cube3DOverlay.cpp @@ -13,7 +13,6 @@ #include -#include #include #include #include @@ -61,7 +60,7 @@ void Cube3DOverlay::render(RenderArgs* args) { // } transform.setScale(dimensions); - DependencyManager::get()->renderSolidCubeInstance(*batch, transform, cubeColor); + DependencyManager::get()->renderSolidCubeInstance(*batch, transform, cubeColor); } else { if (getIsDashedLine()) { @@ -99,7 +98,7 @@ void Cube3DOverlay::render(RenderArgs* args) { } else { batch->setModelTransform(Transform()); transform.setScale(dimensions); - DependencyManager::get()->renderWireCubeInstance(*batch, transform, cubeColor); + DependencyManager::get()->renderWireCubeInstance(*batch, transform, cubeColor); } } } diff --git a/interface/src/ui/overlays/Image3DOverlay.cpp b/interface/src/ui/overlays/Image3DOverlay.cpp index f1e0f08a3a..8ce8bf7a5f 100644 --- a/interface/src/ui/overlays/Image3DOverlay.cpp +++ b/interface/src/ui/overlays/Image3DOverlay.cpp @@ -14,7 +14,6 @@ #include -#include #include #include #include @@ -96,7 +95,7 @@ void Image3DOverlay::render(RenderArgs* args) { batch->setModelTransform(transform); batch->setResourceTexture(0, _texture->getGPUTexture()); - DependencyManager::get()->bindSimpleProgram(*batch, true, false, _emissive, true); + DependencyManager::get()->bindSimpleProgram(*batch, true, false, _emissive, true); DependencyManager::get()->renderQuad( *batch, topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, glm::vec4(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha) diff --git a/interface/src/ui/overlays/ImageOverlay.cpp b/interface/src/ui/overlays/ImageOverlay.cpp index ed88f50981..8df62b9675 100644 --- a/interface/src/ui/overlays/ImageOverlay.cpp +++ b/interface/src/ui/overlays/ImageOverlay.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include diff --git a/interface/src/ui/overlays/Line3DOverlay.cpp b/interface/src/ui/overlays/Line3DOverlay.cpp index 9dc609af31..ed97b95de0 100644 --- a/interface/src/ui/overlays/Line3DOverlay.cpp +++ b/interface/src/ui/overlays/Line3DOverlay.cpp @@ -12,7 +12,6 @@ #include #include -#include QString const Line3DOverlay::TYPE = "line3d"; @@ -54,7 +53,7 @@ void Line3DOverlay::render(RenderArgs* args) { auto batch = args->_batch; if (batch) { batch->setModelTransform(_transform); - DependencyManager::get()->bindSimpleProgram(*batch); + DependencyManager::get()->bindSimpleProgram(*batch); if (getIsDashedLine()) { // TODO: add support for color to renderDashedLine() diff --git a/interface/src/ui/overlays/Overlay.cpp b/interface/src/ui/overlays/Overlay.cpp index 0c909a1bfb..0497a20500 100644 --- a/interface/src/ui/overlays/Overlay.cpp +++ b/interface/src/ui/overlays/Overlay.cpp @@ -222,10 +222,8 @@ float Overlay::updatePulse() { } bool Overlay::addToScene(Overlay::Pointer overlay, std::shared_ptr scene, render::PendingChanges& pendingChanges) { - auto overlayPayload = new Overlay::Payload(overlay); - auto overlayPayloadPointer = Overlay::PayloadPointer(overlayPayload); _renderItemID = scene->allocateID(); - pendingChanges.resetItem(_renderItemID, overlayPayloadPointer); + pendingChanges.resetItem(_renderItemID, std::make_shared(overlay)); return true; } diff --git a/interface/src/ui/overlays/Sphere3DOverlay.cpp b/interface/src/ui/overlays/Sphere3DOverlay.cpp index 7caff3ea04..63ed7fe31d 100644 --- a/interface/src/ui/overlays/Sphere3DOverlay.cpp +++ b/interface/src/ui/overlays/Sphere3DOverlay.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include @@ -45,12 +44,11 @@ void Sphere3DOverlay::render(RenderArgs* args) { Transform transform = _transform; transform.postScale(getDimensions() * SPHERE_OVERLAY_SCALE); if (_isSolid) { - DependencyManager::get()->renderSolidSphereInstance(*batch, transform, sphereColor); + DependencyManager::get()->renderSolidSphereInstance(*batch, transform, sphereColor); } else { - DependencyManager::get()->renderWireSphereInstance(*batch, transform, sphereColor); + DependencyManager::get()->renderWireSphereInstance(*batch, transform, sphereColor); } } - } Sphere3DOverlay* Sphere3DOverlay::createClone() const { diff --git a/interface/src/ui/overlays/Text3DOverlay.cpp b/interface/src/ui/overlays/Text3DOverlay.cpp index 8c448234ad..2e5110951d 100644 --- a/interface/src/ui/overlays/Text3DOverlay.cpp +++ b/interface/src/ui/overlays/Text3DOverlay.cpp @@ -10,7 +10,6 @@ #include "Text3DOverlay.h" -#include #include #include #include @@ -101,7 +100,7 @@ void Text3DOverlay::render(RenderArgs* args) { glm::vec3 topLeft(-halfDimensions.x, -halfDimensions.y, SLIGHTLY_BEHIND); glm::vec3 bottomRight(halfDimensions.x, halfDimensions.y, SLIGHTLY_BEHIND); - DependencyManager::get()->bindSimpleProgram(batch, false, true, false, true); + DependencyManager::get()->bindSimpleProgram(batch, false, true, false, true); DependencyManager::get()->renderQuad(batch, topLeft, bottomRight, quadColor); // Same font properties as textSize() diff --git a/interface/src/ui/overlays/Web3DOverlay.cpp b/interface/src/ui/overlays/Web3DOverlay.cpp index 1088473a25..1ec502139b 100644 --- a/interface/src/ui/overlays/Web3DOverlay.cpp +++ b/interface/src/ui/overlays/Web3DOverlay.cpp @@ -16,8 +16,6 @@ #include #include - -#include #include #include #include @@ -103,7 +101,7 @@ void Web3DOverlay::render(RenderArgs* args) { } batch.setModelTransform(transform); - DependencyManager::get()->bindSimpleProgram(batch, true, false, false, true); + DependencyManager::get()->bindSimpleProgram(batch, true, false, false, true); DependencyManager::get()->renderQuad(batch, halfSize * -1.0f, halfSize, vec2(0), vec2(1), color); batch.setResourceTexture(0, args->_whiteTexture); // restore default white color after me } diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 07d9031f41..c3e012d412 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -17,14 +17,12 @@ #include #include #include -#include #include #include #include #include #include #include -#include #include "EntityTreeRenderer.h" @@ -142,7 +140,7 @@ void EntityTreeRenderer::update() { // even if we haven't changed positions, if we previously attempted to set the skybox, but // have a pending download of the skybox texture, then we should attempt to reapply to // get the correct texture. - if (_pendingSkyboxTextureDownload) { + if (_pendingSkyboxTexture && _skyboxTexture && _skyboxTexture->isLoaded()) { applyZonePropertiesToScene(_bestZone); } @@ -255,94 +253,17 @@ void EntityTreeRenderer::forceRecheckEntities() { void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr zone) { - QSharedPointer scene = DependencyManager::get(); + auto scene = DependencyManager::get(); auto sceneStage = scene->getStage(); + auto skyStage = scene->getSkyStage(); auto sceneKeyLight = sceneStage->getKeyLight(); auto sceneLocation = sceneStage->getLocation(); auto sceneTime = sceneStage->getTime(); + + if (!zone) { + _pendingSkyboxTexture = false; + _skyboxTexture.clear(); - if (zone) { - if (!_hasPreviousZone) { - _previousKeyLightColor = sceneKeyLight->getColor(); - _previousKeyLightIntensity = sceneKeyLight->getIntensity(); - _previousKeyLightAmbientIntensity = sceneKeyLight->getAmbientIntensity(); - _previousKeyLightDirection = sceneKeyLight->getDirection(); - _previousStageSunModelEnabled = sceneStage->isSunModelEnabled(); - _previousStageLongitude = sceneLocation->getLongitude(); - _previousStageLatitude = sceneLocation->getLatitude(); - _previousStageAltitude = sceneLocation->getAltitude(); - _previousStageHour = sceneTime->getHour(); - _previousStageDay = sceneTime->getDay(); - _hasPreviousZone = true; - } - sceneKeyLight->setColor(ColorUtils::toVec3(zone->getKeyLightProperties().getColor())); - sceneKeyLight->setIntensity(zone->getKeyLightProperties().getIntensity()); - sceneKeyLight->setAmbientIntensity(zone->getKeyLightProperties().getAmbientIntensity()); - sceneKeyLight->setDirection(zone->getKeyLightProperties().getDirection()); - sceneStage->setSunModelEnable(zone->getStageProperties().getSunModelEnabled()); - sceneStage->setLocation(zone->getStageProperties().getLongitude(), zone->getStageProperties().getLatitude(), - zone->getStageProperties().getAltitude()); - sceneTime->setHour(zone->getStageProperties().calculateHour()); - sceneTime->setDay(zone->getStageProperties().calculateDay()); - - if (zone->getBackgroundMode() == BACKGROUND_MODE_ATMOSPHERE) { - EnvironmentData data = zone->getEnvironmentData(); - glm::vec3 keyLightDirection = sceneKeyLight->getDirection(); - glm::vec3 inverseKeyLightDirection = keyLightDirection * -1.0f; - - // NOTE: is this right? It seems like the "sun" should be based on the center of the - // atmosphere, not where the camera is. - glm::vec3 keyLightLocation = _viewState->getAvatarPosition() - + (inverseKeyLightDirection * data.getAtmosphereOuterRadius()); - - data.setSunLocation(keyLightLocation); - - const float KEY_LIGHT_INTENSITY_TO_SUN_BRIGHTNESS_RATIO = 20.0f; - float sunBrightness = sceneKeyLight->getIntensity() * KEY_LIGHT_INTENSITY_TO_SUN_BRIGHTNESS_RATIO; - data.setSunBrightness(sunBrightness); - - _viewState->overrideEnvironmentData(data); - scene->getSkyStage()->setBackgroundMode(model::SunSkyStage::SKY_DOME); - _pendingSkyboxTextureDownload = false; - - } else { - _viewState->endOverrideEnvironmentData(); - auto stage = scene->getSkyStage(); - if (zone->getBackgroundMode() == BACKGROUND_MODE_SKYBOX) { - auto skybox = std::dynamic_pointer_cast(stage->getSkybox()); - skybox->setColor(zone->getSkyboxProperties().getColorVec3()); - static QString userData; - if (userData != zone->getUserData()) { - userData = zone->getUserData(); - ProceduralPointer procedural(new Procedural(userData)); - if (procedural->_enabled) { - skybox->setProcedural(procedural); - } else { - skybox->setProcedural(ProceduralPointer()); - } - } - if (zone->getSkyboxProperties().getURL().isEmpty()) { - skybox->setCubemap(gpu::TexturePointer()); - _pendingSkyboxTextureDownload = false; - } else { - // Update the Texture of the Skybox with the one pointed by this zone - auto cubeMap = DependencyManager::get()->getTexture(zone->getSkyboxProperties().getURL(), CUBE_TEXTURE); - - if (cubeMap->getGPUTexture()) { - skybox->setCubemap(cubeMap->getGPUTexture()); - _pendingSkyboxTextureDownload = false; - } else { - _pendingSkyboxTextureDownload = true; - } - } - stage->setBackgroundMode(model::SunSkyStage::SKY_BOX); - } else { - stage->setBackgroundMode(model::SunSkyStage::SKY_DOME); // let the application atmosphere through - _pendingSkyboxTextureDownload = false; - } - } - } else { - _pendingSkyboxTextureDownload = false; if (_hasPreviousZone) { sceneKeyLight->setColor(_previousKeyLightColor); sceneKeyLight->setIntensity(_previousKeyLightIntensity); @@ -355,14 +276,106 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptrsetDay(_previousStageDay); _hasPreviousZone = false; } + _viewState->endOverrideEnvironmentData(); - scene->getSkyStage()->setBackgroundMode(model::SunSkyStage::SKY_DOME); // let the application atmosphere through + skyStage->setBackgroundMode(model::SunSkyStage::SKY_DOME); // let the application atmosphere through + + return; // Early exit + } + + if (!_hasPreviousZone) { + _previousKeyLightColor = sceneKeyLight->getColor(); + _previousKeyLightIntensity = sceneKeyLight->getIntensity(); + _previousKeyLightAmbientIntensity = sceneKeyLight->getAmbientIntensity(); + _previousKeyLightDirection = sceneKeyLight->getDirection(); + _previousStageSunModelEnabled = sceneStage->isSunModelEnabled(); + _previousStageLongitude = sceneLocation->getLongitude(); + _previousStageLatitude = sceneLocation->getLatitude(); + _previousStageAltitude = sceneLocation->getAltitude(); + _previousStageHour = sceneTime->getHour(); + _previousStageDay = sceneTime->getDay(); + _hasPreviousZone = true; + } + + sceneKeyLight->setColor(ColorUtils::toVec3(zone->getKeyLightProperties().getColor())); + sceneKeyLight->setIntensity(zone->getKeyLightProperties().getIntensity()); + sceneKeyLight->setAmbientIntensity(zone->getKeyLightProperties().getAmbientIntensity()); + sceneKeyLight->setDirection(zone->getKeyLightProperties().getDirection()); + sceneStage->setSunModelEnable(zone->getStageProperties().getSunModelEnabled()); + sceneStage->setLocation(zone->getStageProperties().getLongitude(), zone->getStageProperties().getLatitude(), + zone->getStageProperties().getAltitude()); + sceneTime->setHour(zone->getStageProperties().calculateHour()); + sceneTime->setDay(zone->getStageProperties().calculateDay()); + + switch (zone->getBackgroundMode()) { + case BACKGROUND_MODE_ATMOSPHERE: { + EnvironmentData data = zone->getEnvironmentData(); + glm::vec3 keyLightDirection = sceneKeyLight->getDirection(); + glm::vec3 inverseKeyLightDirection = keyLightDirection * -1.0f; + + // NOTE: is this right? It seems like the "sun" should be based on the center of the + // atmosphere, not where the camera is. + glm::vec3 keyLightLocation = _viewState->getAvatarPosition() + + (inverseKeyLightDirection * data.getAtmosphereOuterRadius()); + + data.setSunLocation(keyLightLocation); + + const float KEY_LIGHT_INTENSITY_TO_SUN_BRIGHTNESS_RATIO = 20.0f; + float sunBrightness = sceneKeyLight->getIntensity() * KEY_LIGHT_INTENSITY_TO_SUN_BRIGHTNESS_RATIO; + data.setSunBrightness(sunBrightness); + + _viewState->overrideEnvironmentData(data); + skyStage->setBackgroundMode(model::SunSkyStage::SKY_DOME); + _pendingSkyboxTexture = false; + _skyboxTexture.clear(); + break; + } + case BACKGROUND_MODE_SKYBOX: { + auto skybox = std::dynamic_pointer_cast(skyStage->getSkybox()); + skybox->setColor(zone->getSkyboxProperties().getColorVec3()); + static QString userData; + if (userData != zone->getUserData()) { + userData = zone->getUserData(); + auto procedural = std::make_shared(userData); + if (procedural->_enabled) { + skybox->setProcedural(procedural); + } else { + skybox->setProcedural(ProceduralPointer()); + } + } + if (zone->getSkyboxProperties().getURL().isEmpty()) { + skybox->setCubemap(gpu::TexturePointer()); + _pendingSkyboxTexture = false; + _skyboxTexture.clear(); + } else { + // Update the Texture of the Skybox with the one pointed by this zone + auto textureCache = DependencyManager::get(); + _skyboxTexture = textureCache->getTexture(zone->getSkyboxProperties().getURL(), CUBE_TEXTURE); + + if (_skyboxTexture->getGPUTexture()) { + skybox->setCubemap(_skyboxTexture->getGPUTexture()); + _pendingSkyboxTexture = false; + } else { + _pendingSkyboxTexture = true; + } + } + + _viewState->endOverrideEnvironmentData(); + skyStage->setBackgroundMode(model::SunSkyStage::SKY_BOX); + break; + } + case BACKGROUND_MODE_INHERIT: + _viewState->endOverrideEnvironmentData(); + skyStage->setBackgroundMode(model::SunSkyStage::SKY_DOME); // let the application atmosphere through + _pendingSkyboxTexture = false; + _skyboxTexture.clear(); + break; } } const FBXGeometry* EntityTreeRenderer::getGeometryForEntity(EntityItemPointer entityItem) { const FBXGeometry* result = NULL; - + if (entityItem->getType() == EntityTypes::Model) { std::shared_ptr modelEntityItem = std::dynamic_pointer_cast(entityItem); diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.h b/libraries/entities-renderer/src/EntityTreeRenderer.h index e2cd4fc2dd..09fe7a527c 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.h +++ b/libraries/entities-renderer/src/EntityTreeRenderer.h @@ -15,12 +15,13 @@ #include #include -#include +#include #include // for RayToEntityIntersectionResult +#include #include #include #include -#include +#include class AbstractScriptingServicesInterface; class AbstractViewStateInterface; @@ -142,9 +143,11 @@ private: void forceRecheckEntities(); glm::vec3 _lastAvatarPosition; - bool _pendingSkyboxTextureDownload = false; QVector _currentEntitiesInside; - + + bool _pendingSkyboxTexture { false }; + NetworkTexturePointer _skyboxTexture; + bool _wantScripts; ScriptEngine* _entitiesScriptEngine; @@ -161,11 +164,11 @@ private: bool _displayModelBounds; bool _dontDoPrecisionPicking; - bool _shuttingDown = false; + bool _shuttingDown { false }; QMultiMap _waitingOnPreload; - bool _hasPreviousZone = false; + bool _hasPreviousZone { false }; std::shared_ptr _bestZone; float _bestZoneVolume; diff --git a/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp b/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp index 4de363016b..1b1437a7d9 100644 --- a/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp @@ -15,7 +15,6 @@ #include -#include #include #include #include @@ -69,7 +68,7 @@ void RenderableBoxEntityItem::render(RenderArgs* args) { batch._glColor4f(color.r, color.g, color.b, color.a); DependencyManager::get()->renderCube(batch); } else { - DependencyManager::get()->renderSolidCubeInstance(batch, transToCenter, cubeColor); + DependencyManager::get()->renderSolidCubeInstance(batch, transToCenter, cubeColor); } static const auto triCount = DependencyManager::get()->getCubeTriangleCount(); args->_details._trianglesRendered += (int)triCount; diff --git a/libraries/entities-renderer/src/RenderableLightEntityItem.cpp b/libraries/entities-renderer/src/RenderableLightEntityItem.cpp index 5b8891d1f2..39182f322c 100644 --- a/libraries/entities-renderer/src/RenderableLightEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLightEntityItem.cpp @@ -51,7 +51,7 @@ void RenderableLightEntityItem::render(RenderArgs* args) { Q_ASSERT(args->_batch); gpu::Batch& batch = *args->_batch; batch.setModelTransform(getTransformToCenter()); - DependencyManager::get()->renderWireSphere(batch, 0.5f, 15, 15, glm::vec4(color, 1.0f)); + DependencyManager::get()->renderWireSphere(batch, 0.5f, 15, 15, glm::vec4(color, 1.0f)); #endif }; diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp index 8eb3ea8754..b8815aab7c 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp @@ -14,7 +14,6 @@ #include #include -#include #include #include "RenderableLineEntityItem.h" @@ -53,7 +52,7 @@ void RenderableLineEntityItem::render(RenderArgs* args) { batch.setModelTransform(transform); if (getLinePoints().size() > 1) { - DependencyManager::get()->bindSimpleProgram(batch); + DependencyManager::get()->bindSimpleProgram(batch); DependencyManager::get()->renderVertices(batch, gpu::LINE_STRIP, _lineVerticesID); } }; diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index f5090cc20c..7424180437 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -16,7 +16,6 @@ #include #include -#include #include #include #include @@ -432,7 +431,7 @@ void RenderableModelEntityItem::render(RenderArgs* args) { auto shapeTransform = getTransformToCenter(success); if (success) { batch.setModelTransform(Transform()); // we want to include the scale as well - DependencyManager::get()->renderWireCubeInstance(batch, shapeTransform, greenColor); + DependencyManager::get()->renderWireCubeInstance(batch, shapeTransform, greenColor); } } } diff --git a/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp b/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp index 115eba0a05..e757f5c68a 100644 --- a/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp @@ -11,7 +11,6 @@ #include #include -#include #include #include #include diff --git a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp index fd28bc043d..600b876d39 100644 --- a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include "RenderablePolyLineEntityItem.h" diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 1048f594f4..1029f3b3af 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -27,7 +27,6 @@ #pragma GCC diagnostic pop #endif -#include #include #include #include diff --git a/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp b/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp index 9bed5b3bb0..9f16de0db1 100644 --- a/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp @@ -16,7 +16,6 @@ #include #include -#include #include #include @@ -73,7 +72,7 @@ void RenderableSphereEntityItem::render(RenderArgs* args) { DependencyManager::get()->renderSphere(batch); } else { batch.setModelTransform(Transform()); - DependencyManager::get()->renderSolidSphereInstance(batch, modelTransform, sphereColor); + DependencyManager::get()->renderSolidSphereInstance(batch, modelTransform, sphereColor); } static const auto triCount = DependencyManager::get()->getSphereTriangleCount(); args->_details._trianglesRendered += (int)triCount; diff --git a/libraries/entities-renderer/src/RenderableTextEntityItem.cpp b/libraries/entities-renderer/src/RenderableTextEntityItem.cpp index d88b4d5f0a..5cf31c15e0 100644 --- a/libraries/entities-renderer/src/RenderableTextEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableTextEntityItem.cpp @@ -11,7 +11,6 @@ #include -#include #include #include #include @@ -63,7 +62,7 @@ void RenderableTextEntityItem::render(RenderArgs* args) { batch.setModelTransform(transformToTopLeft); - DependencyManager::get()->bindSimpleProgram(batch, false, false, false, true); + DependencyManager::get()->bindSimpleProgram(batch, false, false, false, true); DependencyManager::get()->renderQuad(batch, minCorner, maxCorner, backgroundColor); float scale = _lineHeight / _textRenderer->getFontSize(); diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp index 979ec32878..ce89197069 100644 --- a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp @@ -15,7 +15,6 @@ #include -#include #include #include #include @@ -69,7 +68,7 @@ void RenderableWebEntityItem::render(RenderArgs* args) { gpu::Batch& batch = *args->_batch; batch.setModelTransform(getTransformToCenter()); // we want to include the scale as well glm::vec4 cubeColor{ 1.0f, 0.0f, 0.0f, 1.0f}; - DependencyManager::get()->renderWireCube(batch, 1.0f, cubeColor); + DependencyManager::get()->renderWireCube(batch, 1.0f, cubeColor); } #endif @@ -201,7 +200,7 @@ void RenderableWebEntityItem::render(RenderArgs* args) { textured = emissive = true; } - DependencyManager::get()->bindSimpleProgram(batch, textured, culled, emissive); + DependencyManager::get()->bindSimpleProgram(batch, textured, culled, emissive); DependencyManager::get()->renderQuad(batch, topLeft, bottomRight, texMin, texMax, glm::vec4(1.0f)); } diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp index eb01bd551e..9396933fc6 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp @@ -14,7 +14,6 @@ #include #include -#include #include #include #include @@ -140,12 +139,12 @@ void RenderableZoneEntityItem::render(RenderArgs* args) { if (!success) { break; } - auto deferredLightingEffect = DependencyManager::get(); + auto geometryCache = DependencyManager::get(); if (getShapeType() == SHAPE_TYPE_SPHERE) { shapeTransform.postScale(SPHERE_ENTITY_SCALE); - deferredLightingEffect->renderWireSphereInstance(batch, shapeTransform, DEFAULT_COLOR); + geometryCache->renderWireSphereInstance(batch, shapeTransform, DEFAULT_COLOR); } else { - deferredLightingEffect->renderWireCubeInstance(batch, shapeTransform, DEFAULT_COLOR); + geometryCache->renderWireCubeInstance(batch, shapeTransform, DEFAULT_COLOR); } break; } diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index d526ffec0d..d0b79723d1 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -275,6 +275,7 @@ public: void setIgnoreForCollisions(bool value) { _ignoreForCollisions = value; } uint8_t getCollisionMask() const { return _collisionMask; } + uint8_t getFinalCollisionMask() const { return _ignoreForCollisions ? 0 : _collisionMask; } void setCollisionMask(uint8_t value) { _collisionMask = value; } bool getCollisionsWillMove() const { return _collisionsWillMove; } @@ -446,6 +447,7 @@ protected: bool _visible; bool _ignoreForCollisions; uint8_t _collisionMask { ENTITY_COLLISION_MASK_DEFAULT }; + uint8_t _collisionGroupOverride; bool _collisionsWillMove; bool _locked; QString _userData; diff --git a/libraries/gpu/src/gpu/Batch.cpp b/libraries/gpu/src/gpu/Batch.cpp index f9c4131a1b..999e528a94 100644 --- a/libraries/gpu/src/gpu/Batch.cpp +++ b/libraries/gpu/src/gpu/Batch.cpp @@ -362,8 +362,8 @@ bool Batch::isSkyboxEnabled() const { void Batch::setupNamedCalls(const std::string& instanceName, size_t count, NamedBatchData::Function function) { NamedBatchData& instance = _namedData[instanceName]; - instance._count += count; - instance._function = function; + instance.count += count; + instance.function = function; } void Batch::setupNamedCalls(const std::string& instanceName, NamedBatchData::Function function) { @@ -372,13 +372,13 @@ void Batch::setupNamedCalls(const std::string& instanceName, NamedBatchData::Fun BufferPointer Batch::getNamedBuffer(const std::string& instanceName, uint8_t index) { NamedBatchData& instance = _namedData[instanceName]; - if (instance._buffers.size() <= index) { - instance._buffers.resize(index + 1); + if (instance.buffers.size() <= index) { + instance.buffers.resize(index + 1); } - if (!instance._buffers[index]) { - instance._buffers[index].reset(new Buffer()); + if (!instance.buffers[index]) { + instance.buffers[index].reset(new Buffer()); } - return instance._buffers[index]; + return instance.buffers[index]; } void Batch::preExecute() { diff --git a/libraries/gpu/src/gpu/Batch.h b/libraries/gpu/src/gpu/Batch.h index 88d28f9d10..aa2fc1622c 100644 --- a/libraries/gpu/src/gpu/Batch.h +++ b/libraries/gpu/src/gpu/Batch.h @@ -49,14 +49,13 @@ public: using BufferPointers = std::vector; using Function = std::function; - std::once_flag _once; - BufferPointers _buffers; - size_t _count{ 0 }; - Function _function; + BufferPointers buffers; + size_t count { 0 }; + Function function; void process(Batch& batch) { - if (_function) { - _function(batch, *this); + if (function) { + function(batch, *this); } } }; diff --git a/libraries/gpu/src/gpu/Context.h b/libraries/gpu/src/gpu/Context.h index ad21d71427..ed2afe91eb 100644 --- a/libraries/gpu/src/gpu/Context.h +++ b/libraries/gpu/src/gpu/Context.h @@ -97,68 +97,16 @@ public: TransformCamera getEyeCamera(int eye, const StereoState& stereo) const; }; - template< typename T > - static void setGPUObject(const Buffer& buffer, T* object) { - buffer.setGPUObject(object); + + template + static void setGPUObject(const U& object, T* gpuObject) { + object.gpuObject.setGPUObject(gpuObject); } - template< typename T > - static T* getGPUObject(const Buffer& buffer) { - return reinterpret_cast(buffer.getGPUObject()); + template + static T* getGPUObject(const U& object) { + return reinterpret_cast(object.gpuObject.getGPUObject()); } - template< typename T > - static void setGPUObject(const Texture& texture, T* object) { - texture.setGPUObject(object); - } - template< typename T > - static T* getGPUObject(const Texture& texture) { - return reinterpret_cast(texture.getGPUObject()); - } - - template< typename T > - static void setGPUObject(const Shader& shader, T* object) { - shader.setGPUObject(object); - } - template< typename T > - static T* getGPUObject(const Shader& shader) { - return reinterpret_cast(shader.getGPUObject()); - } - - template< typename T > - static void setGPUObject(const Pipeline& pipeline, T* object) { - pipeline.setGPUObject(object); - } - template< typename T > - static T* getGPUObject(const Pipeline& pipeline) { - return reinterpret_cast(pipeline.getGPUObject()); - } - - template< typename T > - static void setGPUObject(const State& state, T* object) { - state.setGPUObject(object); - } - template< typename T > - static T* getGPUObject(const State& state) { - return reinterpret_cast(state.getGPUObject()); - } - - template< typename T > - static void setGPUObject(const Framebuffer& framebuffer, T* object) { - framebuffer.setGPUObject(object); - } - template< typename T > - static T* getGPUObject(const Framebuffer& framebuffer) { - return reinterpret_cast(framebuffer.getGPUObject()); - } - - template< typename T > - static void setGPUObject(const Query& query, T* object) { - query.setGPUObject(object); - } - template< typename T > - static T* getGPUObject(const Query& query) { - return reinterpret_cast(query.getGPUObject()); - } protected: StereoState _stereo; diff --git a/libraries/gpu/src/gpu/Format.h b/libraries/gpu/src/gpu/Format.h index 41a95e2578..54d40c3e12 100644 --- a/libraries/gpu/src/gpu/Format.h +++ b/libraries/gpu/src/gpu/Format.h @@ -11,15 +11,30 @@ #ifndef hifi_gpu_Format_h #define hifi_gpu_Format_h -#include #include +#include + +#include namespace gpu { +class Backend; + class GPUObject { public: - GPUObject() {} - virtual ~GPUObject() {} + virtual ~GPUObject() = default; +}; + +class GPUObjectPointer { +private: + using GPUObjectUniquePointer = std::unique_ptr; + + // This shouldn't be used by anything else than the Backend class with the proper casting. + mutable GPUObjectUniquePointer _gpuObject; + void setGPUObject(GPUObject* gpuObject) const { _gpuObject.reset(gpuObject); } + GPUObject* getGPUObject() const { return _gpuObject.get(); } + + friend class Backend; }; typedef int Stamp; diff --git a/libraries/gpu/src/gpu/Framebuffer.h b/libraries/gpu/src/gpu/Framebuffer.h index 807047a56e..e986e4a481 100755 --- a/libraries/gpu/src/gpu/Framebuffer.h +++ b/libraries/gpu/src/gpu/Framebuffer.h @@ -134,6 +134,8 @@ public: static const uint32 MAX_NUM_RENDER_BUFFERS = 8; static uint32 getMaxNumRenderBuffers() { return MAX_NUM_RENDER_BUFFERS; } + const GPUObjectPointer gpuObject {}; + protected: SwapchainPointer _swapchain; @@ -153,12 +155,6 @@ protected: // Non exposed Framebuffer(const Framebuffer& framebuffer) = delete; Framebuffer() {} - - // This shouldn't be used by anything else than the Backend class with the proper casting. - mutable GPUObject* _gpuObject = NULL; - void setGPUObject(GPUObject* gpuObject) const { _gpuObject = gpuObject; } - GPUObject* getGPUObject() const { return _gpuObject; } - friend class Backend; }; typedef std::shared_ptr FramebufferPointer; diff --git a/libraries/gpu/src/gpu/Pipeline.h b/libraries/gpu/src/gpu/Pipeline.h index adc65a0c66..28f7fe106e 100755 --- a/libraries/gpu/src/gpu/Pipeline.h +++ b/libraries/gpu/src/gpu/Pipeline.h @@ -31,6 +31,8 @@ public: const StatePointer& getState() const { return _state; } + const GPUObjectPointer gpuObject {}; + protected: ShaderPointer _program; StatePointer _state; @@ -38,12 +40,6 @@ protected: Pipeline(); Pipeline(const Pipeline& pipeline); // deep copy of the sysmem shader Pipeline& operator=(const Pipeline& pipeline); // deep copy of the sysmem texture - - // This shouldn't be used by anything else than the Backend class with the proper casting. - mutable GPUObject* _gpuObject = nullptr; - void setGPUObject(GPUObject* gpuObject) const { _gpuObject = gpuObject; } - GPUObject* getGPUObject() const { return _gpuObject; } - friend class Backend; }; typedef Pipeline::Pointer PipelinePointer; diff --git a/libraries/gpu/src/gpu/Query.h b/libraries/gpu/src/gpu/Query.h index d9c3185d9e..25897c5c91 100644 --- a/libraries/gpu/src/gpu/Query.h +++ b/libraries/gpu/src/gpu/Query.h @@ -28,13 +28,7 @@ namespace gpu { double getElapsedTime(); - protected: - - // This shouldn't be used by anything else than the Backend class with the proper casting. - mutable GPUObject* _gpuObject = NULL; - void setGPUObject(GPUObject* gpuObject) const { _gpuObject = gpuObject; } - GPUObject* getGPUObject() const { return _gpuObject; } - friend class Backend; + const GPUObjectPointer gpuObject {}; }; typedef std::shared_ptr QueryPointer; diff --git a/libraries/gpu/src/gpu/Resource.cpp b/libraries/gpu/src/gpu/Resource.cpp index c162b38b93..1788f6ece5 100644 --- a/libraries/gpu/src/gpu/Resource.cpp +++ b/libraries/gpu/src/gpu/Resource.cpp @@ -170,20 +170,17 @@ Resource::Size Resource::Sysmem::append(Size size, const Byte* bytes) { Buffer::Buffer() : Resource(), - _sysmem(new Sysmem()), - _gpuObject(NULL) { + _sysmem(new Sysmem()) { } Buffer::Buffer(Size size, const Byte* bytes) : Resource(), - _sysmem(new Sysmem(size, bytes)), - _gpuObject(NULL) { + _sysmem(new Sysmem(size, bytes)) { } Buffer::Buffer(const Buffer& buf) : Resource(), - _sysmem(new Sysmem(buf.getSysmem())), - _gpuObject(NULL) { + _sysmem(new Sysmem(buf.getSysmem())) { } Buffer& Buffer::operator=(const Buffer& buf) { @@ -196,10 +193,6 @@ Buffer::~Buffer() { delete _sysmem; _sysmem = NULL; } - if (_gpuObject) { - delete _gpuObject; - _gpuObject = NULL; - } } Buffer::Size Buffer::resize(Size size) { diff --git a/libraries/gpu/src/gpu/Resource.h b/libraries/gpu/src/gpu/Resource.h index 794ee680f4..3517b67203 100644 --- a/libraries/gpu/src/gpu/Resource.h +++ b/libraries/gpu/src/gpu/Resource.h @@ -153,16 +153,11 @@ public: const Sysmem& getSysmem() const { assert(_sysmem); return (*_sysmem); } Sysmem& editSysmem() { assert(_sysmem); return (*_sysmem); } + const GPUObjectPointer gpuObject {}; + protected: Sysmem* _sysmem = NULL; - - - // This shouldn't be used by anything else than the Backend class with the proper casting. - mutable GPUObject* _gpuObject = NULL; - void setGPUObject(GPUObject* gpuObject) const { _gpuObject = gpuObject; } - GPUObject* getGPUObject() const { return _gpuObject; } - friend class Backend; }; typedef std::shared_ptr BufferPointer; diff --git a/libraries/gpu/src/gpu/Shader.h b/libraries/gpu/src/gpu/Shader.h index b737a42e12..59c6401150 100755 --- a/libraries/gpu/src/gpu/Shader.h +++ b/libraries/gpu/src/gpu/Shader.h @@ -155,6 +155,8 @@ public: // independant of the graphics api in use underneath (looking at you opengl & vulkan). static bool makeProgram(Shader& shader, const Shader::BindingSet& bindings = Shader::BindingSet()); + const GPUObjectPointer gpuObject {}; + protected: Shader(Type type, const Source& source); Shader(Type type, const Pointer& vertex, const Pointer& pixel); @@ -178,12 +180,6 @@ protected: // The type of the shader, the master key Type _type; - - // This shouldn't be used by anything else than the Backend class with the proper casting. - mutable GPUObject* _gpuObject = NULL; - void setGPUObject(GPUObject* gpuObject) const { _gpuObject = gpuObject; } - GPUObject* getGPUObject() const { return _gpuObject; } - friend class Backend; }; typedef Shader::Pointer ShaderPointer; diff --git a/libraries/gpu/src/gpu/State.h b/libraries/gpu/src/gpu/State.h index 7740506bce..7e32a7280a 100755 --- a/libraries/gpu/src/gpu/State.h +++ b/libraries/gpu/src/gpu/State.h @@ -385,6 +385,8 @@ public: State(const Data& values); const Data& getValues() const { return _values; } + const GPUObjectPointer gpuObject {}; + protected: State(const State& state); State& operator=(const State& state); @@ -392,12 +394,6 @@ protected: Data _values; Signature _signature{0}; Stamp _stamp{0}; - - // This shouldn't be used by anything else than the Backend class with the proper casting. - mutable GPUObject* _gpuObject = nullptr; - void setGPUObject(GPUObject* gpuObject) const { _gpuObject = gpuObject; } - GPUObject* getGPUObject() const { return _gpuObject; } - friend class Backend; }; typedef std::shared_ptr< State > StatePointer; diff --git a/libraries/gpu/src/gpu/Texture.h b/libraries/gpu/src/gpu/Texture.h index 6e8eb10380..378f49c2f4 100755 --- a/libraries/gpu/src/gpu/Texture.h +++ b/libraries/gpu/src/gpu/Texture.h @@ -356,6 +356,8 @@ public: // Only callable by the Backend void notifyMipFaceGPULoaded(uint16 level, uint8 face) const { return _storage->notifyMipFaceGPULoaded(level, face); } + const GPUObjectPointer gpuObject {}; + protected: std::unique_ptr< Storage > _storage; @@ -386,13 +388,6 @@ protected: static Texture* create(Type type, const Element& texelFormat, uint16 width, uint16 height, uint16 depth, uint16 numSamples, uint16 numSlices, const Sampler& sampler); Size resize(Type type, const Element& texelFormat, uint16 width, uint16 height, uint16 depth, uint16 numSamples, uint16 numSlices); - - // This shouldn't be used by anything else than the Backend class with the proper casting. - mutable GPUObject* _gpuObject = NULL; - void setGPUObject(GPUObject* gpuObject) const { _gpuObject = gpuObject; } - GPUObject* getGPUObject() const { return _gpuObject; } - - friend class Backend; }; typedef std::shared_ptr TexturePointer; diff --git a/libraries/model-networking/src/model-networking/ModelCache.cpp b/libraries/model-networking/src/model-networking/ModelCache.cpp index 4fd47affc2..0bec7636b9 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.cpp +++ b/libraries/model-networking/src/model-networking/ModelCache.cpp @@ -22,8 +22,6 @@ #include "TextureCache.h" #include "ModelNetworkingLogging.h" -#include "gpu/StandardShaderLib.h" - #include "model/TextureMap.h" //#define WANT_DEBUG @@ -149,7 +147,6 @@ void NetworkGeometry::setTextureWithNameToURL(const QString& name, const QUrl& u if (_meshes.size() > 0) { auto textureCache = DependencyManager::get(); for (auto&& material : _materials) { - QSharedPointer matchingTexture = QSharedPointer(); if (material->diffuseTextureName == name) { material->diffuseTexture = textureCache->getTexture(url, DEFAULT_TEXTURE); } else if (material->normalTextureName == name) { diff --git a/libraries/model-networking/src/model-networking/ModelCache.h b/libraries/model-networking/src/model-networking/ModelCache.h index cd75794e2b..b2d81c5900 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.h +++ b/libraries/model-networking/src/model-networking/ModelCache.h @@ -48,9 +48,6 @@ public: /// \param delayLoad if true, don't load the geometry immediately; wait until load is first requested QSharedPointer getGeometry(const QUrl& url, const QUrl& fallback = QUrl(), bool delayLoad = false); - /// Set a batch to the simple pipeline, returning the previous pipeline - void useSimpleDrawPipeline(gpu::Batch& batch, bool noBlend = false); - private: ModelCache(); virtual ~ModelCache(); diff --git a/libraries/model-networking/src/model-networking/TextureCache.cpp b/libraries/model-networking/src/model-networking/TextureCache.cpp index ae705faf86..60f6d50d59 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.cpp +++ b/libraries/model-networking/src/model-networking/TextureCache.cpp @@ -72,11 +72,12 @@ const gpu::TexturePointer& TextureCache::getPermutationNormalTexture() { data[3*i+0] = permutation[i]; data[3*i+1] = permutation[i]; data[3*i+2] = permutation[i]; + } #else for (int i = 0; i < 256 * 3; i++) { data[i] = rand() % 256; -#endif } +#endif for (int i = 256 * 3; i < 256 * 3 * 2; i += 3) { glm::vec3 randvec = glm::sphericalRand(1.0f); @@ -173,19 +174,11 @@ QSharedPointer TextureCache::createResource(const QUrl& url, &Resource::allReferencesCleared); } -Texture::Texture() { -} - -Texture::~Texture() { -} - NetworkTexture::NetworkTexture(const QUrl& url, TextureType type, const QByteArray& content) : Resource(url, !content.isEmpty()), - _type(type), - _width(0), - _height(0) { - - _textureSource.reset(new gpu::TextureSource()); + _type(type) +{ + _textureSource = std::make_shared(); if (!url.isValid()) { _loaded = true; @@ -200,24 +193,9 @@ NetworkTexture::NetworkTexture(const QUrl& url, TextureType type, const QByteArr } NetworkTexture::NetworkTexture(const QUrl& url, const TextureLoaderFunc& textureLoader, const QByteArray& content) : - Resource(url, !content.isEmpty()), - _type(CUSTOM_TEXTURE), - _textureLoader(textureLoader), - _width(0), - _height(0) { - - _textureSource.reset(new gpu::TextureSource()); - - if (!url.isValid()) { - _loaded = true; - } - - std::string theName = url.toString().toStdString(); - // if we have content, load it after we have our self pointer - if (!content.isEmpty()) { - _startedLoading = true; - QMetaObject::invokeMethod(this, "loadContent", Qt::QueuedConnection, Q_ARG(const QByteArray&, content)); - } + NetworkTexture(url, CUSTOM_TEXTURE, content) +{ + _textureLoader = textureLoader; } NetworkTexture::TextureLoaderFunc NetworkTexture::getTextureLoader() const { @@ -247,57 +225,52 @@ NetworkTexture::TextureLoaderFunc NetworkTexture::getTextureLoader() const { } } } - + class ImageReader : public QRunnable { public: - ImageReader(const QWeakPointer& texture, const NetworkTexture::TextureLoaderFunc& textureLoader, const QByteArray& data, const QUrl& url = QUrl()); - + ImageReader(const QWeakPointer& texture, const QByteArray& data, const QUrl& url = QUrl()); + virtual void run(); private: - + static void listSupportedImageFormats(); + QWeakPointer _texture; - NetworkTexture::TextureLoaderFunc _textureLoader; QUrl _url; QByteArray _content; }; void NetworkTexture::downloadFinished(const QByteArray& data) { // send the reader off to the thread pool - QThreadPool::globalInstance()->start(new ImageReader(_self, getTextureLoader(), data, _url)); + QThreadPool::globalInstance()->start(new ImageReader(_self, data, _url)); } void NetworkTexture::loadContent(const QByteArray& content) { - QThreadPool::globalInstance()->start(new ImageReader(_self, getTextureLoader(), content, _url)); + QThreadPool::globalInstance()->start(new ImageReader(_self, content, _url)); } -ImageReader::ImageReader(const QWeakPointer& texture, const NetworkTexture::TextureLoaderFunc& textureLoader, const QByteArray& data, +ImageReader::ImageReader(const QWeakPointer& texture, const QByteArray& data, const QUrl& url) : _texture(texture), - _textureLoader(textureLoader), _url(url), _content(data) { - } -std::once_flag onceListSupportedFormatsflag; -void listSupportedImageFormats() { - std::call_once(onceListSupportedFormatsflag, [](){ +void ImageReader::listSupportedImageFormats() { + static std::once_flag once; + std::call_once(once, []{ auto supportedFormats = QImageReader::supportedImageFormats(); - QString formats; - foreach(const QByteArray& f, supportedFormats) { - formats += QString(f) + ","; - } - qCDebug(modelnetworking) << "List of supported Image formats:" << formats; + qCDebug(modelnetworking) << "List of supported Image formats:" << supportedFormats.join(", "); }); } void ImageReader::run() { - QSharedPointer texture = _texture.toStrongRef(); - if (texture.isNull()) { + auto texture = _texture.toStrongRef(); + if (!texture) { + qCWarning(modelnetworking) << "Could not get strong ref"; return; } @@ -324,7 +297,7 @@ void ImageReader::run() { } gpu::Texture* theTexture = nullptr; - auto ntex = dynamic_cast(&*texture); + auto ntex = texture.dynamicCast(); if (ntex) { theTexture = ntex->getTextureLoader()(image, _url.toString().toStdString()); } @@ -333,8 +306,6 @@ void ImageReader::run() { Q_ARG(const QImage&, image), Q_ARG(void*, theTexture), Q_ARG(int, originalWidth), Q_ARG(int, originalHeight)); - - } void NetworkTexture::setImage(const QImage& image, void* voidTexture, int originalWidth, diff --git a/libraries/model-networking/src/model-networking/TextureCache.h b/libraries/model-networking/src/model-networking/TextureCache.h index 4171b6c1cb..033b4bede6 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.h +++ b/libraries/model-networking/src/model-networking/TextureCache.h @@ -67,9 +67,6 @@ public: typedef gpu::Texture* TextureLoader(const QImage& image, const std::string& srcImageName); typedef std::function TextureLoaderFunc; - - NetworkTexturePointer getTexture(const QUrl& url, const TextureLoaderFunc& textureLoader, - const QByteArray& content = QByteArray()); protected: virtual QSharedPointer createResource(const QUrl& url, @@ -94,15 +91,9 @@ private: class Texture { public: friend class TextureCache; - Texture(); - ~Texture(); - const gpu::TexturePointer getGPUTexture() const { return _textureSource->getGPUTexture(); } + gpu::TexturePointer getGPUTexture() const { return _textureSource->getGPUTexture(); } gpu::TextureSourcePointer _textureSource; - -protected: - -private: }; /// A texture loaded from the network. @@ -134,14 +125,14 @@ protected: virtual void imageLoaded(const QImage& image); - TextureType _type; private: + TextureType _type; TextureLoaderFunc _textureLoader; - int _originalWidth; - int _originalHeight; - int _width; - int _height; + int _originalWidth { 0 }; + int _originalHeight { 0 }; + int _width { 0 }; + int _height { 0 }; }; #endif // hifi_TextureCache_h diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index f75469e820..2c09c3aa55 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -644,7 +644,7 @@ void EntityMotionState::computeCollisionGroupAndMask(int16_t& group, int16_t& ma mask = PhysicsEngine::getCollisionMask(group); if (_entity) { - uint8_t entityCollisionMask = _entity->getCollisionMask(); + uint8_t entityCollisionMask = _entity->getFinalCollisionMask(); if ((bool)(entityCollisionMask & USER_COLLISION_GROUP_MY_AVATAR) != (bool)(entityCollisionMask & USER_COLLISION_GROUP_OTHER_AVATAR)) { // asymmetric avatar collision mask bits diff --git a/libraries/physics/src/ObjectActionSpring.cpp b/libraries/physics/src/ObjectActionSpring.cpp index a737a2b8b6..3f2664fb12 100644 --- a/libraries/physics/src/ObjectActionSpring.cpp +++ b/libraries/physics/src/ObjectActionSpring.cpp @@ -63,8 +63,8 @@ void ObjectActionSpring::updateActionWorker(btScalar deltaTimeStep) { btVector3 targetVelocity(0.0f, 0.0f, 0.0f); float speed = (offsetLength > FLT_EPSILON) ? glm::min(offsetLength / _linearTimeScale, SPRING_MAX_SPEED) : 0.0f; + targetVelocity = (-speed / offsetLength) * offset; if (speed > rigidBody->getLinearSleepingThreshold()) { - targetVelocity = (-speed / offsetLength) * offset; rigidBody->activate(); } @@ -92,8 +92,8 @@ void ObjectActionSpring::updateActionWorker(btScalar deltaTimeStep) { // dQ = Q1 * Q0^ btQuaternion deltaQ = target * bodyRotation.inverse(); float speed = deltaQ.getAngle() / _angularTimeScale; + targetVelocity = speed * deltaQ.getAxis(); if (speed > rigidBody->getAngularSleepingThreshold()) { - targetVelocity = speed * deltaQ.getAxis(); rigidBody->activate(); } } diff --git a/libraries/render-utils/src/AmbientOcclusionEffect.cpp b/libraries/render-utils/src/AmbientOcclusionEffect.cpp index 44dfde13dc..87b7a0643d 100644 --- a/libraries/render-utils/src/AmbientOcclusionEffect.cpp +++ b/libraries/render-utils/src/AmbientOcclusionEffect.cpp @@ -18,14 +18,13 @@ #include #include #include +#include -#include "gpu/StandardShaderLib.h" #include "AmbientOcclusionEffect.h" #include "TextureCache.h" #include "FramebufferCache.h" #include "DependencyManager.h" #include "ViewFrustum.h" -#include "GeometryCache.h" #include "ssao_makePyramid_frag.h" #include "ssao_makeOcclusion_frag.h" @@ -314,6 +313,7 @@ void AmbientOcclusionEffect::run(const render::SceneContextPointer& sceneContext assert(renderContext->getArgs()->_viewFrustum); RenderArgs* args = renderContext->getArgs(); + auto framebufferCache = DependencyManager::get(); auto depthBuffer = framebufferCache->getPrimaryDepthTexture(); auto normalBuffer = framebufferCache->getDeferredNormalTexture(); @@ -395,5 +395,6 @@ void AmbientOcclusionEffect::run(const render::SceneContextPointer& sceneContext batch.setPipeline(lastVBlurPipeline); batch.setResourceTexture(AmbientOcclusionEffect_OcclusionMapSlot, occlusionBlurredFBO->getRenderBuffer(0)); batch.draw(gpu::TRIANGLE_STRIP, 4); + }); } diff --git a/libraries/render-utils/src/AntialiasingEffect.cpp b/libraries/render-utils/src/AntialiasingEffect.cpp index 3acc88f953..52e0836029 100644 --- a/libraries/render-utils/src/AntialiasingEffect.cpp +++ b/libraries/render-utils/src/AntialiasingEffect.cpp @@ -16,7 +16,6 @@ #include #include -#include "gpu/StandardShaderLib.h" #include "AntialiasingEffect.h" #include "TextureCache.h" #include "FramebufferCache.h" @@ -101,7 +100,7 @@ void Antialiasing::run(const render::SceneContextPointer& sceneContext, const re } RenderArgs* args = renderContext->getArgs(); - gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { + gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { batch.enableStereo(false); auto framebufferCache = DependencyManager::get(); diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index e6892b95f4..7c8aa393d4 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -17,18 +17,12 @@ #include #include -#include #include "AbstractViewStateInterface.h" #include "GeometryCache.h" #include "TextureCache.h" #include "FramebufferCache.h" - -#include "simple_vert.h" -#include "simple_textured_frag.h" -#include "simple_textured_emisive_frag.h" - #include "deferred_light_vert.h" #include "deferred_light_limited_vert.h" #include "deferred_light_spot_vert.h" @@ -53,47 +47,7 @@ struct LightLocations { static void loadLightProgram(const char* vertSource, const char* fragSource, bool lightVolume, gpu::PipelinePointer& program, LightLocationsPtr& locations); -gpu::PipelinePointer DeferredLightingEffect::getPipeline(SimpleProgramKey config) { - auto it = _simplePrograms.find(config); - if (it != _simplePrograms.end()) { - return it.value(); - } - - auto state = std::make_shared(); - if (config.isCulled()) { - state->setCullMode(gpu::State::CULL_BACK); - } else { - state->setCullMode(gpu::State::CULL_NONE); - } - state->setDepthTest(true, true, gpu::LESS_EQUAL); - if (config.hasDepthBias()) { - state->setDepthBias(1.0f); - state->setDepthBiasSlopeScale(1.0f); - } - state->setBlendFunction(false, - gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, - gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); - - gpu::ShaderPointer program = (config.isEmissive()) ? _emissiveShader : _simpleShader; - gpu::PipelinePointer pipeline = gpu::Pipeline::create(program, state); - _simplePrograms.insert(config, pipeline); - return pipeline; -} - void DeferredLightingEffect::init() { - auto VS = gpu::Shader::createVertex(std::string(simple_vert)); - auto PS = gpu::Shader::createPixel(std::string(simple_textured_frag)); - auto PSEmissive = gpu::Shader::createPixel(std::string(simple_textured_emisive_frag)); - - _simpleShader = gpu::Shader::createProgram(VS, PS); - _emissiveShader = gpu::Shader::createProgram(VS, PSEmissive); - - gpu::Shader::BindingSet slotBindings; - slotBindings.insert(gpu::Shader::Binding(std::string("normalFittingMap"), DeferredLightingEffect::NORMAL_FITTING_MAP_SLOT)); - gpu::Shader::makeProgram(*_simpleShader, slotBindings); - gpu::Shader::makeProgram(*_emissiveShader, slotBindings); - - _directionalLightLocations = std::make_shared(); _directionalAmbientSphereLightLocations = std::make_shared(); _directionalSkyboxLightLocations = std::make_shared(); @@ -123,144 +77,6 @@ void DeferredLightingEffect::init() { lp->setAmbientSpherePreset(gpu::SphericalHarmonics::Preset(_ambientLightMode % gpu::SphericalHarmonics::NUM_PRESET)); } - - -gpu::PipelinePointer DeferredLightingEffect::bindSimpleProgram(gpu::Batch& batch, bool textured, bool culled, - bool emissive, bool depthBias) { - SimpleProgramKey config{textured, culled, emissive, depthBias}; - gpu::PipelinePointer pipeline = getPipeline(config); - batch.setPipeline(pipeline); - - gpu::ShaderPointer program = (config.isEmissive()) ? _emissiveShader : _simpleShader; - - if (!config.isTextured()) { - // If it is not textured, bind white texture and keep using textured pipeline - batch.setResourceTexture(0, DependencyManager::get()->getWhiteTexture()); - } - - batch.setResourceTexture(NORMAL_FITTING_MAP_SLOT, DependencyManager::get()->getNormalFittingTexture()); - return pipeline; -} - -uint32_t toCompactColor(const glm::vec4& color) { - uint32_t compactColor = ((int(color.x * 255.0f) & 0xFF)) | - ((int(color.y * 255.0f) & 0xFF) << 8) | - ((int(color.z * 255.0f) & 0xFF) << 16) | - ((int(color.w * 255.0f) & 0xFF) << 24); - return compactColor; -} - -static const size_t INSTANCE_TRANSFORM_BUFFER = 0; -static const size_t INSTANCE_COLOR_BUFFER = 1; - -template -void renderInstances(const std::string& name, gpu::Batch& batch, const Transform& transform, const glm::vec4& color, F f) { - { - gpu::BufferPointer instanceTransformBuffer = batch.getNamedBuffer(name, INSTANCE_TRANSFORM_BUFFER); - glm::mat4 glmTransform; - instanceTransformBuffer->append(transform.getMatrix(glmTransform)); - - gpu::BufferPointer instanceColorBuffer = batch.getNamedBuffer(name, INSTANCE_COLOR_BUFFER); - auto compactColor = toCompactColor(color); - instanceColorBuffer->append(compactColor); - } - - auto that = DependencyManager::get(); - batch.setupNamedCalls(name, [=](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { - auto pipeline = that->bindSimpleProgram(batch); - auto location = pipeline->getProgram()->getUniforms().findLocation("Instanced"); - - batch._glUniform1i(location, 1); - f(batch, data); - batch._glUniform1i(location, 0); - }); -} - -void DeferredLightingEffect::renderSolidSphereInstance(gpu::Batch& batch, const Transform& transform, const glm::vec4& color) { - static const std::string INSTANCE_NAME = __FUNCTION__; - renderInstances(INSTANCE_NAME, batch, transform, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { - DependencyManager::get()->renderShapeInstances(batch, GeometryCache::Sphere, data._count, - data._buffers[INSTANCE_TRANSFORM_BUFFER], data._buffers[INSTANCE_COLOR_BUFFER]); - }); -} - -void DeferredLightingEffect::renderWireSphereInstance(gpu::Batch& batch, const Transform& transform, const glm::vec4& color) { - static const std::string INSTANCE_NAME = __FUNCTION__; - renderInstances(INSTANCE_NAME, batch, transform, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { - DependencyManager::get()->renderWireShapeInstances(batch, GeometryCache::Sphere, data._count, - data._buffers[INSTANCE_TRANSFORM_BUFFER], data._buffers[INSTANCE_COLOR_BUFFER]); - }); -} - -// Enable this in a debug build to cause 'box' entities to iterate through all the -// available shape types, both solid and wireframes -//#define DEBUG_SHAPES - -void DeferredLightingEffect::renderSolidCubeInstance(gpu::Batch& batch, const Transform& transform, const glm::vec4& color) { - static const std::string INSTANCE_NAME = __FUNCTION__; - -#ifdef DEBUG_SHAPES - static auto startTime = usecTimestampNow(); - renderInstances(INSTANCE_NAME, batch, transform, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { - - auto usecs = usecTimestampNow(); - usecs -= startTime; - auto msecs = usecs / USECS_PER_MSEC; - float seconds = msecs; - seconds /= MSECS_PER_SECOND; - float fractionalSeconds = seconds - floor(seconds); - int shapeIndex = (int)seconds; - - // Every second we flip to the next shape. - static const int SHAPE_COUNT = 5; - GeometryCache::Shape shapes[SHAPE_COUNT] = { - GeometryCache::Cube, - GeometryCache::Tetrahedron, - GeometryCache::Sphere, - GeometryCache::Icosahedron, - GeometryCache::Line, - }; - - shapeIndex %= SHAPE_COUNT; - GeometryCache::Shape shape = shapes[shapeIndex]; - - // For the first half second for a given shape, show the wireframe, for the second half, show the solid. - if (fractionalSeconds > 0.5f) { - DependencyManager::get()->renderShapeInstances(batch, shape, data._count, - data._buffers[INSTANCE_TRANSFORM_BUFFER], data._buffers[INSTANCE_COLOR_BUFFER]); - } else { - DependencyManager::get()->renderWireShapeInstances(batch, shape, data._count, - data._buffers[INSTANCE_TRANSFORM_BUFFER], data._buffers[INSTANCE_COLOR_BUFFER]); - } - }); -#else - renderInstances(INSTANCE_NAME, batch, transform, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { - DependencyManager::get()->renderCubeInstances(batch, data._count, - data._buffers[INSTANCE_TRANSFORM_BUFFER], data._buffers[INSTANCE_COLOR_BUFFER]); - }); -#endif -} - -void DeferredLightingEffect::renderWireCubeInstance(gpu::Batch& batch, const Transform& transform, const glm::vec4& color) { - static const std::string INSTANCE_NAME = __FUNCTION__; - renderInstances(INSTANCE_NAME, batch, transform, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { - DependencyManager::get()->renderWireCubeInstances(batch, data._count, - data._buffers[INSTANCE_TRANSFORM_BUFFER], data._buffers[INSTANCE_COLOR_BUFFER]); - }); -} - -void DeferredLightingEffect::renderQuad(gpu::Batch& batch, const glm::vec3& minCorner, const glm::vec3& maxCorner, - const glm::vec4& color) { - bindSimpleProgram(batch); - DependencyManager::get()->renderQuad(batch, minCorner, maxCorner, color); -} - -void DeferredLightingEffect::renderLine(gpu::Batch& batch, const glm::vec3& p1, const glm::vec3& p2, - const glm::vec4& color1, const glm::vec4& color2) { - bindSimpleProgram(batch); - DependencyManager::get()->renderLine(batch, p1, p2, color1, color2); -} - void DeferredLightingEffect::addPointLight(const glm::vec3& position, float radius, const glm::vec3& color, float intensity) { addSpotLight(position, radius, color, intensity); @@ -295,7 +111,7 @@ void DeferredLightingEffect::addSpotLight(const glm::vec3& position, float radiu } void DeferredLightingEffect::prepare(RenderArgs* args) { - gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { + gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { batch.enableStereo(false); batch.setViewportTransform(args->_viewport); batch.setStateScissorRect(args->_viewport); @@ -326,7 +142,7 @@ void DeferredLightingEffect::prepare(RenderArgs* args) { } void DeferredLightingEffect::render(RenderArgs* args) { - gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { + gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { // Allocate the parameters buffer used by all the deferred shaders if (!_deferredTransformBuffer[0]._buffer) { @@ -663,12 +479,12 @@ static void loadLightProgram(const char* vertSource, const char* fragSource, boo slotBindings.insert(gpu::Shader::Binding(std::string("specularMap"), 2)); slotBindings.insert(gpu::Shader::Binding(std::string("depthMap"), 3)); slotBindings.insert(gpu::Shader::Binding(std::string("skyboxMap"), 5)); - const int LIGHT_GPU_SLOT = 3; + static const int LIGHT_GPU_SLOT = 3; slotBindings.insert(gpu::Shader::Binding(std::string("lightBuffer"), LIGHT_GPU_SLOT)); - const int ATMOSPHERE_GPU_SLOT = 4; + static const int ATMOSPHERE_GPU_SLOT = 4; slotBindings.insert(gpu::Shader::Binding(std::string("atmosphereBufferUnit"), ATMOSPHERE_GPU_SLOT)); - - slotBindings.insert(gpu::Shader::Binding(std::string("deferredTransformBuffer"), DeferredLightingEffect::DEFERRED_TRANSFORM_BUFFER_SLOT)); + static const int DEFERRED_TRANSFORM_BUFFER_SLOT = 2; + slotBindings.insert(gpu::Shader::Binding(std::string("deferredTransformBuffer"), DEFERRED_TRANSFORM_BUFFER_SLOT)); gpu::Shader::makeProgram(*program, slotBindings); diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index f00f558122..cb746153a1 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -21,10 +21,7 @@ #include "model/Stage.h" #include "model/Geometry.h" -#include "render/ShapePipeline.h" - class RenderArgs; -class SimpleProgramKey; struct LightLocations; using LightLocationsPtr = std::shared_ptr; /// Handles deferred lighting for the bits that require it (voxels...) @@ -32,42 +29,7 @@ class DeferredLightingEffect : public Dependency { SINGLETON_DEPENDENCY public: - static const int NORMAL_FITTING_MAP_SLOT = render::ShapePipeline::Slot::NORMAL_FITTING_MAP; - static const int DEFERRED_TRANSFORM_BUFFER_SLOT = 2; - void init(); - - /// Sets up the state necessary to render static untextured geometry with the simple program. - gpu::PipelinePointer bindSimpleProgram(gpu::Batch& batch, bool textured = false, bool culled = true, - bool emissive = false, bool depthBias = false); - - void renderSolidSphereInstance(gpu::Batch& batch, const Transform& xfm, const glm::vec4& color); - void renderSolidSphereInstance(gpu::Batch& batch, const Transform& xfm, const glm::vec3& color) { - renderSolidSphereInstance(batch, xfm, glm::vec4(color, 1.0)); - } - - void renderWireSphereInstance(gpu::Batch& batch, const Transform& xfm, const glm::vec4& color); - void renderWireSphereInstance(gpu::Batch& batch, const Transform& xfm, const glm::vec3& color) { - renderWireSphereInstance(batch, xfm, glm::vec4(color, 1.0)); - } - - void renderSolidCubeInstance(gpu::Batch& batch, const Transform& xfm, const glm::vec4& color); - void renderSolidCubeInstance(gpu::Batch& batch, const Transform& xfm, const glm::vec3& color) { - renderSolidCubeInstance(batch, xfm, glm::vec4(color, 1.0)); - } - - void renderWireCubeInstance(gpu::Batch& batch, const Transform& xfm, const glm::vec4& color); - void renderWireCubeInstance(gpu::Batch& batch, const Transform& xfm, const glm::vec3& color) { - renderWireCubeInstance(batch, xfm, glm::vec4(color, 1.0)); - } - - - //// Renders a quad with the simple program. - void renderQuad(gpu::Batch& batch, const glm::vec3& minCorner, const glm::vec3& maxCorner, const glm::vec4& color); - - //// Renders a line with the simple program. - void renderLine(gpu::Batch& batch, const glm::vec3& p1, const glm::vec3& p2, - const glm::vec4& color1, const glm::vec4& color2); /// Adds a point light to render for the current frame. void addPointLight(const glm::vec3& position, float radius, const glm::vec3& color = glm::vec3(0.0f, 0.0f, 0.0f), @@ -90,17 +52,10 @@ public: void setGlobalSkybox(const model::SkyboxPointer& skybox); private: - DeferredLightingEffect() {} - virtual ~DeferredLightingEffect() { } + DeferredLightingEffect() = default; model::MeshPointer _spotLightMesh; model::MeshPointer getSpotLightMesh(); - - gpu::PipelinePointer getPipeline(SimpleProgramKey config); - - gpu::ShaderPointer _simpleShader; - gpu::ShaderPointer _emissiveShader; - QHash _simplePrograms; gpu::PipelinePointer _directionalSkyboxLight; LightLocationsPtr _directionalSkyboxLightLocations; @@ -160,53 +115,4 @@ private: UniformBufferView _deferredTransformBuffer[2]; }; -class SimpleProgramKey { -public: - enum FlagBit { - IS_TEXTURED_FLAG = 0, - IS_CULLED_FLAG, - IS_EMISSIVE_FLAG, - HAS_DEPTH_BIAS_FLAG, - - NUM_FLAGS, - }; - - enum Flag { - IS_TEXTURED = (1 << IS_TEXTURED_FLAG), - IS_CULLED = (1 << IS_CULLED_FLAG), - IS_EMISSIVE = (1 << IS_EMISSIVE_FLAG), - HAS_DEPTH_BIAS = (1 << HAS_DEPTH_BIAS_FLAG), - }; - typedef unsigned short Flags; - - bool isFlag(short flagNum) const { return bool((_flags & flagNum) != 0); } - - bool isTextured() const { return isFlag(IS_TEXTURED); } - bool isCulled() const { return isFlag(IS_CULLED); } - bool isEmissive() const { return isFlag(IS_EMISSIVE); } - bool hasDepthBias() const { return isFlag(HAS_DEPTH_BIAS); } - - Flags _flags = 0; - short _spare = 0; - - int getRaw() const { return *reinterpret_cast(this); } - - - SimpleProgramKey(bool textured = false, bool culled = true, - bool emissive = false, bool depthBias = false) { - _flags = (textured ? IS_TEXTURED : 0) | (culled ? IS_CULLED : 0) | - (emissive ? IS_EMISSIVE : 0) | (depthBias ? HAS_DEPTH_BIAS : 0); - } - - SimpleProgramKey(int bitmask) : _flags(bitmask) {} -}; - -inline uint qHash(const SimpleProgramKey& key, uint seed) { - return qHash(key.getRaw(), seed); -} - -inline bool operator==(const SimpleProgramKey& a, const SimpleProgramKey& b) { - return a.getRaw() == b.getRaw(); -} - #endif // hifi_DeferredLightingEffect_h diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 5ae90e2124..35773e8748 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -29,6 +29,10 @@ #include "model/TextureMap.h" +#include "simple_vert.h" +#include "simple_textured_frag.h" +#include "simple_textured_emisive_frag.h" + //#define WANT_DEBUG const int GeometryCache::UNKNOWN_ID = -1; @@ -36,17 +40,6 @@ const int GeometryCache::UNKNOWN_ID = -1; static const int VERTICES_PER_TRIANGLE = 3; -//static const uint FLOATS_PER_VERTEX = 3; -//static const uint TRIANGLES_PER_QUAD = 2; -//static const uint CUBE_FACES = 6; -//static const uint CUBE_VERTICES_PER_FACE = 4; -//static const uint CUBE_VERTICES = CUBE_FACES * CUBE_VERTICES_PER_FACE; -//static const uint CUBE_VERTEX_POINTS = CUBE_VERTICES * FLOATS_PER_VERTEX; -//static const uint CUBE_INDICES = CUBE_FACES * TRIANGLES_PER_QUAD * VERTICES_PER_TRIANGLE; -//static const uint SPHERE_LATITUDES = 24; -//static const uint SPHERE_MERIDIANS = SPHERE_LATITUDES * 2; -//static const uint SPHERE_INDICES = SPHERE_MERIDIANS * (SPHERE_LATITUDES - 1) * TRIANGLES_PER_QUAD * VERTICES_PER_TRIANGLE; - static const gpu::Element POSITION_ELEMENT{ gpu::VEC3, gpu::FLOAT, gpu::XYZ }; static const gpu::Element NORMAL_ELEMENT{ gpu::VEC3, gpu::FLOAT, gpu::XYZ }; static const gpu::Element COLOR_ELEMENT{ gpu::VEC4, gpu::NUINT8, gpu::RGBA }; @@ -1741,3 +1734,227 @@ void GeometryCache::useSimpleDrawPipeline(gpu::Batch& batch, bool noBlend) { } } + + +class SimpleProgramKey { +public: + enum FlagBit { + IS_TEXTURED_FLAG = 0, + IS_CULLED_FLAG, + IS_EMISSIVE_FLAG, + HAS_DEPTH_BIAS_FLAG, + + NUM_FLAGS, + }; + + enum Flag { + IS_TEXTURED = (1 << IS_TEXTURED_FLAG), + IS_CULLED = (1 << IS_CULLED_FLAG), + IS_EMISSIVE = (1 << IS_EMISSIVE_FLAG), + HAS_DEPTH_BIAS = (1 << HAS_DEPTH_BIAS_FLAG), + }; + typedef unsigned short Flags; + + bool isFlag(short flagNum) const { return bool((_flags & flagNum) != 0); } + + bool isTextured() const { return isFlag(IS_TEXTURED); } + bool isCulled() const { return isFlag(IS_CULLED); } + bool isEmissive() const { return isFlag(IS_EMISSIVE); } + bool hasDepthBias() const { return isFlag(HAS_DEPTH_BIAS); } + + Flags _flags = 0; + short _spare = 0; + + int getRaw() const { return *reinterpret_cast(this); } + + + SimpleProgramKey(bool textured = false, bool culled = true, + bool emissive = false, bool depthBias = false) { + _flags = (textured ? IS_TEXTURED : 0) | (culled ? IS_CULLED : 0) | + (emissive ? IS_EMISSIVE : 0) | (depthBias ? HAS_DEPTH_BIAS : 0); + } + + SimpleProgramKey(int bitmask) : _flags(bitmask) {} +}; + +inline uint qHash(const SimpleProgramKey& key, uint seed) { + return qHash(key.getRaw(), seed); +} + +inline bool operator==(const SimpleProgramKey& a, const SimpleProgramKey& b) { + return a.getRaw() == b.getRaw(); +} + +gpu::PipelinePointer GeometryCache::getPipeline(SimpleProgramKey config) { + static std::once_flag once; + std::call_once(once, [&]() { + auto VS = gpu::Shader::createVertex(std::string(simple_vert)); + auto PS = gpu::Shader::createPixel(std::string(simple_textured_frag)); + auto PSEmissive = gpu::Shader::createPixel(std::string(simple_textured_emisive_frag)); + + _simpleShader = gpu::Shader::createProgram(VS, PS); + _emissiveShader = gpu::Shader::createProgram(VS, PSEmissive); + + gpu::Shader::BindingSet slotBindings; + slotBindings.insert(gpu::Shader::Binding(std::string("normalFittingMap"), render::ShapePipeline::Slot::NORMAL_FITTING_MAP)); + gpu::Shader::makeProgram(*_simpleShader, slotBindings); + gpu::Shader::makeProgram(*_emissiveShader, slotBindings); + }); + + + auto it = _simplePrograms.find(config); + if (it != _simplePrograms.end()) { + return it.value(); + } + + auto state = std::make_shared(); + if (config.isCulled()) { + state->setCullMode(gpu::State::CULL_BACK); + } else { + state->setCullMode(gpu::State::CULL_NONE); + } + state->setDepthTest(true, true, gpu::LESS_EQUAL); + if (config.hasDepthBias()) { + state->setDepthBias(1.0f); + state->setDepthBiasSlopeScale(1.0f); + } + state->setBlendFunction(false, + gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, + gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); + + gpu::ShaderPointer program = (config.isEmissive()) ? _emissiveShader : _simpleShader; + gpu::PipelinePointer pipeline = gpu::Pipeline::create(program, state); + _simplePrograms.insert(config, pipeline); + return pipeline; +} + +gpu::PipelinePointer GeometryCache::bindSimpleProgram(gpu::Batch& batch, bool textured, bool culled, + bool emissive, bool depthBias) { + SimpleProgramKey config{textured, culled, emissive, depthBias}; + gpu::PipelinePointer pipeline = getPipeline(config); + batch.setPipeline(pipeline); + + gpu::ShaderPointer program = (config.isEmissive()) ? _emissiveShader : _simpleShader; + + if (!config.isTextured()) { + // If it is not textured, bind white texture and keep using textured pipeline + batch.setResourceTexture(0, DependencyManager::get()->getWhiteTexture()); + } + + batch.setResourceTexture(render::ShapePipeline::Slot::NORMAL_FITTING_MAP, + DependencyManager::get()->getNormalFittingTexture()); + return pipeline; +} + +uint32_t toCompactColor(const glm::vec4& color) { + uint32_t compactColor = ((int(color.x * 255.0f) & 0xFF)) | + ((int(color.y * 255.0f) & 0xFF) << 8) | + ((int(color.z * 255.0f) & 0xFF) << 16) | + ((int(color.w * 255.0f) & 0xFF) << 24); + return compactColor; +} + +static const size_t INSTANCE_TRANSFORM_BUFFER = 0; +static const size_t INSTANCE_COLOR_BUFFER = 1; + +template +void renderInstances(const std::string& name, gpu::Batch& batch, const Transform& transform, const glm::vec4& color, F f) { + { + gpu::BufferPointer instanceTransformBuffer = batch.getNamedBuffer(name, INSTANCE_TRANSFORM_BUFFER); + glm::mat4 glmTransform; + instanceTransformBuffer->append(transform.getMatrix(glmTransform)); + + gpu::BufferPointer instanceColorBuffer = batch.getNamedBuffer(name, INSTANCE_COLOR_BUFFER); + auto compactColor = toCompactColor(color); + instanceColorBuffer->append(compactColor); + } + + batch.setupNamedCalls(name, [f](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { + auto pipeline = DependencyManager::get()->bindSimpleProgram(batch); + auto location = pipeline->getProgram()->getUniforms().findLocation("Instanced"); + + batch._glUniform1i(location, 1); + f(batch, data); + batch._glUniform1i(location, 0); + }); +} + +void GeometryCache::renderSolidSphereInstance(gpu::Batch& batch, const Transform& transform, const glm::vec4& color) { + static const std::string INSTANCE_NAME = __FUNCTION__; + renderInstances(INSTANCE_NAME, batch, transform, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { + DependencyManager::get()->renderShapeInstances(batch, GeometryCache::Sphere, data.count, + data.buffers[INSTANCE_TRANSFORM_BUFFER], + data.buffers[INSTANCE_COLOR_BUFFER]); + }); +} + +void GeometryCache::renderWireSphereInstance(gpu::Batch& batch, const Transform& transform, const glm::vec4& color) { + static const std::string INSTANCE_NAME = __FUNCTION__; + renderInstances(INSTANCE_NAME, batch, transform, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { + DependencyManager::get()->renderWireShapeInstances(batch, GeometryCache::Sphere, data.count, + data.buffers[INSTANCE_TRANSFORM_BUFFER], + data.buffers[INSTANCE_COLOR_BUFFER]); + }); +} + +// Enable this in a debug build to cause 'box' entities to iterate through all the +// available shape types, both solid and wireframes +//#define DEBUG_SHAPES + +void GeometryCache::renderSolidCubeInstance(gpu::Batch& batch, const Transform& transform, const glm::vec4& color) { + static const std::string INSTANCE_NAME = __FUNCTION__; + +#ifdef DEBUG_SHAPES + static auto startTime = usecTimestampNow(); + renderInstances(INSTANCE_NAME, batch, transform, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { + + auto usecs = usecTimestampNow(); + usecs -= startTime; + auto msecs = usecs / USECS_PER_MSEC; + float seconds = msecs; + seconds /= MSECS_PER_SECOND; + float fractionalSeconds = seconds - floor(seconds); + int shapeIndex = (int)seconds; + + // Every second we flip to the next shape. + static const int SHAPE_COUNT = 5; + GeometryCache::Shape shapes[SHAPE_COUNT] = { + GeometryCache::Cube, + GeometryCache::Tetrahedron, + GeometryCache::Sphere, + GeometryCache::Icosahedron, + GeometryCache::Line, + }; + + shapeIndex %= SHAPE_COUNT; + GeometryCache::Shape shape = shapes[shapeIndex]; + + // For the first half second for a given shape, show the wireframe, for the second half, show the solid. + if (fractionalSeconds > 0.5f) { + DependencyManager::get()->renderShapeInstances(batch, shape, data.count, + data.buffers[INSTANCE_TRANSFORM_BUFFER], + data.buffers[INSTANCE_COLOR_BUFFER]); + } else { + DependencyManager::get()->renderWireShapeInstances(batch, shape, data.count, + data.buffers[INSTANCE_TRANSFORM_BUFFER], + data.buffers[INSTANCE_COLOR_BUFFER]); + } + }); +#else + renderInstances(INSTANCE_NAME, batch, transform, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { + DependencyManager::get()->renderCubeInstances(batch, data.count, + data.buffers[INSTANCE_TRANSFORM_BUFFER], + data.buffers[INSTANCE_COLOR_BUFFER]); + }); +#endif +} + +void GeometryCache::renderWireCubeInstance(gpu::Batch& batch, const Transform& transform, const glm::vec4& color) { + static const std::string INSTANCE_NAME = __FUNCTION__; + renderInstances(INSTANCE_NAME, batch, transform, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { + DependencyManager::get()->renderWireCubeInstances(batch, data.count, + data.buffers[INSTANCE_TRANSFORM_BUFFER], + data.buffers[INSTANCE_COLOR_BUFFER]); + }); +} + diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index c408115011..90ba3be978 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -16,7 +16,6 @@ #include - #include #include @@ -25,10 +24,13 @@ #include #include +#include #include #include +class SimpleProgramKey; + typedef glm::vec3 Vec3Key; typedef QPair Vec2Pair; @@ -146,6 +148,32 @@ public: int allocateID() { return _nextID++; } static const int UNKNOWN_ID; + + + /// Sets up the state necessary to render static untextured geometry with the simple program. + gpu::PipelinePointer bindSimpleProgram(gpu::Batch& batch, bool textured = false, bool culled = true, + bool emissive = false, bool depthBias = false); + + void renderSolidSphereInstance(gpu::Batch& batch, const Transform& xfm, const glm::vec4& color); + void renderSolidSphereInstance(gpu::Batch& batch, const Transform& xfm, const glm::vec3& color) { + renderSolidSphereInstance(batch, xfm, glm::vec4(color, 1.0)); + } + + void renderWireSphereInstance(gpu::Batch& batch, const Transform& xfm, const glm::vec4& color); + void renderWireSphereInstance(gpu::Batch& batch, const Transform& xfm, const glm::vec3& color) { + renderWireSphereInstance(batch, xfm, glm::vec4(color, 1.0)); + } + + void renderSolidCubeInstance(gpu::Batch& batch, const Transform& xfm, const glm::vec4& color); + void renderSolidCubeInstance(gpu::Batch& batch, const Transform& xfm, const glm::vec3& color) { + renderSolidCubeInstance(batch, xfm, glm::vec4(color, 1.0)); + } + + void renderWireCubeInstance(gpu::Batch& batch, const Transform& xfm, const glm::vec4& color); + void renderWireCubeInstance(gpu::Batch& batch, const Transform& xfm, const glm::vec3& color) { + renderWireCubeInstance(batch, xfm, glm::vec4(color, 1.0)); + } + void renderShapeInstances(gpu::Batch& batch, Shape shape, size_t count, gpu::BufferPointer& transformBuffer, gpu::BufferPointer& colorBuffer); void renderWireShapeInstances(gpu::Batch& batch, Shape shape, size_t count, gpu::BufferPointer& transformBuffer, gpu::BufferPointer& colorBuffer); @@ -335,6 +363,13 @@ private: QHash _gridColors; QHash > _networkGeometry; + + + gpu::PipelinePointer getPipeline(SimpleProgramKey config); + + gpu::ShaderPointer _simpleShader; + gpu::ShaderPointer _emissiveShader; + QHash _simplePrograms; }; #endif // hifi_GeometryCache_h diff --git a/libraries/render-utils/src/HitEffect.cpp b/libraries/render-utils/src/HitEffect.cpp index bf65eaf059..89f950d830 100644 --- a/libraries/render-utils/src/HitEffect.cpp +++ b/libraries/render-utils/src/HitEffect.cpp @@ -64,7 +64,7 @@ void HitEffect::run(const render::SceneContextPointer& sceneContext, const rende assert(renderContext->getArgs()); assert(renderContext->getArgs()->_viewFrustum); RenderArgs* args = renderContext->getArgs(); - gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { + gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { glm::mat4 projMat; Transform viewMat; diff --git a/libraries/render-utils/src/MeshPartPayload.cpp b/libraries/render-utils/src/MeshPartPayload.cpp index 492021c1a9..3fe639b47f 100644 --- a/libraries/render-utils/src/MeshPartPayload.cpp +++ b/libraries/render-utils/src/MeshPartPayload.cpp @@ -499,7 +499,7 @@ void ModelMeshPartPayload::render(RenderArgs* args) const { transform.setTranslation(partBounds.calcCenter()); transform.setScale(partBounds.getDimensions()); batch.setModelTransform(transform); - DependencyManager::get()->renderWireCube(batch, 1.0f, cubeColor); + DependencyManager::get()->renderWireCube(batch, 1.0f, cubeColor); } #endif //def DEBUG_BOUNDING_PARTS diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index a7bdd42b7e..14da2b3102 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -358,7 +358,7 @@ void DrawStencilDeferred::run(const SceneContextPointer& sceneContext, const Ren // from the touched pixel generate the stencil buffer RenderArgs* args = renderContext->getArgs(); - doInBatch(args->_context, [=](gpu::Batch& batch) { + doInBatch(args->_context, [&](gpu::Batch& batch) { args->_batch = &batch; auto deferredFboColorDepthStencil = DependencyManager::get()->getDeferredFramebufferDepthColor(); @@ -393,7 +393,7 @@ void DrawBackgroundDeferred::run(const SceneContextPointer& sceneContext, const inItems.emplace_back(id); } RenderArgs* args = renderContext->getArgs(); - doInBatch(args->_context, [=](gpu::Batch& batch) { + doInBatch(args->_context, [&](gpu::Batch& batch) { args->_batch = &batch; auto lightingFBO = DependencyManager::get()->getLightingFramebuffer(); @@ -437,7 +437,7 @@ void Blit::run(const SceneContextPointer& sceneContext, const RenderContextPoint auto framebufferCache = DependencyManager::get(); auto primaryFbo = framebufferCache->getPrimaryFramebuffer(); - gpu::doInBatch(renderArgs->_context, [=](gpu::Batch& batch) { + gpu::doInBatch(renderArgs->_context, [&](gpu::Batch& batch) { batch.setFramebuffer(blitFbo); if (renderArgs->_renderMode == RenderArgs::MIRROR_RENDER_MODE) { diff --git a/libraries/render-utils/src/TextRenderer3D.cpp b/libraries/render-utils/src/TextRenderer3D.cpp index c3056be00b..6d10ed7069 100644 --- a/libraries/render-utils/src/TextRenderer3D.cpp +++ b/libraries/render-utils/src/TextRenderer3D.cpp @@ -29,7 +29,6 @@ #include "sdf_text3D_frag.h" #include "GeometryCache.h" -#include "DeferredLightingEffect.h" const float TextRenderer3D::DEFAULT_POINT_SIZE = 12; diff --git a/libraries/render-utils/src/ToneMappingEffect.cpp b/libraries/render-utils/src/ToneMappingEffect.cpp index 81c25bb4b8..55b7d41ab3 100644 --- a/libraries/render-utils/src/ToneMappingEffect.cpp +++ b/libraries/render-utils/src/ToneMappingEffect.cpp @@ -115,7 +115,7 @@ void ToneMappingEffect::render(RenderArgs* args) { init(); } auto framebufferCache = DependencyManager::get(); - gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { + gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { batch.enableStereo(false); QSize framebufferSize = framebufferCache->getFrameBufferSize(); diff --git a/libraries/render/src/render/DrawStatus.cpp b/libraries/render/src/render/DrawStatus.cpp index fa177bd0d4..3f919b3d8c 100644 --- a/libraries/render/src/render/DrawStatus.cpp +++ b/libraries/render/src/render/DrawStatus.cpp @@ -160,7 +160,7 @@ void DrawStatus::run(const SceneContextPointer& sceneContext, } // Allright, something to render let's do it - gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { + gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { glm::mat4 projMat; Transform viewMat; args->_viewFrustum->evalProjectionMatrix(projMat); diff --git a/libraries/render/src/render/DrawTask.cpp b/libraries/render/src/render/DrawTask.cpp index 2b977081a1..88aeb55ffc 100755 --- a/libraries/render/src/render/DrawTask.cpp +++ b/libraries/render/src/render/DrawTask.cpp @@ -212,7 +212,7 @@ void DrawLight::run(const SceneContextPointer& sceneContext, const RenderContext args->_details.pointTo(RenderDetails::OTHER_ITEM); cullItems(sceneContext, renderContext, inItems, culledItems); - gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { + gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { args->_batch = &batch; renderLights(sceneContext, renderContext, culledItems); args->_batch = nullptr; diff --git a/libraries/script-engine/src/ScriptEngines.cpp b/libraries/script-engine/src/ScriptEngines.cpp index 0a646bd696..0a0b2de47e 100644 --- a/libraries/script-engine/src/ScriptEngines.cpp +++ b/libraries/script-engine/src/ScriptEngines.cpp @@ -42,6 +42,17 @@ ScriptEngines::ScriptEngines() _scriptsModelFilter.setDynamicSortFilter(true); } +QString normalizeScriptUrl(const QString& rawScriptUrl) { + auto lower = rawScriptUrl.toLower(); + if (!rawScriptUrl.startsWith("http:") && !rawScriptUrl.startsWith("https:") && !rawScriptUrl.startsWith("atp:")) { + if (rawScriptUrl.startsWith("file:")) { + return rawScriptUrl.toLower(); + } + // Force lowercase on file scripts because of drive letter weirdness. + return QUrl::fromLocalFile(rawScriptUrl).toString().toLower(); + } + return QUrl(rawScriptUrl).toString(); +} QObject* scriptsModel(); @@ -290,22 +301,23 @@ void ScriptEngines::stopAllScripts(bool restart) { } } -bool ScriptEngines::stopScript(const QString& scriptHash, bool restart) { +bool ScriptEngines::stopScript(const QString& rawScriptUrl, bool restart) { bool stoppedScript = false; { QReadLocker lock(&_scriptEnginesHashLock); - if (_scriptEnginesHash.contains(scriptHash)) { - ScriptEngine* scriptEngine = _scriptEnginesHash[scriptHash]; + const QString scriptURLString = normalizeScriptUrl(rawScriptUrl); + if (_scriptEnginesHash.contains(scriptURLString)) { + ScriptEngine* scriptEngine = _scriptEnginesHash[scriptURLString]; if (restart) { auto scriptCache = DependencyManager::get(); - scriptCache->deleteScript(QUrl(scriptHash)); + scriptCache->deleteScript(QUrl(scriptURLString)); connect(scriptEngine, &ScriptEngine::finished, this, [this](QString scriptName, ScriptEngine* engine) { reloadScript(scriptName); }); } scriptEngine->stop(); stoppedScript = true; - qCDebug(scriptengine) << "stopping script..." << scriptHash; + qCDebug(scriptengine) << "stopping script..." << scriptURLString; } } return stoppedScript; @@ -364,11 +376,12 @@ ScriptEngine* ScriptEngines::loadScript(const QString& scriptFilename, bool isUs return scriptEngine; } -ScriptEngine* ScriptEngines::getScriptEngine(const QString& scriptHash) { +ScriptEngine* ScriptEngines::getScriptEngine(const QString& rawScriptUrl) { ScriptEngine* result = nullptr; { QReadLocker lock(&_scriptEnginesHashLock); - auto it = _scriptEnginesHash.find(scriptHash); + const QString scriptURLString = normalizeScriptUrl(rawScriptUrl); + auto it = _scriptEnginesHash.find(scriptURLString); if (it != _scriptEnginesHash.end()) { result = it.value(); } @@ -377,15 +390,16 @@ ScriptEngine* ScriptEngines::getScriptEngine(const QString& scriptHash) { } // FIXME - change to new version of ScriptCache loading notification -void ScriptEngines::onScriptEngineLoaded(const QString& scriptFilename) { - UserActivityLogger::getInstance().loadedScript(scriptFilename); +void ScriptEngines::onScriptEngineLoaded(const QString& rawScriptUrl) { + UserActivityLogger::getInstance().loadedScript(rawScriptUrl); ScriptEngine* scriptEngine = qobject_cast(sender()); launchScriptEngine(scriptEngine); { QWriteLocker lock(&_scriptEnginesHashLock); - _scriptEnginesHash.insertMulti(scriptFilename, scriptEngine); + const QString scriptURLString = normalizeScriptUrl(rawScriptUrl); + _scriptEnginesHash.insertMulti(scriptURLString, scriptEngine); } emit scriptCountChanged(); } @@ -407,11 +421,11 @@ void ScriptEngines::launchScriptEngine(ScriptEngine* scriptEngine) { } -void ScriptEngines::onScriptFinished(const QString& scriptName, ScriptEngine* engine) { +void ScriptEngines::onScriptFinished(const QString& rawScriptUrl, ScriptEngine* engine) { bool removed = false; { QWriteLocker lock(&_scriptEnginesHashLock); - const QString& scriptURLString = QUrl(scriptName).toString(); + const QString scriptURLString = normalizeScriptUrl(rawScriptUrl); for (auto it = _scriptEnginesHash.find(scriptURLString); it != _scriptEnginesHash.end(); ++it) { if (it.value() == engine) { _scriptEnginesHash.erase(it); diff --git a/tests/gpu-test/src/main.cpp b/tests/gpu-test/src/main.cpp index e185266408..de5aa877eb 100644 --- a/tests/gpu-test/src/main.cpp +++ b/tests/gpu-test/src/main.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include @@ -247,7 +246,7 @@ public: batch.setModelTransform(Transform()); batch.setPipeline(_pipeline); batch._glUniform1i(_instanceLocation, 1); - geometryCache->renderWireShapeInstances(batch, GeometryCache::Line, data._count, transformBuffer, colorBuffer); + geometryCache->renderWireShapeInstances(batch, GeometryCache::Line, data.count, transformBuffer, colorBuffer); batch._glUniform1i(_instanceLocation, 0); }); } diff --git a/unpublishedScripts/hiddenEntityReset.js b/unpublishedScripts/hiddenEntityReset.js index 4352a5d562..8f095ba0c5 100644 --- a/unpublishedScripts/hiddenEntityReset.js +++ b/unpublishedScripts/hiddenEntityReset.js @@ -113,7 +113,6 @@ z: 504.5 }); - createCombinedArmChair({ x: 549.29, y: 494.9, @@ -300,12 +299,17 @@ userData: JSON.stringify({ grabbableKey: { spatialKey: { - relativePosition: { - x: 0, - y: 0, - z: 0 + rightRelativePosition: { + x: 0.03, + y: 0.0, + z: -0.065 }, - relativeRotation: Quat.fromPitchYawRollDegrees(45, 90, 0) + leftRelativePosition: { + x: -0.03, + y: 0.00, + z: -0.065 + }, + relativeRotation: Quat.fromPitchYawRollDegrees(90, 90, 0) }, invertSolidWhileHeld: true }, @@ -359,12 +363,17 @@ grabbableKey: { invertSolidWhileHeld: true, spatialKey: { - relativePosition: { - x: 0, - y: 0.06, + rightRelativePosition: { + x: 0.03, + y: 0.08, z: 0.11 }, - relativeRotation: Quat.fromPitchYawRollDegrees(0, -90, 90) + leftRelativePosition: { + x: -0.03, + y: 0.08, + z: 0.11 + }, + relativeRotation: Quat.fromPitchYawRollDegrees(180, 90, 90) } } }) @@ -1151,10 +1160,15 @@ }, grabbableKey: { spatialKey: { - relativePosition: { + rightRelativePosition: { x: -0.05, - y: 0, - z: 0.0 + y: .06, + z: 0.05 + }, + leftRelativePosition: { + x: 0.05, + y: 0.06, + z: 0.05 }, relativeRotation: Quat.fromPitchYawRollDegrees(0, -90, -90) }, @@ -1509,4 +1523,4 @@ }; // entity scripts always need to return a newly constructed object of our type return new ResetSwitch(); -}); +}); \ No newline at end of file diff --git a/unpublishedScripts/masterReset.js b/unpublishedScripts/masterReset.js index 8aedd1c650..e6605c17e0 100644 --- a/unpublishedScripts/masterReset.js +++ b/unpublishedScripts/masterReset.js @@ -285,16 +285,16 @@ MasterReset = function() { grabbableKey: { spatialKey: { rightRelativePosition: { - x: 0.02, - y: 0, - z: -0.03 + x: 0.03, + y: 0.0, + z: -0.065 }, leftRelativePosition: { - x: -0.02, - y: 0, - z: -0.03 + x: -0.03, + y: 0.00, + z: -0.065 }, - relativeRotation: Quat.fromPitchYawRollDegrees(100, 90, 0) + relativeRotation: Quat.fromPitchYawRollDegrees(90, 90, 0) }, invertSolidWhileHeld: true }, @@ -348,12 +348,17 @@ MasterReset = function() { grabbableKey: { invertSolidWhileHeld: true, spatialKey: { - relativePosition: { - x: 0, - y: 0.06, + rightRelativePosition: { + x: 0.03, + y: 0.08, z: 0.11 }, - relativeRotation: Quat.fromPitchYawRollDegrees(0, -90, 90) + leftRelativePosition: { + x: -0.03, + y: 0.08, + z: 0.11 + }, + relativeRotation: Quat.fromPitchYawRollDegrees(180, 90, 90) } } }) @@ -1141,10 +1146,15 @@ MasterReset = function() { }, grabbableKey: { spatialKey: { - relativePosition: { - x: 0, - y: 0, - z: 0.06 + rightRelativePosition: { + x: -0.05, + y: .06, + z: 0.05 + }, + leftRelativePosition: { + x: 0.05, + y: 0.06, + z: 0.05 }, relativeRotation: Quat.fromPitchYawRollDegrees(0, -90, -90) }, @@ -1494,4 +1504,4 @@ MasterReset = function() { Script.scriptEnding.connect(cleanup); } -}; +}; \ No newline at end of file