From 5050171d30b3e74321de840143a2cb6d0cc451f2 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 13 May 2015 11:34:19 -0700 Subject: [PATCH 01/23] Fix face-tracked head disappearing into body Normalize quaternion to ensure that acos(r.w) is valid (r.w <= 1.0) and r.w = 1.0 when r.x = r.y = r.z = 0.0. --- interface/src/devices/DdeFaceTracker.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/devices/DdeFaceTracker.cpp b/interface/src/devices/DdeFaceTracker.cpp index e0b888746f..db90f92f37 100644 --- a/interface/src/devices/DdeFaceTracker.cpp +++ b/interface/src/devices/DdeFaceTracker.cpp @@ -382,7 +382,7 @@ void DdeFaceTracker::decodePacket(const QByteArray& buffer) { // Compute relative rotation rotation = glm::inverse(_referenceRotation) * rotation; if (isFiltering) { - glm::quat r = rotation * glm::inverse(_headRotation); + glm::quat r = glm::normalize(rotation * glm::inverse(_headRotation)); float theta = 2 * acos(r.w); glm::vec3 angularVelocity; if (theta > EPSILON) { From 7319c7b767c01f735eee919c1ef9b769618f4d8b Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 13 May 2015 11:35:04 -0700 Subject: [PATCH 02/23] Fix face-tracked head rotation for Faceshift, also --- interface/src/devices/Faceshift.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/devices/Faceshift.cpp b/interface/src/devices/Faceshift.cpp index 409f359afa..b517f9d67b 100644 --- a/interface/src/devices/Faceshift.cpp +++ b/interface/src/devices/Faceshift.cpp @@ -213,7 +213,7 @@ void Faceshift::receive(const QByteArray& buffer) { glm::quat newRotation = glm::quat(data.m_headRotation.w, -data.m_headRotation.x, data.m_headRotation.y, -data.m_headRotation.z); // Compute angular velocity of the head - glm::quat r = newRotation * glm::inverse(_headRotation); + glm::quat r = glm::normalize(newRotation * glm::inverse(_headRotation)); float theta = 2 * acos(r.w); if (theta > EPSILON) { float rMag = glm::length(glm::vec3(r.x, r.y, r.z)); From 6797174b97ffd3e0cb81ca8d06228b874985da9c Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Thu, 14 May 2015 19:15:47 -0700 Subject: [PATCH 03/23] Fix picking in the HMD --- interface/src/Application.cpp | 25 +++++++-------- interface/src/ui/ApplicationOverlay.cpp | 42 ++++++++++++++++++------- interface/src/ui/ApplicationOverlay.h | 2 +- 3 files changed, 42 insertions(+), 27 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 20c93a7ae5..6665e71642 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3077,13 +3077,10 @@ PickRay Application::computePickRay(float x, float y) const { y /= size.y; PickRay result; if (isHMDMode()) { - ApplicationOverlay::computeHmdPickRay(glm::vec2(x, y), result.origin, result.direction); + getApplicationOverlay().computeHmdPickRay(glm::vec2(x, y), result.origin, result.direction); } else { - if (activeRenderingThread) { - getDisplayViewFrustum()->computePickRay(x, y, result.origin, result.direction); - } else { - getViewFrustum()->computePickRay(x, y, result.origin, result.direction); - } + auto frustum = activeRenderingThread ? getDisplayViewFrustum() : getViewFrustum(); + frustum->computePickRay(x, y, result.origin, result.direction); } return result; } @@ -3111,8 +3108,8 @@ QImage Application::renderAvatarBillboard() { ViewFrustum* Application::getViewFrustum() { #ifdef DEBUG if (QThread::currentThread() == activeRenderingThread) { - // FIXME, should this be an assert? - qWarning() << "Calling Application::getViewFrustum() from the active rendering thread, did you mean Application::getDisplayViewFrustum()?"; + // FIXME, figure out a better way to do this + //qWarning() << "Calling Application::getViewFrustum() from the active rendering thread, did you mean Application::getDisplayViewFrustum()?"; } #endif return &_viewFrustum; @@ -3121,8 +3118,8 @@ ViewFrustum* Application::getViewFrustum() { const ViewFrustum* Application::getViewFrustum() const { #ifdef DEBUG if (QThread::currentThread() == activeRenderingThread) { - // FIXME, should this be an assert? - qWarning() << "Calling Application::getViewFrustum() from the active rendering thread, did you mean Application::getDisplayViewFrustum()?"; + // FIXME, figure out a better way to do this + //qWarning() << "Calling Application::getViewFrustum() from the active rendering thread, did you mean Application::getDisplayViewFrustum()?"; } #endif return &_viewFrustum; @@ -3131,8 +3128,8 @@ const ViewFrustum* Application::getViewFrustum() const { ViewFrustum* Application::getDisplayViewFrustum() { #ifdef DEBUG if (QThread::currentThread() != activeRenderingThread) { - // FIXME, should this be an assert? - qWarning() << "Calling Application::getDisplayViewFrustum() from outside the active rendering thread or outside rendering, did you mean Application::getViewFrustum()?"; + // FIXME, figure out a better way to do this + // qWarning() << "Calling Application::getDisplayViewFrustum() from outside the active rendering thread or outside rendering, did you mean Application::getViewFrustum()?"; } #endif return &_displayViewFrustum; @@ -3141,8 +3138,8 @@ ViewFrustum* Application::getDisplayViewFrustum() { const ViewFrustum* Application::getDisplayViewFrustum() const { #ifdef DEBUG if (QThread::currentThread() != activeRenderingThread) { - // FIXME, should this be an assert? - qWarning() << "Calling Application::getDisplayViewFrustum() from outside the active rendering thread or outside rendering, did you mean Application::getViewFrustum()?"; + // FIXME, figure out a better way to do this + // qWarning() << "Calling Application::getDisplayViewFrustum() from outside the active rendering thread or outside rendering, did you mean Application::getViewFrustum()?"; } #endif return &_displayViewFrustum; diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index b65e75923e..e3f9216c13 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -301,9 +301,14 @@ void ApplicationOverlay::displayOverlayTextureHmd(Camera& whichCamera) { //Update and draw the magnifiers MyAvatar* myAvatar = DependencyManager::get()->getMyAvatar(); const glm::quat& orientation = myAvatar->getOrientation(); - const glm::vec3& position = myAvatar->getDefaultEyePosition(); + // Always display the HMD overlay relative to the camera position but + // remove the HMD pose offset. This results in an overlay that sticks with you + // even in third person mode, but isn't drawn at a fixed distance. + glm::vec3 position = whichCamera.getPosition(); + position -= qApp->getCamera()->getHmdPosition(); const float scale = myAvatar->getScale() * _oculusUIRadius; +// glm::vec3 eyeOffset = setEyeOffsetPosition; glMatrixMode(GL_MODELVIEW); glPushMatrix(); { glTranslatef(position.x, position.y, position.z); @@ -453,19 +458,32 @@ void ApplicationOverlay::displayOverlayTextureStereo(Camera& whichCamera, float glEnable(GL_LIGHTING); } -void ApplicationOverlay::computeHmdPickRay(glm::vec2 cursorPos, glm::vec3& origin, glm::vec3& direction) { - const MyAvatar* myAvatar = DependencyManager::get()->getMyAvatar(); - cursorPos = 0.5f - cursorPos; - cursorPos *= MOUSE_RANGE; - const glm::quat orientation(glm::vec3(cursorPos, 0.0f)); - const glm::vec3 localDirection = orientation * IDENTITY_FRONT; +void ApplicationOverlay::computeHmdPickRay(glm::vec2 cursorPos, glm::vec3& origin, glm::vec3& direction) const { + cursorPos *= qApp->getCanvasSize(); + const glm::vec2 projection = screenToSpherical(cursorPos); + // The overlay space orientation of the mouse coordinates + const glm::quat orientation(glm::vec3(-projection.y, projection.x, 0.0f)); + // FIXME We now have the direction of the ray FROM THE DEFAULT HEAD POSE. + // Now we need to account for the actual camera position relative to the overlay + glm::vec3 overlaySpaceDirection = glm::normalize(orientation * IDENTITY_FRONT); - // Get cursor position - const glm::vec3 cursorDir = myAvatar->getDefaultEyePosition() + myAvatar->getOrientation() * localDirection; - // Ray start where the eye position is and stop where the cursor is - origin = myAvatar->getEyePosition(); - direction = cursorDir - origin; + const glm::vec3& hmdPosition = qApp->getCamera()->getHmdPosition(); + const glm::quat& hmdOrientation = qApp->getCamera()->getHmdRotation(); + + // We need the RAW camera orientation and position, because this is what the overlay is + // rendered relative to + const glm::vec3 overlayPosition = qApp->getCamera()->getPosition() - hmdPosition; + const glm::quat overlayOrientation = qApp->getCamera()->getRotation() * glm::inverse(hmdOrientation); + + // Intersection UI overlay space + glm::vec3 worldSpaceDirection = overlayOrientation * overlaySpaceDirection; + glm::vec3 intersectionWithUi = glm::normalize(worldSpaceDirection) * _oculusUIRadius; + intersectionWithUi += overlayPosition; + + // Intersection in world space + origin = overlayPosition + hmdPosition; + direction = glm::normalize(intersectionWithUi - origin); } //Caculate the click location using one of the sixense controllers. Scale is not applied diff --git a/interface/src/ui/ApplicationOverlay.h b/interface/src/ui/ApplicationOverlay.h index 62bbfa2747..34beb98682 100644 --- a/interface/src/ui/ApplicationOverlay.h +++ b/interface/src/ui/ApplicationOverlay.h @@ -58,12 +58,12 @@ public: glm::vec2 overlayToSpherical(const glm::vec2 & overlayPos) const; glm::vec2 screenToOverlay(const glm::vec2 & screenPos) const; glm::vec2 overlayToScreen(const glm::vec2 & overlayPos) const; + void computeHmdPickRay(glm::vec2 cursorPos, glm::vec3& origin, glm::vec3& direction) const; 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); - static void computeHmdPickRay(glm::vec2 cursorPos, glm::vec3& origin, glm::vec3& direction); private: // Interleaved vertex data From e0ae8597bcf5ed2ba01c8fde0e49434e6bf9d584 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 15 May 2015 15:45:31 +0200 Subject: [PATCH 04/23] Factor zone code in Model::render --- .../src/EntityTreeRenderer.cpp | 161 +++++++++--------- .../src/EntityTreeRenderer.h | 1 + 2 files changed, 83 insertions(+), 79 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 49187c3b2f..98e9a725b5 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -392,6 +392,87 @@ void EntityTreeRenderer::leaveAllEntities() { _lastAvatarPosition = _viewState->getAvatarPosition() + glm::vec3((float)TREE_SCALE); } } + +void EntityTreeRenderer::applyZonePropertiesToScene(const ZoneEntityItem* zone) { + QSharedPointer scene = DependencyManager::get(); + if (zone) { + if (!_hasPreviousZone) { + _previousKeyLightColor = scene->getKeyLightColor(); + _previousKeyLightIntensity = scene->getKeyLightIntensity(); + _previousKeyLightAmbientIntensity = scene->getKeyLightAmbientIntensity(); + _previousKeyLightDirection = scene->getKeyLightDirection(); + _previousStageSunModelEnabled = scene->isStageSunModelEnabled(); + _previousStageLongitude = scene->getStageLocationLongitude(); + _previousStageLatitude = scene->getStageLocationLatitude(); + _previousStageAltitude = scene->getStageLocationAltitude(); + _previousStageHour = scene->getStageDayTime(); + _previousStageDay = scene->getStageYearTime(); + _hasPreviousZone = true; + } + scene->setKeyLightColor(zone->getKeyLightColorVec3()); + scene->setKeyLightIntensity(zone->getKeyLightIntensity()); + scene->setKeyLightAmbientIntensity(zone->getKeyLightAmbientIntensity()); + scene->setKeyLightDirection(zone->getKeyLightDirection()); + scene->setStageSunModelEnable(zone->getStageProperties().getSunModelEnabled()); + scene->setStageLocation(zone->getStageProperties().getLongitude(), zone->getStageProperties().getLatitude(), + zone->getStageProperties().getAltitude()); + scene->setStageDayTime(zone->getStageProperties().calculateHour()); + scene->setStageYearTime(zone->getStageProperties().calculateDay()); + + if (zone->getBackgroundMode() == BACKGROUND_MODE_ATMOSPHERE) { + EnvironmentData data = zone->getEnvironmentData(); + glm::vec3 keyLightDirection = scene->getKeyLightDirection(); + 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 = scene->getKeyLightIntensity() * KEY_LIGHT_INTENSITY_TO_SUN_BRIGHTNESS_RATIO; + data.setSunBrightness(sunBrightness); + + _viewState->overrideEnvironmentData(data); + scene->getSkyStage()->setBackgroundMode(model::SunSkyStage::SKY_DOME); + + } else { + _viewState->endOverrideEnvironmentData(); + auto stage = scene->getSkyStage(); + if (zone->getBackgroundMode() == BACKGROUND_MODE_SKYBOX) { + stage->getSkybox()->setColor(zone->getSkyboxProperties().getColorVec3()); + if (zone->getSkyboxProperties().getURL().isEmpty()) { + stage->getSkybox()->clearCubemap(); + } else { + // Update the Texture of the Skybox with the one pointed by this zone + auto cubeMap = DependencyManager::get()->getTexture(zone->getSkyboxProperties().getURL(), CUBE_TEXTURE); + stage->getSkybox()->setCubemap(cubeMap->getGPUTexture()); + } + stage->setBackgroundMode(model::SunSkyStage::SKY_BOX); + } else { + stage->setBackgroundMode(model::SunSkyStage::SKY_DOME); // let the application atmosphere through + } + } + } else { + if (_hasPreviousZone) { + scene->setKeyLightColor(_previousKeyLightColor); + scene->setKeyLightIntensity(_previousKeyLightIntensity); + scene->setKeyLightAmbientIntensity(_previousKeyLightAmbientIntensity); + scene->setKeyLightDirection(_previousKeyLightDirection); + scene->setStageSunModelEnable(_previousStageSunModelEnabled); + scene->setStageLocation(_previousStageLongitude, _previousStageLatitude, + _previousStageAltitude); + scene->setStageDayTime(_previousStageHour); + scene->setStageYearTime(_previousStageDay); + _hasPreviousZone = false; + } + _viewState->endOverrideEnvironmentData(); + scene->getSkyStage()->setBackgroundMode(model::SunSkyStage::SKY_DOME); // let the application atmosphere through + } +} + void EntityTreeRenderer::render(RenderArgs::RenderMode renderMode, RenderArgs::RenderSide renderSide, RenderArgs::DebugFlags renderDebugFlags) { @@ -411,85 +492,7 @@ void EntityTreeRenderer::render(RenderArgs::RenderMode renderMode, _bestZoneVolume = std::numeric_limits::max(); _tree->recurseTreeWithOperation(renderOperation, &args); - QSharedPointer scene = DependencyManager::get(); - - if (_bestZone) { - if (!_hasPreviousZone) { - _previousKeyLightColor = scene->getKeyLightColor(); - _previousKeyLightIntensity = scene->getKeyLightIntensity(); - _previousKeyLightAmbientIntensity = scene->getKeyLightAmbientIntensity(); - _previousKeyLightDirection = scene->getKeyLightDirection(); - _previousStageSunModelEnabled = scene->isStageSunModelEnabled(); - _previousStageLongitude = scene->getStageLocationLongitude(); - _previousStageLatitude = scene->getStageLocationLatitude(); - _previousStageAltitude = scene->getStageLocationAltitude(); - _previousStageHour = scene->getStageDayTime(); - _previousStageDay = scene->getStageYearTime(); - _hasPreviousZone = true; - } - scene->setKeyLightColor(_bestZone->getKeyLightColorVec3()); - scene->setKeyLightIntensity(_bestZone->getKeyLightIntensity()); - scene->setKeyLightAmbientIntensity(_bestZone->getKeyLightAmbientIntensity()); - scene->setKeyLightDirection(_bestZone->getKeyLightDirection()); - scene->setStageSunModelEnable(_bestZone->getStageProperties().getSunModelEnabled()); - scene->setStageLocation(_bestZone->getStageProperties().getLongitude(), _bestZone->getStageProperties().getLatitude(), - _bestZone->getStageProperties().getAltitude()); - scene->setStageDayTime(_bestZone->getStageProperties().calculateHour()); - scene->setStageYearTime(_bestZone->getStageProperties().calculateDay()); - - if (_bestZone->getBackgroundMode() == BACKGROUND_MODE_ATMOSPHERE) { - EnvironmentData data = _bestZone->getEnvironmentData(); - glm::vec3 keyLightDirection = scene->getKeyLightDirection(); - 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 = scene->getKeyLightIntensity() * KEY_LIGHT_INTENSITY_TO_SUN_BRIGHTNESS_RATIO; - data.setSunBrightness(sunBrightness); - - _viewState->overrideEnvironmentData(data); - scene->getSkyStage()->setBackgroundMode(model::SunSkyStage::SKY_DOME); - - } else { - _viewState->endOverrideEnvironmentData(); - auto stage = scene->getSkyStage(); - if (_bestZone->getBackgroundMode() == BACKGROUND_MODE_SKYBOX) { - stage->getSkybox()->setColor(_bestZone->getSkyboxProperties().getColorVec3()); - if (_bestZone->getSkyboxProperties().getURL().isEmpty()) { - stage->getSkybox()->clearCubemap(); - } else { - // Update the Texture of the Skybox with the one pointed by this zone - auto cubeMap = DependencyManager::get()->getTexture(_bestZone->getSkyboxProperties().getURL(), CUBE_TEXTURE); - stage->getSkybox()->setCubemap(cubeMap->getGPUTexture()); - } - stage->setBackgroundMode(model::SunSkyStage::SKY_BOX); - } else { - stage->setBackgroundMode(model::SunSkyStage::SKY_DOME); // let the application atmosphere through - } - } - - } else { - if (_hasPreviousZone) { - scene->setKeyLightColor(_previousKeyLightColor); - scene->setKeyLightIntensity(_previousKeyLightIntensity); - scene->setKeyLightAmbientIntensity(_previousKeyLightAmbientIntensity); - scene->setKeyLightDirection(_previousKeyLightDirection); - scene->setStageSunModelEnable(_previousStageSunModelEnabled); - scene->setStageLocation(_previousStageLongitude, _previousStageLatitude, - _previousStageAltitude); - scene->setStageDayTime(_previousStageHour); - scene->setStageYearTime(_previousStageDay); - _hasPreviousZone = false; - } - _viewState->endOverrideEnvironmentData(); - scene->getSkyStage()->setBackgroundMode(model::SunSkyStage::SKY_DOME); // let the application atmosphere through - } + applyZonePropertiesToScene(_bestZone); // we must call endScene while we still have the tree locked so that no one deletes a model // on us while rendering the scene diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.h b/libraries/entities-renderer/src/EntityTreeRenderer.h index 9768d4a20a..da50fa7af8 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.h +++ b/libraries/entities-renderer/src/EntityTreeRenderer.h @@ -125,6 +125,7 @@ protected: virtual Octree* createTree() { return new EntityTree(true); } private: + void applyZonePropertiesToScene(const ZoneEntityItem* zone); void renderElementProxy(EntityTreeElement* entityTreeElement); void checkAndCallPreload(const EntityItemID& entityID); void checkAndCallUnload(const EntityItemID& entityID); From d3cb6a9334e7abd1de4b770c9753e6adfc208fb7 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 15 May 2015 09:40:32 -0700 Subject: [PATCH 05/23] Fix visibility of binary eyelid control menu item --- interface/src/Menu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 0d7563f27a..95877b92c4 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -393,7 +393,7 @@ Menu::Menu() { #ifdef HAVE_DDE faceTrackingMenu->addSeparator(); QAction* binaryEyelidControl = addCheckableActionToQMenuAndActionHash(faceTrackingMenu, MenuOption::BinaryEyelidControl, 0, true); - binaryEyelidControl->setVisible(false); + binaryEyelidControl->setVisible(true); // DDE face tracking is on by default QAction* useAudioForMouth = addCheckableActionToQMenuAndActionHash(faceTrackingMenu, MenuOption::UseAudioForMouth, 0, true); useAudioForMouth->setVisible(true); // DDE face tracking is on by default QAction* ddeFiltering = addCheckableActionToQMenuAndActionHash(faceTrackingMenu, MenuOption::VelocityFilter, 0, true); From bb3d1a6a58031344a1332aa84bc1736f27499d40 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 15 May 2015 13:10:16 -0700 Subject: [PATCH 06/23] rays never pick a line entity. some fixes to pointer.js --- examples/pointer.js | 35 ++++++++++++++----------- libraries/entities/src/LineEntityItem.h | 6 +++++ 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/examples/pointer.js b/examples/pointer.js index 2d7b601baa..d4348e19aa 100644 --- a/examples/pointer.js +++ b/examples/pointer.js @@ -24,23 +24,28 @@ function removeLine() { function createOrUpdateLine(event) { var pickRay = Camera.computePickRay(event.x, event.y); var intersection = Entities.findRayIntersection(pickRay, true); // accurate picking + var props = Entities.getEntityProperties(intersection.entityID); - if (lineIsRezzed) { - Entities.editEntity(lineEntityID, { - position: nearLinePoint(intersection.intersection), - dimensions: Vec3.subtract(intersection.intersection, nearLinePoint(intersection.intersection)), - lifetime: 30 // renew lifetime - }); - + if (intersection.intersects) { + var dim = Vec3.subtract(intersection.intersection, nearLinePoint(intersection.intersection)); + if (lineIsRezzed) { + Entities.editEntity(lineEntityID, { + position: nearLinePoint(intersection.intersection), + dimensions: dim, + lifetime: 60 + props.lifespan // renew lifetime + }); + } else { + lineIsRezzed = true; + lineEntityID = Entities.addEntity({ + type: "Line", + position: nearLinePoint(intersection.intersection), + dimensions: dim, + color: { red: 255, green: 255, blue: 255 }, + lifetime: 60 // if someone crashes while pointing, don't leave the line there forever. + }); + } } else { - lineIsRezzed = true; - lineEntityID = Entities.addEntity({ - type: "Line", - position: nearLinePoint(intersection.intersection), - dimensions: Vec3.subtract(intersection.intersection, nearLinePoint(intersection.intersection)), - color: { red: 255, green: 255, blue: 255 }, - lifetime: 30 // if someone crashes while pointing, don't leave the line there forever. - }); + removeLine(); } } diff --git a/libraries/entities/src/LineEntityItem.h b/libraries/entities/src/LineEntityItem.h index a834fee816..a8bc867bdd 100644 --- a/libraries/entities/src/LineEntityItem.h +++ b/libraries/entities/src/LineEntityItem.h @@ -53,6 +53,12 @@ class LineEntityItem : public EntityItem { virtual ShapeType getShapeType() const { return SHAPE_TYPE_LINE; } + // never have a ray intersection pick a LineEntityItem. + virtual bool supportsDetailedRayIntersection() const { return true; } + virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, + bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face, + void** intersectedObject, bool precisionPicking) const { return false; } + virtual void debugDump() const; protected: From cb0112e14e6edad17133d407dd8f60a06c028e35 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 15 May 2015 13:21:58 -0700 Subject: [PATCH 07/23] remove line pointers from grab and hockey grab --- examples/example/games/grabHockey.js | 19 ++----------------- examples/grab.js | 16 ---------------- 2 files changed, 2 insertions(+), 33 deletions(-) diff --git a/examples/example/games/grabHockey.js b/examples/example/games/grabHockey.js index 31597ba32d..5e101e1d48 100644 --- a/examples/example/games/grabHockey.js +++ b/examples/example/games/grabHockey.js @@ -13,7 +13,6 @@ var isGrabbing = false; var grabbedEntity = null; -var lineEntityID = null; var prevMouse = {}; var deltaMouse = { z: 0 @@ -39,9 +38,9 @@ var angularVelocity = { var grabSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/eric/sounds/CloseClamp.wav"); var releaseSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/eric/sounds/ReleaseClamp.wav"); -var VOLUME = 0.10; +var VOLUME = 0.0; -var DROP_DISTANCE = 5.0; +var DROP_DISTANCE = 0.10; var DROP_COLOR = { red: 200, green: 200, @@ -92,14 +91,6 @@ function mousePressEvent(event) { gravity: {x: 0, y: 0, z: 0} }); - lineEntityID = Entities.addEntity({ - type: "Line", - position: nearLinePoint(targetPosition), - dimensions: Vec3.subtract(targetPosition, nearLinePoint(targetPosition)), - color: { red: 255, green: 255, blue: 255 }, - lifetime: 300 // if someone crashes while moving something, don't leave the line there forever. - }); - Audio.playSound(grabSound, { position: props.position, volume: VOLUME @@ -145,8 +136,6 @@ function mouseReleaseEvent() { }); targetPosition = null; - Entities.deleteEntity(lineEntityID); - Audio.playSound(releaseSound, { position: entityProps.position, volume: VOLUME @@ -193,10 +182,6 @@ function mouseMoveEvent(event) { angularVelocity = Vec3.multiply((theta / dT), axisAngle); } - Entities.editEntity(lineEntityID, { - position: nearLinePoint(targetPosition), - dimensions: Vec3.subtract(targetPosition, nearLinePoint(targetPosition)) - }); } prevMouse.x = event.x; prevMouse.y = event.y; diff --git a/examples/grab.js b/examples/grab.js index 019ec2320f..f1e1b6571c 100644 --- a/examples/grab.js +++ b/examples/grab.js @@ -13,7 +13,6 @@ var isGrabbing = false; var grabbedEntity = null; -var lineEntityID = null; var prevMouse = {}; var deltaMouse = { z: 0 @@ -91,14 +90,6 @@ function mousePressEvent(event) { gravity: {x: 0, y: 0, z: 0} }); - lineEntityID = Entities.addEntity({ - type: "Line", - position: nearLinePoint(targetPosition), - dimensions: Vec3.subtract(targetPosition, nearLinePoint(targetPosition)), - color: { red: 255, green: 255, blue: 255 }, - lifetime: 300 // if someone crashes while moving something, don't leave the line there forever. - }); - Audio.playSound(grabSound, { position: props.position, volume: 0.4 @@ -144,8 +135,6 @@ function mouseReleaseEvent() { }); targetPosition = null; - Entities.deleteEntity(lineEntityID); - Audio.playSound(grabSound, { position: entityProps.position, volume: 0.25 @@ -191,11 +180,6 @@ function mouseMoveEvent(event) { axisAngle = Quat.axis(dQ); angularVelocity = Vec3.multiply((theta / dT), axisAngle); } - - Entities.editEntity(lineEntityID, { - position: nearLinePoint(targetPosition), - dimensions: Vec3.subtract(targetPosition, nearLinePoint(targetPosition)) - }); } prevMouse.x = event.x; prevMouse.y = event.y; From f535bd2a76cb4ce55fa2288722fb6ab4f8392032 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 15 May 2015 13:54:24 -0700 Subject: [PATCH 08/23] more fixes to pointer.js --- examples/pointer.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/examples/pointer.js b/examples/pointer.js index d4348e19aa..c41bf277dd 100644 --- a/examples/pointer.js +++ b/examples/pointer.js @@ -17,6 +17,7 @@ function removeLine() { Entities.deleteEntity(lineEntityID); lineEntityID = null; lineIsRezzed = false; + Controller.mouseMoveEvent.disconnect(mouseMoveEvent); } } @@ -43,6 +44,7 @@ function createOrUpdateLine(event) { color: { red: 255, green: 255, blue: 255 }, lifetime: 60 // if someone crashes while pointing, don't leave the line there forever. }); + Controller.mouseMoveEvent.connect(mouseMoveEvent); } } else { removeLine(); @@ -58,9 +60,6 @@ function mousePressEvent(event) { return; } createOrUpdateLine(event); - if (lineIsRezzed) { - Controller.mouseMoveEvent.connect(mouseMoveEvent); - } } @@ -70,9 +69,6 @@ function mouseMoveEvent(event) { function mouseReleaseEvent() { - if (lineIsRezzed) { - Controller.mouseMoveEvent.disconnect(mouseMoveEvent); - } removeLine(); } From 9c6be26290a71cf6a2a7e89baad75ea220c045cf Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Fri, 15 May 2015 13:55:48 -0700 Subject: [PATCH 09/23] changed dice to use collisionSoundURL prop --- examples/dice.js | 180 +++++++++++++++++++++++++---------------------- 1 file changed, 94 insertions(+), 86 deletions(-) diff --git a/examples/dice.js b/examples/dice.js index f313e606b8..515019e740 100644 --- a/examples/dice.js +++ b/examples/dice.js @@ -12,17 +12,17 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -var isDice = false; -var NUMBER_OF_DICE = 4; -var LIFETIME = 10000; // Dice will live for about 3 hours +var isDice = false; +var NUMBER_OF_DICE = 4; +var LIFETIME = 10000; // Dice will live for about 3 hours var dice = []; var DIE_SIZE = 0.20; -var madeSound = true; // Set false at start of throw to look for collision +var madeSound = true; // Set false at start of throw to look for collision HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/"; +SoundCache.getSound("http://s3.amazonaws.com/hifi-public/sounds/dice/diceCollide.wav"); -var rollSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/dice/diceRoll.wav"); var INSUFFICIENT_PERMISSIONS_ERROR_MSG = "You do not have the necessary permissions to create new objects." @@ -32,34 +32,46 @@ var BUTTON_SIZE = 32; var PADDING = 3; var offButton = Overlays.addOverlay("image", { - x: screenSize.x / 2 - BUTTON_SIZE * 2 + PADDING, - y: screenSize.y- (BUTTON_SIZE + PADDING), - width: BUTTON_SIZE, - height: BUTTON_SIZE, - imageURL: HIFI_PUBLIC_BUCKET + "images/close.png", - color: { red: 255, green: 255, blue: 255}, - alpha: 1 - }); + x: screenSize.x / 2 - BUTTON_SIZE * 2 + PADDING, + y: screenSize.y - (BUTTON_SIZE + PADDING), + width: BUTTON_SIZE, + height: BUTTON_SIZE, + imageURL: HIFI_PUBLIC_BUCKET + "images/close.png", + color: { + red: 255, + green: 255, + blue: 255 + }, + alpha: 1 +}); var deleteButton = Overlays.addOverlay("image", { - x: screenSize.x / 2 - BUTTON_SIZE, - y: screenSize.y- (BUTTON_SIZE + PADDING), - width: BUTTON_SIZE, - height: BUTTON_SIZE, - imageURL: HIFI_PUBLIC_BUCKET + "images/delete.png", - color: { red: 255, green: 255, blue: 255}, - alpha: 1 - }); + x: screenSize.x / 2 - BUTTON_SIZE, + y: screenSize.y - (BUTTON_SIZE + PADDING), + width: BUTTON_SIZE, + height: BUTTON_SIZE, + imageURL: HIFI_PUBLIC_BUCKET + "images/delete.png", + color: { + red: 255, + green: 255, + blue: 255 + }, + alpha: 1 +}); var diceButton = Overlays.addOverlay("image", { - x: screenSize.x / 2 + PADDING, - y: screenSize.y - (BUTTON_SIZE + PADDING), - width: BUTTON_SIZE, - height: BUTTON_SIZE, - imageURL: HIFI_PUBLIC_BUCKET + "images/die.png", - color: { red: 255, green: 255, blue: 255}, - alpha: 1 - }); + x: screenSize.x / 2 + PADDING, + y: screenSize.y - (BUTTON_SIZE + PADDING), + width: BUTTON_SIZE, + height: BUTTON_SIZE, + imageURL: HIFI_PUBLIC_BUCKET + "images/die.png", + color: { + red: 255, + green: 255, + blue: 255 + }, + alpha: 1 +}); var GRAVITY = -3.5; @@ -68,74 +80,70 @@ var MAX_ANGULAR_SPEED = Math.PI; function shootDice(position, velocity) { - if (!Entities.canRez()) { - Window.alert(INSUFFICIENT_PERMISSIONS_ERROR_MSG); - } else { - for (var i = 0; i < NUMBER_OF_DICE; i++) { - dice.push(Entities.addEntity( - { type: "Model", - modelURL: HIFI_PUBLIC_BUCKET + "models/props/Dice/goldDie.fbx", - position: position, - velocity: velocity, - rotation: Quat.fromPitchYawRollDegrees(Math.random() * 360, Math.random() * 360, Math.random() * 360), - angularVelocity: { x: Math.random() * MAX_ANGULAR_SPEED, - y: Math.random() * MAX_ANGULAR_SPEED, - z: Math.random() * MAX_ANGULAR_SPEED }, - lifetime: LIFETIME, - gravity: { x: 0, y: GRAVITY, z: 0 }, - shapeType: "box", - collisionsWillMove: true - })); - position = Vec3.sum(position, Vec3.multiply(DIE_SIZE, Vec3.normalize(Quat.getRight(Camera.getOrientation())))); - } + if (!Entities.canRez()) { + Window.alert(INSUFFICIENT_PERMISSIONS_ERROR_MSG); + } else { + for (var i = 0; i < NUMBER_OF_DICE; i++) { + dice.push(Entities.addEntity( + { + type: "Model", + modelURL: HIFI_PUBLIC_BUCKET + "models/props/Dice/goldDie.fbx", + position: position, + velocity: velocity, + rotation: Quat.fromPitchYawRollDegrees(Math.random() * 360, Math.random() * 360, Math.random() * 360), + angularVelocity: { + x: Math.random() * MAX_ANGULAR_SPEED, + y: Math.random() * MAX_ANGULAR_SPEED, + z: Math.random() * MAX_ANGULAR_SPEED + }, + gravity: { + x: 0, + y: GRAVITY, + z: 0 + }, + lifetime: LIFETIME, + shapeType: "box", + collisionsWillMove: true, + collisionSoundURL: "http://s3.amazonaws.com/hifi-public/sounds/dice/diceCollide.wav" + })); + position = Vec3.sum(position, Vec3.multiply(DIE_SIZE, Vec3.normalize(Quat.getRight(Camera.getOrientation())))); } + } } function deleteDice() { - while(dice.length > 0) { - Entities.deleteEntity(dice.pop()); - } + while (dice.length > 0) { + Entities.deleteEntity(dice.pop()); + } } -function entityCollisionWithEntity(entity1, entity2, collision) { - if (!madeSound) { - // Is it one of our dice? - for (var i = 0; i < dice.length; i++) { - if (!dice[i].isKnownID) { - dice[i] = Entities.identifyEntity(dice[i]); - } - if ((entity1.id == dice[i].id) || (entity2.id == dice[i].id)) { - madeSound = true; - Audio.playSound(rollSound, { position: collision.contactPoint, localOnly: true }); - } - } - - } -} + function mousePressEvent(event) { - var clickedText = false; - var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y}); - if (clickedOverlay == offButton) { - deleteDice(); - Script.stop(); - } else if (clickedOverlay == deleteButton) { - deleteDice(); - } else if (clickedOverlay == diceButton) { - var HOW_HARD = 2.0; - var position = Vec3.sum(Camera.getPosition(), Quat.getFront(Camera.getOrientation())); - var velocity = Vec3.multiply(HOW_HARD, Quat.getFront(Camera.getOrientation())); - shootDice(position, velocity); - madeSound = false; - } + var clickedText = false; + var clickedOverlay = Overlays.getOverlayAtPoint({ + x: event.x, + y: event.y + }); + if (clickedOverlay == offButton) { + deleteDice(); + Script.stop(); + } else if (clickedOverlay == deleteButton) { + deleteDice(); + } else if (clickedOverlay == diceButton) { + var HOW_HARD = 2.0; + var position = Vec3.sum(Camera.getPosition(), Quat.getFront(Camera.getOrientation())); + var velocity = Vec3.multiply(HOW_HARD, Quat.getFront(Camera.getOrientation())); + shootDice(position, velocity); + madeSound = false; + } } function scriptEnding() { - Overlays.deleteOverlay(offButton); - Overlays.deleteOverlay(diceButton); - Overlays.deleteOverlay(deleteButton); + Overlays.deleteOverlay(offButton); + Overlays.deleteOverlay(diceButton); + Overlays.deleteOverlay(deleteButton); } -Entities.entityCollisionWithEntity.connect(entityCollisionWithEntity); Controller.mousePressEvent.connect(mousePressEvent); -Script.scriptEnding.connect(scriptEnding); +Script.scriptEnding.connect(scriptEnding); \ No newline at end of file From aeb5cead65f19d38b73e456f905821281f5cb146 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 15 May 2015 14:02:25 -0700 Subject: [PATCH 10/23] more fixes to pointer.js --- examples/pointer.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/examples/pointer.js b/examples/pointer.js index c41bf277dd..ef35e13f7b 100644 --- a/examples/pointer.js +++ b/examples/pointer.js @@ -17,7 +17,6 @@ function removeLine() { Entities.deleteEntity(lineEntityID); lineEntityID = null; lineIsRezzed = false; - Controller.mouseMoveEvent.disconnect(mouseMoveEvent); } } @@ -44,7 +43,6 @@ function createOrUpdateLine(event) { color: { red: 255, green: 255, blue: 255 }, lifetime: 60 // if someone crashes while pointing, don't leave the line there forever. }); - Controller.mouseMoveEvent.connect(mouseMoveEvent); } } else { removeLine(); @@ -56,9 +54,7 @@ function mousePressEvent(event) { if (!event.isLeftButton) { return; } - if (lineIsRezzed) { - return; - } + Controller.mouseMoveEvent.connect(mouseMoveEvent); createOrUpdateLine(event); } @@ -69,6 +65,7 @@ function mouseMoveEvent(event) { function mouseReleaseEvent() { + Controller.mouseMoveEvent.disconnect(mouseMoveEvent); removeLine(); } From 0d3add85968ec0ee90512ce28bfa32253723df53 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 15 May 2015 14:16:06 -0700 Subject: [PATCH 11/23] left mouse button only --- examples/pointer.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/pointer.js b/examples/pointer.js index ef35e13f7b..6c26a28ed8 100644 --- a/examples/pointer.js +++ b/examples/pointer.js @@ -64,7 +64,10 @@ function mouseMoveEvent(event) { } -function mouseReleaseEvent() { +function mouseReleaseEvent(event) { + if (!event.isLeftButton) { + return; + } Controller.mouseMoveEvent.disconnect(mouseMoveEvent); removeLine(); } From 60bd345e577ec94035fb744974462e84066f58d8 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 15 May 2015 14:20:29 -0700 Subject: [PATCH 12/23] shorter timeout --- examples/pointer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/pointer.js b/examples/pointer.js index 6c26a28ed8..dfb79569f7 100644 --- a/examples/pointer.js +++ b/examples/pointer.js @@ -32,7 +32,7 @@ function createOrUpdateLine(event) { Entities.editEntity(lineEntityID, { position: nearLinePoint(intersection.intersection), dimensions: dim, - lifetime: 60 + props.lifespan // renew lifetime + lifetime: 15 + props.lifespan // renew lifetime }); } else { lineIsRezzed = true; @@ -41,7 +41,7 @@ function createOrUpdateLine(event) { position: nearLinePoint(intersection.intersection), dimensions: dim, color: { red: 255, green: 255, blue: 255 }, - lifetime: 60 // if someone crashes while pointing, don't leave the line there forever. + lifetime: 15 // if someone crashes while pointing, don't leave the line there forever. }); } } else { From 5abd4bb08edeea92e719a4f7fa728d4e13687cd8 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 15 May 2015 14:37:42 -0700 Subject: [PATCH 13/23] Update GeometryCache to accept gpu::Batch --- .../src/DeferredLightingEffect.cpp | 33 +++- .../render-utils/src/DeferredLightingEffect.h | 6 + libraries/render-utils/src/GeometryCache.cpp | 143 +++++++++++------- libraries/render-utils/src/GeometryCache.h | 44 +++++- 4 files changed, 170 insertions(+), 56 deletions(-) diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 972858be07..fa9f1aaa21 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -106,24 +106,48 @@ void DeferredLightingEffect::releaseSimpleProgram() { } void DeferredLightingEffect::renderSolidSphere(float radius, int slices, int stacks, const glm::vec4& color) { + gpu::Batch batch; + renderSolidSphere(batch, radius, slices, stacks, color); + gpu::GLBackend::renderBatch(batch); +} + +void DeferredLightingEffect::renderSolidSphere(gpu::Batch& batch, float radius, int slices, int stacks, const glm::vec4& color) { bindSimpleProgram(); DependencyManager::get()->renderSphere(radius, slices, stacks, color); releaseSimpleProgram(); } void DeferredLightingEffect::renderWireSphere(float radius, int slices, int stacks, const glm::vec4& color) { + gpu::Batch batch; + renderWireSphere(batch, radius, slices, stacks, color); + gpu::GLBackend::renderBatch(batch); +} + +void DeferredLightingEffect::renderWireSphere(gpu::Batch& batch, float radius, int slices, int stacks, const glm::vec4& color) { bindSimpleProgram(); - DependencyManager::get()->renderSphere(radius, slices, stacks, color, false); + DependencyManager::get()->renderSphere(batch, radius, slices, stacks, color, false); releaseSimpleProgram(); } void DeferredLightingEffect::renderSolidCube(float size, const glm::vec4& color) { + gpu::Batch batch; + renderSolidCube(batch, size, color); + gpu::GLBackend::renderBatch(batch); +} + +void DeferredLightingEffect::renderSolidCube(gpu::Batch& batch, float size, const glm::vec4& color) { bindSimpleProgram(); DependencyManager::get()->renderSolidCube(size, color); releaseSimpleProgram(); } void DeferredLightingEffect::renderWireCube(float size, const glm::vec4& color) { + gpu::Batch batch; + renderWireCube(batch, size, color); + gpu::GLBackend::renderBatch(batch); +} + +void DeferredLightingEffect::renderWireCube(gpu::Batch& batch, float size, const glm::vec4& color) { bindSimpleProgram(); DependencyManager::get()->renderWireCube(size, color); releaseSimpleProgram(); @@ -131,6 +155,13 @@ void DeferredLightingEffect::renderWireCube(float size, const glm::vec4& color) void DeferredLightingEffect::renderLine(const glm::vec3& p1, const glm::vec3& p2, const glm::vec4& color1, const glm::vec4& color2) { + gpu::Batch batch; + renderLine(batch, p1, p2, color1, color2); + gpu::GLBackend::renderBatch(batch); +} + +void DeferredLightingEffect::renderLine(gpu::Batch& batch, const glm::vec3& p1, const glm::vec3& p2, + const glm::vec4& color1, const glm::vec4& color2) { bindSimpleProgram(); DependencyManager::get()->renderLine(p1, p2, color1, color2); releaseSimpleProgram(); diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index fa37d48221..e979aeeb9c 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -44,19 +44,25 @@ public: //// Renders a solid sphere with the simple program. void renderSolidSphere(float radius, int slices, int stacks, const glm::vec4& color); + void renderSolidSphere(gpu::Batch& batch, float radius, int slices, int stacks, const glm::vec4& color); //// Renders a wireframe sphere with the simple program. void renderWireSphere(float radius, int slices, int stacks, const glm::vec4& color); + void renderWireSphere(gpu::Batch& batch, float radius, int slices, int stacks, const glm::vec4& color); //// Renders a solid cube with the simple program. void renderSolidCube(float size, const glm::vec4& color); + void renderSolidCube(gpu::Batch& batch, float size, const glm::vec4& color); //// Renders a wireframe cube with the simple program. void renderWireCube(float size, const glm::vec4& color); + void renderWireCube(gpu::Batch& batch, float size, const glm::vec4& color); //// Renders a line with the simple program. void renderLine(const glm::vec3& p1, const glm::vec3& p2, const glm::vec4& color1, const glm::vec4& color2); + void renderLine(gpu::Batch& batch, const glm::vec3& p1, const glm::vec3& p2, + const glm::vec4& color1, const glm::vec4& color2); //// Renders a solid cone with the simple program. void renderSolidCone(float base, float height, int slices, int stacks); diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 770717edbe..f66bfb91ea 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -56,6 +56,12 @@ const int NUM_BYTES_PER_VERTEX = NUM_COORDS_PER_VERTEX * sizeof(GLfloat); const int NUM_BYTES_PER_INDEX = sizeof(GLushort); void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm::vec4& color, bool solid, int id) { + gpu::Batch batch; + renderSphere(batch, radius, slices, stacks, color, solid, id); + gpu::GLBackend::renderBatch(batch); +} + +void GeometryCache::renderSphere(gpu::Batch& batch, float radius, int slices, int stacks, const glm::vec4& color, bool solid, int id) { bool registered = (id != UNKNOWN_ID); Vec2Pair radiusKey(glm::vec2(radius, slices), glm::vec2(stacks, 0)); @@ -279,8 +285,6 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm gpu::BufferView normalsView(verticesBuffer, streamFormat->getAttributes().at(gpu::Stream::NORMAL)._element); gpu::BufferView colorView(colorBuffer, streamFormat->getAttributes().at(gpu::Stream::COLOR)._element); - gpu::Batch batch; - batch.setInputFormat(streamFormat); batch.setInputBuffer(VERTICES_SLOT, verticesView); batch.setInputBuffer(NORMALS_SLOT, normalsView); @@ -293,8 +297,6 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm batch.drawIndexed(gpu::LINES, indices); } - gpu::GLBackend::renderBatch(batch); - glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); @@ -402,7 +404,14 @@ void GeometryCache::renderCone(float base, float height, int slices, int stacks) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } + void GeometryCache::renderGrid(int xDivisions, int yDivisions, const glm::vec4& color) { + gpu::Batch batch; + renderGrid(batch, xDivisions, yDivisions, color); + gpu::GLBackend::renderBatch(batch); +} + +void GeometryCache::renderGrid(gpu::Batch& batch, int xDivisions, int yDivisions, const glm::vec4& color) { IntPair key(xDivisions, yDivisions); Vec3Pair colorKey(glm::vec3(color.x, color.y, yDivisions), glm::vec3(color.z, color.y, xDivisions)); @@ -470,15 +479,11 @@ void GeometryCache::renderGrid(int xDivisions, int yDivisions, const glm::vec4& gpu::BufferView verticesView(verticesBuffer, 0, verticesBuffer->getSize(), streamFormat->getAttributes().at(gpu::Stream::POSITION)._element); gpu::BufferView colorView(colorBuffer, streamFormat->getAttributes().at(gpu::Stream::COLOR)._element); - gpu::Batch batch; - batch.setInputFormat(streamFormat); batch.setInputBuffer(VERTICES_SLOT, verticesView); batch.setInputBuffer(COLOR_SLOT, colorView); batch.draw(gpu::LINES, vertices, 0); - gpu::GLBackend::renderBatch(batch); - glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); @@ -486,9 +491,15 @@ void GeometryCache::renderGrid(int xDivisions, int yDivisions, const glm::vec4& } +void GeometryCache::renderGrid(int x, int y, int width, int height, int rows, int cols, const glm::vec4& color, int id) { + gpu::Batch batch; + renderGrid(x, y, width, height, rows, cols, color, id); + gpu::GLBackend::renderBatch(batch); +} + // TODO: properly handle the x,y,w,h changing for an ID // TODO: why do we seem to create extra BatchItemDetails when we resize the window?? what's that?? -void GeometryCache::renderGrid(int x, int y, int width, int height, int rows, int cols, const glm::vec4& color, int id) { +void GeometryCache::renderGrid(gpu::Batch& batch, int x, int y, int width, int height, int rows, int cols, const glm::vec4& color, int id) { #ifdef WANT_DEBUG qCDebug(renderutils) << "GeometryCache::renderGrid(x["<getSize(), streamFormat->getAttributes().at(gpu::Stream::POSITION)._element); gpu::BufferView colorView(colorBuffer, streamFormat->getAttributes().at(gpu::Stream::COLOR)._element); - - gpu::Batch batch; batch.setInputFormat(streamFormat); batch.setInputBuffer(VERTICES_SLOT, verticesView); batch.setInputBuffer(COLOR_SLOT, colorView); batch.draw(gpu::LINES, vertices, 0); - gpu::GLBackend::renderBatch(batch); - glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); @@ -810,6 +817,12 @@ void GeometryCache::renderVertices(gpu::Primitive primitiveType, int id) { } void GeometryCache::renderSolidCube(float size, const glm::vec4& color) { + gpu::Batch batch; + renderSolidCube(batch, size, color); + gpu::GLBackend::renderBatch(batch); +} + +void GeometryCache::renderSolidCube(gpu::Batch& batch, float size, const glm::vec4& color) { Vec2Pair colorKey(glm::vec2(color.x, color.y), glm::vec2(color.z, color.y)); const int FLOATS_PER_VERTEX = 3; const int VERTICES_PER_FACE = 4; @@ -915,8 +928,6 @@ void GeometryCache::renderSolidCube(float size, const glm::vec4& color) { gpu::BufferView normalsView(verticesBuffer, NORMALS_OFFSET, verticesBuffer->getSize(), VERTEX_STRIDE, streamFormat->getAttributes().at(gpu::Stream::NORMAL)._element); gpu::BufferView colorView(colorBuffer, streamFormat->getAttributes().at(gpu::Stream::COLOR)._element); - gpu::Batch batch; - batch.setInputFormat(streamFormat); batch.setInputBuffer(VERTICES_SLOT, verticesView); batch.setInputBuffer(NORMALS_SLOT, normalsView); @@ -924,8 +935,6 @@ void GeometryCache::renderSolidCube(float size, const glm::vec4& color) { batch.setIndexBuffer(gpu::UINT8, _solidCubeIndexBuffer, 0); batch.drawIndexed(gpu::TRIANGLES, indices); - gpu::GLBackend::renderBatch(batch); - glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); @@ -934,6 +943,12 @@ void GeometryCache::renderSolidCube(float size, const glm::vec4& color) { } void GeometryCache::renderWireCube(float size, const glm::vec4& color) { + gpu::Batch batch; + renderWireCube(batch, size, color); + gpu::GLBackend::renderBatch(batch); +} + +void GeometryCache::renderWireCube(gpu::Batch& batch, float size, const glm::vec4& color) { Vec2Pair colorKey(glm::vec2(color.x, color.y),glm::vec2(color.z, color.y)); const int FLOATS_PER_VERTEX = 3; const int VERTICES_PER_EDGE = 2; @@ -1003,16 +1018,12 @@ void GeometryCache::renderWireCube(float size, const glm::vec4& color) { gpu::BufferView verticesView(verticesBuffer, streamFormat->getAttributes().at(gpu::Stream::POSITION)._element); gpu::BufferView colorView(colorBuffer, streamFormat->getAttributes().at(gpu::Stream::COLOR)._element); - gpu::Batch batch; - batch.setInputFormat(streamFormat); batch.setInputBuffer(VERTICES_SLOT, verticesView); batch.setInputBuffer(COLOR_SLOT, colorView); batch.setIndexBuffer(gpu::UINT8, _wireCubeIndexBuffer, 0); batch.drawIndexed(gpu::LINES, indices); - gpu::GLBackend::renderBatch(batch); - glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); @@ -1021,6 +1032,12 @@ void GeometryCache::renderWireCube(float size, const glm::vec4& color) { } void GeometryCache::renderBevelCornersRect(int x, int y, int width, int height, int bevelDistance, const glm::vec4& color, int id) { + gpu::Batch batch; + renderBevelCornersRect(batch, x, y, width, height, bevelDistance, color, id); + gpu::GLBackend::renderBatch(batch); +} + +void GeometryCache::renderBevelCornersRect(gpu::Batch& batch, int x, int y, int width, int height, int bevelDistance, const glm::vec4& color, int id) { bool registered = (id != UNKNOWN_ID); Vec3Pair key(glm::vec3(x, y, 0.0f), glm::vec3(width, height, bevelDistance)); BatchItemDetails& details = registered ? _registeredBevelRects[id] : _bevelRects[key]; @@ -1113,14 +1130,10 @@ void GeometryCache::renderBevelCornersRect(int x, int y, int width, int height, delete[] vertexBuffer; } - gpu::Batch batch; - batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(gpu::QUADS, 4, 0); - gpu::GLBackend::renderBatch(batch); - glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); @@ -1128,6 +1141,12 @@ void GeometryCache::renderBevelCornersRect(int x, int y, int width, int height, } void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, const glm::vec4& color, int id) { + gpu::Batch batch; + renderQuad(batch, minCorner, maxCorner, color, id); + gpu::GLBackend::renderBatch(batch); +} + +void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec2& minCorner, const glm::vec2& maxCorner, const glm::vec4& color, int id) { bool registered = (id != UNKNOWN_ID); Vec4Pair key(glm::vec4(minCorner.x, minCorner.y, maxCorner.x, maxCorner.y), color); BatchItemDetails& details = registered ? _registeredQuad2D[id] : _quad2D[key]; @@ -1193,14 +1212,10 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC details.colorBuffer->append(sizeof(colors), (gpu::Byte*) colors); } - gpu::Batch batch; - batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(gpu::QUADS, 4, 0); - gpu::GLBackend::renderBatch(batch); - glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); @@ -1210,6 +1225,14 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, const glm::vec2& texCoordMinCorner, const glm::vec2& texCoordMaxCorner, const glm::vec4& color, int id) { + gpu::Batch batch; + renderQuad(batch, minCorner, maxCorner, texCoordMinCorner, texCoordMaxCorner, color, id); + gpu::GLBackend::renderBatch(batch); +} + +void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec2& minCorner, const glm::vec2& maxCorner, + const glm::vec2& texCoordMinCorner, const glm::vec2& texCoordMaxCorner, + const glm::vec4& color, int id) { bool registered = (id != UNKNOWN_ID); Vec4PairVec4 key(Vec4Pair(glm::vec4(minCorner.x, minCorner.y, maxCorner.x, maxCorner.y), @@ -1282,8 +1305,6 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC details.colorBuffer->append(sizeof(colors), (gpu::Byte*) colors); } - gpu::Batch batch; - // glEnable(GL_TEXTURE_2D); //glBindTexture(GL_TEXTURE_2D, _currentTextureID); // this is quad specific... @@ -1291,8 +1312,6 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC batch.setInputStream(0, *details.stream); batch.draw(gpu::QUADS, 4, 0); - gpu::GLBackend::renderBatch(batch); - glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_COLOR_ARRAY); @@ -1303,6 +1322,12 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC } void GeometryCache::renderQuad(const glm::vec3& minCorner, const glm::vec3& maxCorner, const glm::vec4& color, int id) { + gpu::Batch batch; + renderQuad(batch, minCorner, maxCorner, color, id); + gpu::GLBackend::renderBatch(batch); +} + +void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec3& minCorner, const glm::vec3& maxCorner, const glm::vec4& color, int id) { bool registered = (id != UNKNOWN_ID); Vec3PairVec4 key(Vec3Pair(minCorner, maxCorner), color); BatchItemDetails& details = registered ? _registeredQuad3D[id] : _quad3D[key]; @@ -1368,14 +1393,10 @@ void GeometryCache::renderQuad(const glm::vec3& minCorner, const glm::vec3& maxC details.colorBuffer->append(sizeof(colors), (gpu::Byte*) colors); } - gpu::Batch batch; - batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(gpu::QUADS, 4, 0); - gpu::GLBackend::renderBatch(batch); - glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); @@ -1387,6 +1408,17 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomLeft, const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight, const glm::vec4& color, int id) { + gpu::Batch batch; + renderQuad(batch, topLeft, bottomLeft, bottomRight, topRight, texCoordTopLeft, texCoordBottomLeft, + texCoordBottomRight, texCoordTopRight, color, id); + gpu::GLBackend::renderBatch(batch); +} + +void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec3& topLeft, const glm::vec3& bottomLeft, + const glm::vec3& bottomRight, const glm::vec3& topRight, + const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomLeft, + const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight, + const glm::vec4& color, int id) { #ifdef WANT_DEBUG qCDebug(renderutils) << "renderQuad() vec3 + texture VBO..."; @@ -1470,8 +1502,6 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom details.colorBuffer->append(sizeof(colors), (gpu::Byte*) colors); } - gpu::Batch batch; - glEnable(GL_TEXTURE_2D); //glBindTexture(GL_TEXTURE_2D, _currentTextureID); // this is quad specific... @@ -1479,8 +1509,6 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom batch.setInputStream(0, *details.stream); batch.draw(gpu::QUADS, 4, 0); - gpu::GLBackend::renderBatch(batch); - glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_COLOR_ARRAY); @@ -1495,6 +1523,12 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom } void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& end, const glm::vec4& color, int id) { + gpu::Batch batch; + renderDashedLine(batch, start, end, color, id); + gpu::GLBackend::renderBatch(batch); +} + +void GeometryCache::renderDashedLine(gpu::Batch& batch, const glm::vec3& start, const glm::vec3& end, const glm::vec4& color, int id) { bool registered = (id != UNKNOWN_ID); Vec3PairVec2Pair key(Vec3Pair(start, end), Vec2Pair(glm::vec2(color.x, color.y), glm::vec2(color.z, color.w))); BatchItemDetails& details = registered ? _registeredDashedLines[id] : _dashedLines[key]; @@ -1594,14 +1628,10 @@ void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& en #endif } - gpu::Batch batch; - batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(gpu::LINES, details.vertices, 0); - gpu::GLBackend::renderBatch(batch); - glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); @@ -1659,6 +1689,13 @@ void GeometryCache::BatchItemDetails::clear() { void GeometryCache::renderLine(const glm::vec3& p1, const glm::vec3& p2, const glm::vec4& color1, const glm::vec4& color2, int id) { + gpu::Batch batch; + renderLine(batch, p1, p2, color1, color2, id); + gpu::GLBackend::renderBatch(batch); +} + +void GeometryCache::renderLine(gpu::Batch& batch, const glm::vec3& p1, const glm::vec3& p2, + const glm::vec4& color1, const glm::vec4& color2, int id) { bool registered = (id != UNKNOWN_ID); Vec3Pair key(p1, p2); @@ -1735,21 +1772,23 @@ void GeometryCache::renderLine(const glm::vec3& p1, const glm::vec3& p2, #endif } - gpu::Batch batch; - // this is what it takes to render a quad batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(gpu::LINES, 2, 0); - gpu::GLBackend::renderBatch(batch); - glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, 0); } -void GeometryCache::renderLine(const glm::vec2& p1, const glm::vec2& p2, +void GeometryCache::renderLine(const glm::vec2& p1, const glm::vec2& p2, const glm::vec4& color1, const glm::vec4& color2, int id) { + gpu::Batch batch; + renderLine(batch, p1, p2, color1, color2, id); + gpu::GLBackend::renderBatch(batch); +} + +void GeometryCache::renderLine(gpu::Batch& batch, const glm::vec2& p1, const glm::vec2& p2, const glm::vec4& color1, const glm::vec4& color2, int id) { bool registered = (id != UNKNOWN_ID); @@ -1827,15 +1866,11 @@ void GeometryCache::renderLine(const glm::vec2& p1, const glm::vec2& p2, #endif } - gpu::Batch batch; - // this is what it takes to render a quad batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(gpu::LINES, 2, 0); - gpu::GLBackend::renderBatch(batch); - glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, 0); diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 672e4ddb78..3dc1a7ac41 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -135,66 +135,108 @@ public: void renderCone(float base, float height, int slices, int stacks); - void renderSphere(float radius, int slices, int stacks, const glm::vec3& color, bool solid = true, int id = UNKNOWN_ID) + void renderSphere(float radius, int slices, int stacks, const glm::vec3& color, bool solid = true, int id = UNKNOWN_ID) { renderSphere(radius, slices, stacks, glm::vec4(color, 1.0f), solid, id); } + void renderSphere(gpu::Batch& batch, float radius, int slices, int stacks, const glm::vec3& color, bool solid = true, int id = UNKNOWN_ID) + { renderSphere(batch, radius, slices, stacks, glm::vec4(color, 1.0f), solid, id); } void renderSphere(float radius, int slices, int stacks, const glm::vec4& color, bool solid = true, int id = UNKNOWN_ID); + void renderSphere(gpu::Batch& batch, float radius, int slices, int stacks, const glm::vec4& color, bool solid = true, int id = UNKNOWN_ID); + void renderGrid(int xDivisions, int yDivisions, const glm::vec4& color); + void renderGrid(gpu::Batch& batch, int xDivisions, int yDivisions, const glm::vec4& color); void renderGrid(int x, int y, int width, int height, int rows, int cols, const glm::vec4& color, int id = UNKNOWN_ID); + void renderGrid(gpu::Batch& batch, int x, int y, int width, int height, int rows, int cols, const glm::vec4& color, int id = UNKNOWN_ID); + void renderSolidCube(float size, const glm::vec4& color); + void renderSolidCube(gpu::Batch& batch, float size, const glm::vec4& color); void renderWireCube(float size, const glm::vec4& color); + void renderWireCube(gpu::Batch& batch, float size, const glm::vec4& color); void renderBevelCornersRect(int x, int y, int width, int height, int bevelDistance, const glm::vec4& color, int id = UNKNOWN_ID); + void renderBevelCornersRect(gpu::Batch& batch, int x, int y, int width, int height, int bevelDistance, const glm::vec4& color, int id = UNKNOWN_ID); void renderQuad(int x, int y, int width, int height, const glm::vec4& color, int id = UNKNOWN_ID) { renderQuad(glm::vec2(x,y), glm::vec2(x + width, y + height), color, id); } + void renderQuad(gpu::Batch& batch, int x, int y, int width, int height, const glm::vec4& color, int id = UNKNOWN_ID) + { renderQuad(batch, glm::vec2(x,y), glm::vec2(x + width, y + height), color, id); } // TODO: I think there's a bug in this version of the renderQuad() that's not correctly rebuilding the vbos // if the color changes by the corners are the same, as evidenced by the audio meter which should turn white // when it's clipping void renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, const glm::vec4& color, int id = UNKNOWN_ID); + void renderQuad(gpu::Batch& batch, const glm::vec2& minCorner, const glm::vec2& maxCorner, const glm::vec4& color, int id = UNKNOWN_ID); void renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, const glm::vec2& texCoordMinCorner, const glm::vec2& texCoordMaxCorner, const glm::vec4& color, int id = UNKNOWN_ID); + void renderQuad(gpu::Batch& batch, const glm::vec2& minCorner, const glm::vec2& maxCorner, + const glm::vec2& texCoordMinCorner, const glm::vec2& texCoordMaxCorner, + const glm::vec4& color, int id = UNKNOWN_ID); void renderQuad(const glm::vec3& minCorner, const glm::vec3& maxCorner, const glm::vec4& color, int id = UNKNOWN_ID); + void renderQuad(gpu::Batch& batch, const glm::vec3& minCorner, const glm::vec3& maxCorner, const glm::vec4& color, int id = UNKNOWN_ID); void renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomLeft, const glm::vec3& bottomRight, const glm::vec3& topRight, const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomLeft, const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight, const glm::vec4& color, int id = UNKNOWN_ID); + void renderQuad(gpu::Batch& batch, const glm::vec3& topLeft, const glm::vec3& bottomLeft, + const glm::vec3& bottomRight, const glm::vec3& topRight, + const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomLeft, + const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight, + const glm::vec4& color, int id = UNKNOWN_ID); void renderLine(const glm::vec3& p1, const glm::vec3& p2, const glm::vec3& color, int id = UNKNOWN_ID) { renderLine(p1, p2, color, color, id); } + void renderLine(gpu::Batch& batch, const glm::vec3& p1, const glm::vec3& p2, const glm::vec3& color, int id = UNKNOWN_ID) + { renderLine(batch, p1, p2, color, color, id); } void renderLine(const glm::vec3& p1, const glm::vec3& p2, const glm::vec3& color1, const glm::vec3& color2, int id = UNKNOWN_ID) { renderLine(p1, p2, glm::vec4(color1, 1.0f), glm::vec4(color2, 1.0f), id); } + void renderLine(gpu::Batch& batch, const glm::vec3& p1, const glm::vec3& p2, + const glm::vec3& color1, const glm::vec3& color2, int id = UNKNOWN_ID) + { renderLine(batch, p1, p2, glm::vec4(color1, 1.0f), glm::vec4(color2, 1.0f), id); } void renderLine(const glm::vec3& p1, const glm::vec3& p2, const glm::vec4& color, int id = UNKNOWN_ID) { renderLine(p1, p2, color, color, id); } + void renderLine(gpu::Batch& batch, const glm::vec3& p1, const glm::vec3& p2, + const glm::vec4& color, int id = UNKNOWN_ID) + { renderLine(batch, p1, p2, color, color, id); } void renderLine(const glm::vec3& p1, const glm::vec3& p2, const glm::vec4& color1, const glm::vec4& color2, int id = UNKNOWN_ID); + void renderLine(gpu::Batch& batch, const glm::vec3& p1, const glm::vec3& p2, + const glm::vec4& color1, const glm::vec4& color2, int id = UNKNOWN_ID); void renderDashedLine(const glm::vec3& start, const glm::vec3& end, const glm::vec4& color, int id = UNKNOWN_ID); + void renderDashedLine(gpu::Batch& batch, const glm::vec3& start, const glm::vec3& end, const glm::vec4& color, int id = UNKNOWN_ID); void renderLine(const glm::vec2& p1, const glm::vec2& p2, const glm::vec3& color, int id = UNKNOWN_ID) { renderLine(p1, p2, glm::vec4(color, 1.0f), id); } + void renderLine(gpu::Batch& batch, const glm::vec2& p1, const glm::vec2& p2, const glm::vec3& color, int id = UNKNOWN_ID) + { renderLine(batch, p1, p2, glm::vec4(color, 1.0f), id); } void renderLine(const glm::vec2& p1, const glm::vec2& p2, const glm::vec4& color, int id = UNKNOWN_ID) { renderLine(p1, p2, color, color, id); } + void renderLine(gpu::Batch& batch, const glm::vec2& p1, const glm::vec2& p2, const glm::vec4& color, int id = UNKNOWN_ID) + { renderLine(batch, p1, p2, color, color, id); } void renderLine(const glm::vec2& p1, const glm::vec2& p2, const glm::vec3& color1, const glm::vec3& color2, int id = UNKNOWN_ID) { renderLine(p1, p2, glm::vec4(color1, 1.0f), glm::vec4(color2, 1.0f), id); } + void renderLine(gpu::Batch& batch, const glm::vec2& p1, const glm::vec2& p2, + const glm::vec3& color1, const glm::vec3& color2, int id = UNKNOWN_ID) + { renderLine(batch, p1, p2, glm::vec4(color1, 1.0f), glm::vec4(color2, 1.0f), id); } void renderLine(const glm::vec2& p1, const glm::vec2& p2, const glm::vec4& color1, const glm::vec4& color2, int id = UNKNOWN_ID); + void renderLine(gpu::Batch& batch, const glm::vec2& p1, const glm::vec2& p2, + const glm::vec4& color1, const glm::vec4& color2, int id = UNKNOWN_ID); void updateVertices(int id, const QVector& points, const glm::vec4& color); void updateVertices(int id, const QVector& points, const glm::vec4& color); From 776955b04026493fe7931ed826f553284ad38df8 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 15 May 2015 14:58:27 -0700 Subject: [PATCH 14/23] Move GeometryCache gl* calls to non-batch methods --- libraries/render-utils/src/GeometryCache.cpp | 166 +++++++++---------- libraries/render-utils/src/GeometryCache.h | 1 + 2 files changed, 83 insertions(+), 84 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index f66bfb91ea..a62eadac45 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -59,6 +59,12 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm gpu::Batch batch; renderSphere(batch, radius, slices, stacks, color, solid, id); gpu::GLBackend::renderBatch(batch); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } void GeometryCache::renderSphere(gpu::Batch& batch, float radius, int slices, int stacks, const glm::vec4& color, bool solid, int id) { @@ -296,12 +302,6 @@ void GeometryCache::renderSphere(gpu::Batch& batch, float radius, int slices, in } else { batch.drawIndexed(gpu::LINES, indices); } - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } void GeometryCache::renderCone(float base, float height, int slices, int stacks) { @@ -409,6 +409,11 @@ void GeometryCache::renderGrid(int xDivisions, int yDivisions, const glm::vec4& gpu::Batch batch; renderGrid(batch, xDivisions, yDivisions, color); gpu::GLBackend::renderBatch(batch); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + + glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderGrid(gpu::Batch& batch, int xDivisions, int yDivisions, const glm::vec4& color) { @@ -483,18 +488,17 @@ void GeometryCache::renderGrid(gpu::Batch& batch, int xDivisions, int yDivisions batch.setInputBuffer(VERTICES_SLOT, verticesView); batch.setInputBuffer(COLOR_SLOT, colorView); batch.draw(gpu::LINES, vertices, 0); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - - glBindBuffer(GL_ARRAY_BUFFER, 0); - } void GeometryCache::renderGrid(int x, int y, int width, int height, int rows, int cols, const glm::vec4& color, int id) { gpu::Batch batch; renderGrid(x, y, width, height, rows, cols, color, id); gpu::GLBackend::renderBatch(batch); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + + glBindBuffer(GL_ARRAY_BUFFER, 0); } // TODO: properly handle the x,y,w,h changing for an ID @@ -596,11 +600,6 @@ void GeometryCache::renderGrid(gpu::Batch& batch, int x, int y, int width, int h batch.setInputBuffer(VERTICES_SLOT, verticesView); batch.setInputBuffer(COLOR_SLOT, colorView); batch.draw(gpu::LINES, vertices, 0); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - - glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::updateVertices(int id, const QVector& points, const glm::vec4& color) { @@ -799,20 +798,22 @@ void GeometryCache::updateVertices(int id, const QVector& points, con } void GeometryCache::renderVertices(gpu::Primitive primitiveType, int id) { + gpu::Batch batch; + renderVertices(batch, primitiveType, id); + gpu::GLBackend::renderBatch(batch); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + + glBindBuffer(GL_ARRAY_BUFFER, 0); +} + +void GeometryCache::renderVertices(gpu::Batch& batch, gpu::Primitive primitiveType, int id) { BatchItemDetails& details = _registeredVertices[id]; if (details.isCreated) { - gpu::Batch batch; - batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(primitiveType, details.vertices, 0); - - gpu::GLBackend::renderBatch(batch); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - - glBindBuffer(GL_ARRAY_BUFFER, 0); } } @@ -820,6 +821,12 @@ void GeometryCache::renderSolidCube(float size, const glm::vec4& color) { gpu::Batch batch; renderSolidCube(batch, size, color); gpu::GLBackend::renderBatch(batch); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } void GeometryCache::renderSolidCube(gpu::Batch& batch, float size, const glm::vec4& color) { @@ -934,18 +941,18 @@ void GeometryCache::renderSolidCube(gpu::Batch& batch, float size, const glm::ve batch.setInputBuffer(COLOR_SLOT, colorView); batch.setIndexBuffer(gpu::UINT8, _solidCubeIndexBuffer, 0); batch.drawIndexed(gpu::TRIANGLES, indices); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } void GeometryCache::renderWireCube(float size, const glm::vec4& color) { gpu::Batch batch; renderWireCube(batch, size, color); gpu::GLBackend::renderBatch(batch); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } void GeometryCache::renderWireCube(gpu::Batch& batch, float size, const glm::vec4& color) { @@ -1023,18 +1030,17 @@ void GeometryCache::renderWireCube(gpu::Batch& batch, float size, const glm::vec batch.setInputBuffer(COLOR_SLOT, colorView); batch.setIndexBuffer(gpu::UINT8, _wireCubeIndexBuffer, 0); batch.drawIndexed(gpu::LINES, indices); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } void GeometryCache::renderBevelCornersRect(int x, int y, int width, int height, int bevelDistance, const glm::vec4& color, int id) { gpu::Batch batch; renderBevelCornersRect(batch, x, y, width, height, bevelDistance, color, id); gpu::GLBackend::renderBatch(batch); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + + glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderBevelCornersRect(gpu::Batch& batch, int x, int y, int width, int height, int bevelDistance, const glm::vec4& color, int id) { @@ -1133,17 +1139,17 @@ void GeometryCache::renderBevelCornersRect(gpu::Batch& batch, int x, int y, int batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(gpu::QUADS, 4, 0); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - - glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, const glm::vec4& color, int id) { gpu::Batch batch; renderQuad(batch, minCorner, maxCorner, color, id); gpu::GLBackend::renderBatch(batch); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + + glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec2& minCorner, const glm::vec2& maxCorner, const glm::vec4& color, int id) { @@ -1215,11 +1221,6 @@ void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec2& minCorner, co batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(gpu::QUADS, 4, 0); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - - glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, @@ -1228,6 +1229,12 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC gpu::Batch batch; renderQuad(batch, minCorner, maxCorner, texCoordMinCorner, texCoordMaxCorner, color, id); gpu::GLBackend::renderBatch(batch); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + + glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec2& minCorner, const glm::vec2& maxCorner, @@ -1305,26 +1312,20 @@ void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec2& minCorner, co details.colorBuffer->append(sizeof(colors), (gpu::Byte*) colors); } -// glEnable(GL_TEXTURE_2D); - //glBindTexture(GL_TEXTURE_2D, _currentTextureID); // this is quad specific... - batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(gpu::QUADS, 4, 0); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - - glBindBuffer(GL_ARRAY_BUFFER, 0); - // glBindTexture(GL_TEXTURE_2D, 0); - // glDisable(GL_TEXTURE_2D); } void GeometryCache::renderQuad(const glm::vec3& minCorner, const glm::vec3& maxCorner, const glm::vec4& color, int id) { gpu::Batch batch; renderQuad(batch, minCorner, maxCorner, color, id); gpu::GLBackend::renderBatch(batch); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + + glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec3& minCorner, const glm::vec3& maxCorner, const glm::vec4& color, int id) { @@ -1396,11 +1397,6 @@ void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec3& minCorner, co batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(gpu::QUADS, 4, 0); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - - glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomLeft, @@ -1411,7 +1407,16 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom gpu::Batch batch; renderQuad(batch, topLeft, bottomLeft, bottomRight, topRight, texCoordTopLeft, texCoordBottomLeft, texCoordBottomRight, texCoordTopRight, color, id); + + glEnable(GL_TEXTURE_2D); + gpu::GLBackend::renderBatch(batch); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + + glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec3& topLeft, const glm::vec3& bottomLeft, @@ -1502,18 +1507,11 @@ void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec3& topLeft, cons details.colorBuffer->append(sizeof(colors), (gpu::Byte*) colors); } - glEnable(GL_TEXTURE_2D); //glBindTexture(GL_TEXTURE_2D, _currentTextureID); // this is quad specific... batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(gpu::QUADS, 4, 0); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - - glBindBuffer(GL_ARRAY_BUFFER, 0); // TODO: The callers of this method (renderMagnifier and renderReticle) assume that we won't disable an unbind // the texture after rendering. I'm not sure if this is correct in general but it's currently required for the @@ -1526,6 +1524,11 @@ void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& en gpu::Batch batch; renderDashedLine(batch, start, end, color, id); gpu::GLBackend::renderBatch(batch); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + + glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderDashedLine(gpu::Batch& batch, const glm::vec3& start, const glm::vec3& end, const glm::vec4& color, int id) { @@ -1631,11 +1634,6 @@ void GeometryCache::renderDashedLine(gpu::Batch& batch, const glm::vec3& start, batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(gpu::LINES, details.vertices, 0); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - - glBindBuffer(GL_ARRAY_BUFFER, 0); } @@ -1692,6 +1690,10 @@ void GeometryCache::renderLine(const glm::vec3& p1, const glm::vec3& p2, gpu::Batch batch; renderLine(batch, p1, p2, color1, color2, id); gpu::GLBackend::renderBatch(batch); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderLine(gpu::Batch& batch, const glm::vec3& p1, const glm::vec3& p2, @@ -1776,16 +1778,16 @@ void GeometryCache::renderLine(gpu::Batch& batch, const glm::vec3& p1, const glm batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(gpu::LINES, 2, 0); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderLine(const glm::vec2& p1, const glm::vec2& p2, const glm::vec4& color1, const glm::vec4& color2, int id) { gpu::Batch batch; renderLine(batch, p1, p2, color1, color2, id); gpu::GLBackend::renderBatch(batch); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderLine(gpu::Batch& batch, const glm::vec2& p1, const glm::vec2& p2, @@ -1870,10 +1872,6 @@ void GeometryCache::renderLine(gpu::Batch& batch, const glm::vec2& p1, const glm batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(gpu::LINES, 2, 0); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - glBindBuffer(GL_ARRAY_BUFFER, 0); } diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 3dc1a7ac41..9b21eab2d6 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -241,6 +241,7 @@ public: void updateVertices(int id, const QVector& points, const glm::vec4& color); void updateVertices(int id, const QVector& points, const glm::vec4& color); void updateVertices(int id, const QVector& points, const QVector& texCoords, const glm::vec4& color); + void renderVertices(gpu::Batch& batch, gpu::Primitive primitiveType, int id); void renderVertices(gpu::Primitive primitiveType, int id); /// Loads geometry from the specified URL. From 6e1c5d704ca3f6b7ab76ab700ac553647ae0ae01 Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Fri, 15 May 2015 15:24:10 -0700 Subject: [PATCH 15/23] 'modified airHockey script to be able to spawn and delete using buttons, added light flashing on score, and puck now respawns on player's side who just got scored on --- examples/example/games/airHockey.js | 732 ++++++++++++++++++++-------- 1 file changed, 538 insertions(+), 194 deletions(-) diff --git a/examples/example/games/airHockey.js b/examples/example/games/airHockey.js index 98bab1d57e..0bcfa8f2c4 100644 --- a/examples/example/games/airHockey.js +++ b/examples/example/games/airHockey.js @@ -10,29 +10,43 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -var debugVisible = false; +var debugVisible = false; var FIELD_WIDTH = 1.21; var FIELD_LENGTH = 1.92; var FLOOR_THICKNESS = 0.20; var EDGE_THICKESS = 0.10; var EDGE_HEIGHT = 0.10; -var DROP_HEIGHT = 0.3; +var DROP_HEIGHT = 0.3; var PUCK_SIZE = 0.15; var PUCK_THICKNESS = 0.05; var PADDLE_SIZE = 0.15; var PADDLE_THICKNESS = 0.05; +var ENTITY_SEARCH_RANGE = 500; + var GOAL_WIDTH = 0.35; var GRAVITY = -9.8; -var LIFETIME = 6000; +var LIFETIME = 6000; var PUCK_DAMPING = 0.02; var PADDLE_DAMPING = 0.35; var ANGULAR_DAMPING = 0.4; var PADDLE_ANGULAR_DAMPING = 0.75; var MODEL_SCALE = 1.52; -var MODEL_OFFSET = { x: 0, y: -0.19, z: 0 }; +var MODEL_OFFSET = { + x: 0, + y: -0.19, + z: 0 +}; + +var LIGHT_OFFSET = { + x: 0, + y: 0.2, + z: 0 +}; + +var LIGHT_FLASH_TIME = 700; var scoreSound = SoundCache.getSound("https://s3.amazonaws.com/hifi-public/sounds/Collisions-hitsandslaps/airhockey_score.wav"); @@ -46,221 +60,551 @@ var puckCollisionModel = "http://headache.hungry.com/~seth/hifi/airHockeyPuck-hu var paddleModel = "https://hifi-public.s3.amazonaws.com/ozan/props/airHockeyTable/airHockeyPaddle.obj" var paddleCollisionModel = "http://headache.hungry.com/~seth/hifi/paddle-hull.obj" -var center = Vec3.sum(MyAvatar.position, Vec3.multiply((FIELD_WIDTH + FIELD_LENGTH) * 0.60, Quat.getFront(Camera.getOrientation()))); +HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/"; +var screenSize = Controller.getViewportDimensions(); +var BUTTON_SIZE = 32; +var PADDING = 3; + +var center; var edgeRestitution = 0.9; var floorFriction = 0.01; -var floor = Entities.addEntity( - { type: "Box", - position: Vec3.subtract(center, { x: 0, y: 0, z: 0 }), - dimensions: { x: FIELD_WIDTH, y: FLOOR_THICKNESS, z: FIELD_LENGTH }, - color: { red: 128, green: 128, blue: 128 }, - gravity: { x: 0, y: 0, z: 0 }, - ignoreCollisions: false, - locked: true, - friction: floorFriction, - visible: debugVisible, - lifetime: LIFETIME }); +var paddle1Pos, paddle2Pos; +var names = ['floor', 'table', 'paddle', 'edge', 'puck', 'hockeyLight']; -var edge1 = Entities.addEntity( - { type: "Box", - collisionSoundURL: hitSideSound, - position: Vec3.sum(center, { x: FIELD_WIDTH / 2.0, y: FLOOR_THICKNESS / 2.0, z: 0 }), - dimensions: { x: EDGE_THICKESS, y: EDGE_HEIGHT, z: FIELD_LENGTH + EDGE_THICKESS }, - color: { red: 100, green: 100, blue: 100 }, - gravity: { x: 0, y: 0, z: 0 }, - ignoreCollisions: false, - visible: debugVisible, - restitution: edgeRestitution, - locked: true, - lifetime: LIFETIME }); +var deleteButton = Overlays.addOverlay("image", { + x: screenSize.x / 2 - BUTTON_SIZE, + y: screenSize.y - (BUTTON_SIZE + PADDING), + width: BUTTON_SIZE, + height: BUTTON_SIZE, + imageURL: HIFI_PUBLIC_BUCKET + "images/delete.png", + color: { + red: 255, + green: 255, + blue: 255 + }, + alpha: 1 +}); -var edge2 = Entities.addEntity( - { type: "Box", - collisionSoundURL: hitSideSound, - position: Vec3.sum(center, { x: -FIELD_WIDTH / 2.0, y: FLOOR_THICKNESS / 2.0, z: 0 }), - dimensions: { x: EDGE_THICKESS, y: EDGE_HEIGHT, z: FIELD_LENGTH + EDGE_THICKESS }, - color: { red: 100, green: 100, blue: 100 }, - gravity: { x: 0, y: 0, z: 0 }, - ignoreCollisions: false, - visible: debugVisible, - restitution: edgeRestitution, - locked: true, - lifetime: LIFETIME }); +var spawnButton = Overlays.addOverlay("image", { + x: screenSize.x / 2 + PADDING, + y: screenSize.y - (BUTTON_SIZE + PADDING), + width: BUTTON_SIZE, + height: BUTTON_SIZE, + imageURL: HIFI_PUBLIC_BUCKET + "images/die.png", + color: { + red: 255, + green: 255, + blue: 255 + }, + alpha: 1 +}); -var edge3a = Entities.addEntity( - { type: "Box", - collisionSoundURL: hitSideSound, - position: Vec3.sum(center, { x: FIELD_WIDTH / 4.0 + (GOAL_WIDTH / 4.0), y: FLOOR_THICKNESS / 2.0, z: -FIELD_LENGTH / 2.0 }), - dimensions: { x: FIELD_WIDTH / 2.0 - GOAL_WIDTH / 2.0, y: EDGE_HEIGHT, z: EDGE_THICKESS }, - color: { red: 100, green: 100, blue: 100 }, - gravity: { x: 0, y: 0, z: 0 }, - ignoreCollisions: false, - visible: debugVisible, - restitution: edgeRestitution, - locked: true, - lifetime: LIFETIME }); -var edge3b = Entities.addEntity( - { type: "Box", - collisionSoundURL: hitSideSound, - position: Vec3.sum(center, { x: -FIELD_WIDTH / 4.0 - (GOAL_WIDTH / 4.0), y: FLOOR_THICKNESS / 2.0, z: -FIELD_LENGTH / 2.0 }), - dimensions: { x: FIELD_WIDTH / 2.0 - GOAL_WIDTH / 2.0, y: EDGE_HEIGHT, z: EDGE_THICKESS }, - color: { red: 100, green: 100, blue: 100 }, - gravity: { x: 0, y: 0, z: 0 }, - ignoreCollisions: false, - visible: debugVisible, - restitution: edgeRestitution, - locked: true, - lifetime: LIFETIME }); - -var edge4a = Entities.addEntity( - { type: "Box", - collisionSoundURL: hitSideSound, - position: Vec3.sum(center, { x: FIELD_WIDTH / 4.0 + (GOAL_WIDTH / 4.0), y: FLOOR_THICKNESS / 2.0, z: FIELD_LENGTH / 2.0 }), - dimensions: { x: FIELD_WIDTH / 2.0 - GOAL_WIDTH / 2.0, y: EDGE_HEIGHT, z: EDGE_THICKESS }, - color: { red: 100, green: 100, blue: 100 }, - gravity: { x: 0, y: 0, z: 0 }, - ignoreCollisions: false, - visible: debugVisible, - restitution: edgeRestitution, - locked: true, - lifetime: LIFETIME }); - -var edge4b = Entities.addEntity( - { type: "Box", - collisionSoundURL: hitSideSound, - position: Vec3.sum(center, { x: -FIELD_WIDTH / 4.0 - (GOAL_WIDTH / 4.0), y: FLOOR_THICKNESS / 2.0, z: FIELD_LENGTH / 2.0 }), - dimensions: { x: FIELD_WIDTH / 2.0 - GOAL_WIDTH / 2.0, y: EDGE_HEIGHT, z: EDGE_THICKESS }, - color: { red: 100, green: 100, blue: 100 }, - gravity: { x: 0, y: 0, z: 0 }, - ignoreCollisions: false, - visible: debugVisible, - restitution: edgeRestitution, - locked: true, - lifetime: LIFETIME }); - -var table = Entities.addEntity( - { type: "Model", - modelURL: polyTable, - dimensions: Vec3.multiply({ x: 0.8, y: 0.45, z: 1.31 }, MODEL_SCALE), - position: Vec3.sum(center, MODEL_OFFSET), - ignoreCollisions: false, - visible: true, - locked: true, - lifetime: LIFETIME }); +var floor, edge1, edge2, edge3a, edge3b, edge4a, edge4b, light; var puck; var paddle1, paddle2; // Create pucks -function makeNewProp(which) { - if (which == "puck") { - return Entities.addEntity( - { type: "Model", - modelURL: puckModel, - compoundShapeURL: puckCollisionModel, - collisionSoundURL: hitSound1, - position: Vec3.sum(center, { x: 0, y: DROP_HEIGHT, z: 0 }), - dimensions: { x: PUCK_SIZE, y: PUCK_THICKNESS, z: PUCK_SIZE }, - gravity: { x: 0, y: GRAVITY, z: 0 }, - velocity: { x: 0, y: 0.05, z: 0 }, - ignoreCollisions: false, - damping: PUCK_DAMPING, - angularDamping: ANGULAR_DAMPING, - lifetime: LIFETIME, - collisionsWillMove: true }); - } - else if (which == "paddle1") { - return Entities.addEntity( - { type: "Model", - modelURL: paddleModel, - compoundShapeURL: paddleCollisionModel, - collisionSoundURL: hitSound2, - position: Vec3.sum(center, { x: 0, y: DROP_HEIGHT * 1.5, z: FIELD_LENGTH * 0.35 }), - dimensions: { x: PADDLE_SIZE, y: PADDLE_THICKNESS, z: PADDLE_SIZE }, - gravity: { x: 0, y: GRAVITY, z: 0 }, - velocity: { x: 0, y: 0.07, z: 0 }, - ignoreCollisions: false, - damping: PADDLE_DAMPING, - angularDamping: PADDLE_ANGULAR_DAMPING, - lifetime: LIFETIME, - collisionsWillMove: true }); - } - else if (which == "paddle2") { - return Entities.addEntity( - { type: "Model", - modelURL: paddleModel, - compoundShapeURL: paddleCollisionModel, - collisionSoundURL: hitSound2, - position: Vec3.sum(center, { x: 0, y: DROP_HEIGHT * 1.5, z: -FIELD_LENGTH * 0.35 }), - dimensions: { x: PADDLE_SIZE, y: PADDLE_THICKNESS, z: PADDLE_SIZE }, - gravity: { x: 0, y: GRAVITY, z: 0 }, - velocity: { x: 0, y: 0.07, z: 0 }, - ignoreCollisions: false, - damping: PADDLE_DAMPING, - angularDamping: PADDLE_ANGULAR_DAMPING, - lifetime: LIFETIME, - collisionsWillMove: true }); - } +function makeNewProp(which, position) { + if (which == "puck") { + return Entities.addEntity({ + name: 'puck', + type: "Model", + modelURL: puckModel, + compoundShapeURL: puckCollisionModel, + collisionSoundURL: hitSound1, + position: Vec3.sum(center, { + x: 0, + y: DROP_HEIGHT, + z: 0 + }), + dimensions: { + x: PUCK_SIZE, + y: PUCK_THICKNESS, + z: PUCK_SIZE + }, + gravity: { + x: 0, + y: GRAVITY, + z: 0 + }, + velocity: { + x: 0, + y: 0.05, + z: 0 + }, + ignoreCollisions: false, + damping: PUCK_DAMPING, + angularDamping: ANGULAR_DAMPING, + lifetime: LIFETIME, + collisionsWillMove: true + }); + } else if (which == "paddle1") { + paddle1Pos = Vec3.sum(center, { + x: 0, + y: DROP_HEIGHT * 1.5, + z: FIELD_LENGTH * 0.35 + }); + return Entities.addEntity({ + name: "paddle", + type: "Model", + modelURL: paddleModel, + compoundShapeURL: paddleCollisionModel, + collisionSoundURL: hitSound2, + position: paddle1Pos, + dimensions: { + x: PADDLE_SIZE, + y: PADDLE_THICKNESS, + z: PADDLE_SIZE + }, + gravity: { + x: 0, + y: GRAVITY, + z: 0 + }, + velocity: { + x: 0, + y: 0.07, + z: 0 + }, + ignoreCollisions: false, + damping: PADDLE_DAMPING, + angularDamping: PADDLE_ANGULAR_DAMPING, + lifetime: LIFETIME, + collisionsWillMove: true + }); + } else if (which == "paddle2") { + paddle2Pos = Vec3.sum(center, { + x: 0, + y: DROP_HEIGHT * 1.5, + z: -FIELD_LENGTH * 0.35 + }); + return Entities.addEntity({ + name: "paddle", + type: "Model", + modelURL: paddleModel, + compoundShapeURL: paddleCollisionModel, + collisionSoundURL: hitSound2, + position: paddle2Pos, + dimensions: { + x: PADDLE_SIZE, + y: PADDLE_THICKNESS, + z: PADDLE_SIZE + }, + gravity: { + x: 0, + y: GRAVITY, + z: 0 + }, + velocity: { + x: 0, + y: 0.07, + z: 0 + }, + ignoreCollisions: false, + damping: PADDLE_DAMPING, + angularDamping: PADDLE_ANGULAR_DAMPING, + lifetime: LIFETIME, + collisionsWillMove: true + }); + } } -puck = makeNewProp("puck"); -paddle1 = makeNewProp("paddle1"); -paddle2 = makeNewProp("paddle2"); function update(deltaTime) { - if (Math.random() < 0.1) { - puckProps = Entities.getEntityProperties(puck); - paddle1Props = Entities.getEntityProperties(paddle1); - paddle2Props = Entities.getEntityProperties(paddle2); - if (puckProps.position.y < (center.y - DROP_HEIGHT)) { - Audio.playSound(scoreSound, { - position: center, - volume: 1.0 - }); - Entities.deleteEntity(puck); - puck = makeNewProp("puck"); - } - - if (paddle1Props.position.y < (center.y - DROP_HEIGHT)) { - Entities.deleteEntity(paddle1); - paddle1 = makeNewProp("paddle1"); - } - if (paddle2Props.position.y < (center.y - DROP_HEIGHT)) { - Entities.deleteEntity(paddle2); - paddle2 = makeNewProp("paddle2"); - } - } + if (Math.random() < 0.1) { + puckProps = Entities.getEntityProperties(puck); + paddle1Props = Entities.getEntityProperties(paddle1); + paddle2Props = Entities.getEntityProperties(paddle2); + if (puckProps.position.y < (center.y - DROP_HEIGHT)) { + score(); + } + + if (paddle1Props.position.y < (center.y - DROP_HEIGHT)) { + Entities.deleteEntity(paddle1); + paddle1 = makeNewProp("paddle1"); + } + if (paddle2Props.position.y < (center.y - DROP_HEIGHT)) { + Entities.deleteEntity(paddle2); + paddle2 = makeNewProp("paddle2"); + } + } +} + +function score() { + Audio.playSound(scoreSound, { + position: center, + volume: 1.0 + }); + puckDropPosition = Entities.getEntityProperties(puck).position; + var newPosition; + if (Vec3.distance(puckDropPosition, paddle1Pos) > Vec3.distance(puckDropPosition, paddle2Pos)) { + newPosition = paddle2Pos; + } else { + newPosition = paddle1Pos; + } + Entities.editEntity(puck, { + position: newPosition, + velocity: { + x: 0, + y: 0.05, + z: 0 + } + }); + + Entities.editEntity(light, { + visible: true + }); + Script.setTimeout(function() { + Entities.editEntity(light, { + visible: false + }); + }, LIGHT_FLASH_TIME); +} + +function mousePressEvent(event) { + var clickedOverlay = Overlays.getOverlayAtPoint({ + x: event.x, + y: event.y + }); + if (clickedOverlay == spawnButton) { + spawnAllTheThings(); + } else if (clickedOverlay == deleteButton) { + deleteAllTheThings(); + } +} + +function spawnAllTheThings() { + center = Vec3.sum(MyAvatar.position, Vec3.multiply((FIELD_WIDTH + FIELD_LENGTH) * 0.60, Quat.getFront(Camera.getOrientation()))); + floor = Entities.addEntity({ + name: "floor", + type: "Box", + position: Vec3.subtract(center, { + x: 0, + y: 0, + z: 0 + }), + dimensions: { + x: FIELD_WIDTH, + y: FLOOR_THICKNESS, + z: FIELD_LENGTH + }, + color: { + red: 128, + green: 128, + blue: 128 + }, + gravity: { + x: 0, + y: 0, + z: 0 + }, + ignoreCollisions: false, + locked: true, + friction: floorFriction, + visible: debugVisible, + lifetime: LIFETIME + }); + + edge1 = Entities.addEntity({ + name: 'edge', + type: "Box", + collisionSoundURL: hitSideSound, + position: Vec3.sum(center, { + x: FIELD_WIDTH / 2.0, + y: FLOOR_THICKNESS / 2.0, + z: 0 + }), + dimensions: { + x: EDGE_THICKESS, + y: EDGE_HEIGHT, + z: FIELD_LENGTH + EDGE_THICKESS + }, + color: { + red: 100, + green: 100, + blue: 100 + }, + gravity: { + x: 0, + y: 0, + z: 0 + }, + ignoreCollisions: false, + visible: debugVisible, + restitution: edgeRestitution, + locked: true, + lifetime: LIFETIME + }); + + edge2 = Entities.addEntity({ + name: 'edge', + type: "Box", + collisionSoundURL: hitSideSound, + position: Vec3.sum(center, { + x: -FIELD_WIDTH / 2.0, + y: FLOOR_THICKNESS / 2.0, + z: 0 + }), + dimensions: { + x: EDGE_THICKESS, + y: EDGE_HEIGHT, + z: FIELD_LENGTH + EDGE_THICKESS + }, + color: { + red: 100, + green: 100, + blue: 100 + }, + gravity: { + x: 0, + y: 0, + z: 0 + }, + ignoreCollisions: false, + visible: debugVisible, + restitution: edgeRestitution, + locked: true, + lifetime: LIFETIME + }); + + edge3a = Entities.addEntity({ + name: 'edge', + type: "Box", + collisionSoundURL: hitSideSound, + position: Vec3.sum(center, { + x: FIELD_WIDTH / 4.0 + (GOAL_WIDTH / 4.0), + y: FLOOR_THICKNESS / 2.0, + z: -FIELD_LENGTH / 2.0 + }), + dimensions: { + x: FIELD_WIDTH / 2.0 - GOAL_WIDTH / 2.0, + y: EDGE_HEIGHT, + z: EDGE_THICKESS + }, + color: { + red: 100, + green: 100, + blue: 100 + }, + gravity: { + x: 0, + y: 0, + z: 0 + }, + ignoreCollisions: false, + visible: debugVisible, + restitution: edgeRestitution, + locked: true, + lifetime: LIFETIME + }); + + edge3b = Entities.addEntity({ + name: 'edge', + type: "Box", + collisionSoundURL: hitSideSound, + position: Vec3.sum(center, { + x: -FIELD_WIDTH / 4.0 - (GOAL_WIDTH / 4.0), + y: FLOOR_THICKNESS / 2.0, + z: -FIELD_LENGTH / 2.0 + }), + dimensions: { + x: FIELD_WIDTH / 2.0 - GOAL_WIDTH / 2.0, + y: EDGE_HEIGHT, + z: EDGE_THICKESS + }, + color: { + red: 100, + green: 100, + blue: 100 + }, + gravity: { + x: 0, + y: 0, + z: 0 + }, + ignoreCollisions: false, + visible: debugVisible, + restitution: edgeRestitution, + locked: true, + lifetime: LIFETIME + }); + + edge4a = Entities.addEntity({ + name: 'edge', + type: "Box", + collisionSoundURL: hitSideSound, + position: Vec3.sum(center, { + x: FIELD_WIDTH / 4.0 + (GOAL_WIDTH / 4.0), + y: FLOOR_THICKNESS / 2.0, + z: FIELD_LENGTH / 2.0 + }), + dimensions: { + x: FIELD_WIDTH / 2.0 - GOAL_WIDTH / 2.0, + y: EDGE_HEIGHT, + z: EDGE_THICKESS + }, + color: { + red: 100, + green: 100, + blue: 100 + }, + gravity: { + x: 0, + y: 0, + z: 0 + }, + ignoreCollisions: false, + visible: debugVisible, + restitution: edgeRestitution, + locked: true, + lifetime: LIFETIME + }); + + edge4b = Entities.addEntity({ + name: 'edge', + type: "Box", + collisionSoundURL: hitSideSound, + position: Vec3.sum(center, { + x: -FIELD_WIDTH / 4.0 - (GOAL_WIDTH / 4.0), + y: FLOOR_THICKNESS / 2.0, + z: FIELD_LENGTH / 2.0 + }), + dimensions: { + x: FIELD_WIDTH / 2.0 - GOAL_WIDTH / 2.0, + y: EDGE_HEIGHT, + z: EDGE_THICKESS + }, + color: { + red: 100, + green: 100, + blue: 100 + }, + gravity: { + x: 0, + y: 0, + z: 0 + }, + ignoreCollisions: false, + visible: debugVisible, + restitution: edgeRestitution, + locked: true, + lifetime: LIFETIME + }); + + table = Entities.addEntity({ + name: "table", + type: "Model", + modelURL: polyTable, + dimensions: Vec3.multiply({ + x: 0.8, + y: 0.45, + z: 1.31 + }, MODEL_SCALE), + position: Vec3.sum(center, MODEL_OFFSET), + ignoreCollisions: false, + visible: true, + locked: true, + lifetime: LIFETIME + }); + + light = Entities.addEntity({ + name: "hockeyLight", + type: "Light", + dimensions: { + x: 5, + y: 5, + z: 5 + }, + position: Vec3.sum(center, LIGHT_OFFSET), + intensity: 5, + color: { + red: 200, + green: 20, + blue: 200 + }, + visible: false + }); + puck = makeNewProp("puck"); + paddle1 = makeNewProp("paddle1"); + paddle2 = makeNewProp("paddle2"); + + Script.update.connect(update); + +} + +function deleteAllTheThings() { + + Script.update.disconnect(update); + //delete all nearby entitites that are named any the names from our names array + var nearbyEntities = Entities.findEntities(MyAvatar.position, ENTITY_SEARCH_RANGE); + for (var i = 0; i < nearbyEntities.length; i++) { + var entityName = Entities.getEntityProperties(nearbyEntities[i]).name; + for (var j = 0; j < names.length; j++) { + if (names[j] === entityName) { + //We have a mach- delete this entity + Entities.editEntity(nearbyEntities[i], { + locked: false + }); + Entities.deleteEntity(nearbyEntities[i]); + } + } + } + + } function scriptEnding() { - Entities.editEntity(edge1, { locked: false }); - Entities.editEntity(edge2, { locked: false }); - Entities.editEntity(edge3a, { locked: false }); - Entities.editEntity(edge3b, { locked: false }); - Entities.editEntity(edge4a, { locked: false }); - Entities.editEntity(edge4b, { locked: false }); - Entities.editEntity(floor, { locked: false }); - Entities.editEntity(table, { locked: false }); + Overlays.deleteOverlay(spawnButton); + Overlays.deleteOverlay(deleteButton); + + Entities.editEntity(edge1, { + locked: false + }); + Entities.editEntity(edge2, { + locked: false + }); + Entities.editEntity(edge3a, { + locked: false + }); + Entities.editEntity(edge3b, { + locked: false + }); + Entities.editEntity(edge4a, { + locked: false + }); + Entities.editEntity(edge4b, { + locked: false + }); + Entities.editEntity(floor, { + locked: false + }); + Entities.editEntity(table, { + locked: false + }); - Entities.deleteEntity(edge1); - Entities.deleteEntity(edge2); - Entities.deleteEntity(edge3a); - Entities.deleteEntity(edge3b); - Entities.deleteEntity(edge4a); - Entities.deleteEntity(edge4b); - Entities.deleteEntity(floor); - Entities.deleteEntity(puck); - Entities.deleteEntity(paddle1); - Entities.deleteEntity(paddle2); - Entities.deleteEntity(table); + + Entities.deleteEntity(edge1); + Entities.deleteEntity(edge2); + Entities.deleteEntity(edge3a); + Entities.deleteEntity(edge3b); + Entities.deleteEntity(edge4a); + Entities.deleteEntity(edge4b); + Entities.deleteEntity(floor); + Entities.deleteEntity(puck); + Entities.deleteEntity(paddle1); + Entities.deleteEntity(paddle2); + Entities.deleteEntity(table); + Entities.deleteEntity(light); + } -Script.update.connect(update); +Controller.mousePressEvent.connect(mousePressEvent); Script.scriptEnding.connect(scriptEnding); \ No newline at end of file From 9bfca7f54d656d5b00d5fa00669a6a907904e97e Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Fri, 15 May 2015 15:43:23 -0700 Subject: [PATCH 16/23] 'moved icons up so they don't interfere with dice icons and changed spanw icon from dice to puck icon' ' --- examples/example/games/airHockey.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/example/games/airHockey.js b/examples/example/games/airHockey.js index 0bcfa8f2c4..ecef697b3e 100644 --- a/examples/example/games/airHockey.js +++ b/examples/example/games/airHockey.js @@ -75,7 +75,7 @@ var names = ['floor', 'table', 'paddle', 'edge', 'puck', 'hockeyLight']; var deleteButton = Overlays.addOverlay("image", { x: screenSize.x / 2 - BUTTON_SIZE, - y: screenSize.y - (BUTTON_SIZE + PADDING), + y: screenSize.y - (BUTTON_SIZE * 2 + PADDING), width: BUTTON_SIZE, height: BUTTON_SIZE, imageURL: HIFI_PUBLIC_BUCKET + "images/delete.png", @@ -89,10 +89,10 @@ var deleteButton = Overlays.addOverlay("image", { var spawnButton = Overlays.addOverlay("image", { x: screenSize.x / 2 + PADDING, - y: screenSize.y - (BUTTON_SIZE + PADDING), + y: screenSize.y - (BUTTON_SIZE * 2 + PADDING), width: BUTTON_SIZE, height: BUTTON_SIZE, - imageURL: HIFI_PUBLIC_BUCKET + "images/die.png", + imageURL: HIFI_PUBLIC_BUCKET + "images/puck.png", color: { red: 255, green: 255, From a0369d243ae89614723863aa448f44a9d1bf484b Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 15 May 2015 15:58:02 -0700 Subject: [PATCH 17/23] Update web icon --- examples/edit.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/edit.js b/examples/edit.js index e034392df0..e4297a94b3 100644 --- a/examples/edit.js +++ b/examples/edit.js @@ -207,8 +207,8 @@ var toolBar = (function () { }); newWebButton = toolBar.addTool({ - imageURL: "https://s3.amazonaws.com/Oculus/earth17.svg", - subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT }, + imageURL: "https://hifi-public.s3.amazonaws.com/images/www.svg", + subImage: { x: 0, y: 0, width: 128, height: 128 }, width: toolWidth, height: toolHeight, alpha: 0.9, From c220435364c8ea3bc69e3cb7ff10d79cbd90353e Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Sat, 16 May 2015 04:01:08 +0200 Subject: [PATCH 18/23] Restore gl* calls but record them with batch --- libraries/render-utils/src/GeometryCache.cpp | 159 +++++++++---------- 1 file changed, 76 insertions(+), 83 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index a62eadac45..574b58e23b 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -59,12 +59,6 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm gpu::Batch batch; renderSphere(batch, radius, slices, stacks, color, solid, id); gpu::GLBackend::renderBatch(batch); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } void GeometryCache::renderSphere(gpu::Batch& batch, float radius, int slices, int stacks, const glm::vec4& color, bool solid, int id) { @@ -302,6 +296,12 @@ void GeometryCache::renderSphere(gpu::Batch& batch, float radius, int slices, in } else { batch.drawIndexed(gpu::LINES, indices); } + + batch._glDisableClientState(GL_VERTEX_ARRAY); + batch._glDisableClientState(GL_COLOR_ARRAY); + + batch._glBindBuffer(GL_ARRAY_BUFFER, 0); + batch._glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } void GeometryCache::renderCone(float base, float height, int slices, int stacks) { @@ -409,11 +409,6 @@ void GeometryCache::renderGrid(int xDivisions, int yDivisions, const glm::vec4& gpu::Batch batch; renderGrid(batch, xDivisions, yDivisions, color); gpu::GLBackend::renderBatch(batch); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - - glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderGrid(gpu::Batch& batch, int xDivisions, int yDivisions, const glm::vec4& color) { @@ -488,17 +483,17 @@ void GeometryCache::renderGrid(gpu::Batch& batch, int xDivisions, int yDivisions batch.setInputBuffer(VERTICES_SLOT, verticesView); batch.setInputBuffer(COLOR_SLOT, colorView); batch.draw(gpu::LINES, vertices, 0); + + batch._glDisableClientState(GL_VERTEX_ARRAY); + batch._glDisableClientState(GL_COLOR_ARRAY); + + batch._glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderGrid(int x, int y, int width, int height, int rows, int cols, const glm::vec4& color, int id) { gpu::Batch batch; renderGrid(x, y, width, height, rows, cols, color, id); gpu::GLBackend::renderBatch(batch); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - - glBindBuffer(GL_ARRAY_BUFFER, 0); } // TODO: properly handle the x,y,w,h changing for an ID @@ -600,6 +595,11 @@ void GeometryCache::renderGrid(gpu::Batch& batch, int x, int y, int width, int h batch.setInputBuffer(VERTICES_SLOT, verticesView); batch.setInputBuffer(COLOR_SLOT, colorView); batch.draw(gpu::LINES, vertices, 0); + + batch._glDisableClientState(GL_VERTEX_ARRAY); + batch._glDisableClientState(GL_COLOR_ARRAY); + + batch._glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::updateVertices(int id, const QVector& points, const glm::vec4& color) { @@ -801,11 +801,6 @@ void GeometryCache::renderVertices(gpu::Primitive primitiveType, int id) { gpu::Batch batch; renderVertices(batch, primitiveType, id); gpu::GLBackend::renderBatch(batch); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - - glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderVertices(gpu::Batch& batch, gpu::Primitive primitiveType, int id) { @@ -814,6 +809,11 @@ void GeometryCache::renderVertices(gpu::Batch& batch, gpu::Primitive primitiveTy batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(primitiveType, details.vertices, 0); + + batch._glDisableClientState(GL_VERTEX_ARRAY); + batch._glDisableClientState(GL_COLOR_ARRAY); + + batch._glBindBuffer(GL_ARRAY_BUFFER, 0); } } @@ -821,12 +821,6 @@ void GeometryCache::renderSolidCube(float size, const glm::vec4& color) { gpu::Batch batch; renderSolidCube(batch, size, color); gpu::GLBackend::renderBatch(batch); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } void GeometryCache::renderSolidCube(gpu::Batch& batch, float size, const glm::vec4& color) { @@ -941,18 +935,18 @@ void GeometryCache::renderSolidCube(gpu::Batch& batch, float size, const glm::ve batch.setInputBuffer(COLOR_SLOT, colorView); batch.setIndexBuffer(gpu::UINT8, _solidCubeIndexBuffer, 0); batch.drawIndexed(gpu::TRIANGLES, indices); + + batch._glDisableClientState(GL_VERTEX_ARRAY); + batch._glDisableClientState(GL_COLOR_ARRAY); + + batch._glBindBuffer(GL_ARRAY_BUFFER, 0); + batch._glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } void GeometryCache::renderWireCube(float size, const glm::vec4& color) { gpu::Batch batch; renderWireCube(batch, size, color); gpu::GLBackend::renderBatch(batch); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } void GeometryCache::renderWireCube(gpu::Batch& batch, float size, const glm::vec4& color) { @@ -1030,17 +1024,18 @@ void GeometryCache::renderWireCube(gpu::Batch& batch, float size, const glm::vec batch.setInputBuffer(COLOR_SLOT, colorView); batch.setIndexBuffer(gpu::UINT8, _wireCubeIndexBuffer, 0); batch.drawIndexed(gpu::LINES, indices); + + batch._glDisableClientState(GL_VERTEX_ARRAY); + batch._glDisableClientState(GL_COLOR_ARRAY); + + batch._glBindBuffer(GL_ARRAY_BUFFER, 0); + batch._glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } void GeometryCache::renderBevelCornersRect(int x, int y, int width, int height, int bevelDistance, const glm::vec4& color, int id) { gpu::Batch batch; renderBevelCornersRect(batch, x, y, width, height, bevelDistance, color, id); gpu::GLBackend::renderBatch(batch); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - - glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderBevelCornersRect(gpu::Batch& batch, int x, int y, int width, int height, int bevelDistance, const glm::vec4& color, int id) { @@ -1139,17 +1134,17 @@ void GeometryCache::renderBevelCornersRect(gpu::Batch& batch, int x, int y, int batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(gpu::QUADS, 4, 0); + + batch._glDisableClientState(GL_VERTEX_ARRAY); + batch._glDisableClientState(GL_COLOR_ARRAY); + + batch._glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, const glm::vec4& color, int id) { gpu::Batch batch; renderQuad(batch, minCorner, maxCorner, color, id); gpu::GLBackend::renderBatch(batch); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - - glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec2& minCorner, const glm::vec2& maxCorner, const glm::vec4& color, int id) { @@ -1221,6 +1216,11 @@ void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec2& minCorner, co batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(gpu::QUADS, 4, 0); + + batch._glDisableClientState(GL_VERTEX_ARRAY); + batch._glDisableClientState(GL_COLOR_ARRAY); + + batch._glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, @@ -1229,12 +1229,6 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC gpu::Batch batch; renderQuad(batch, minCorner, maxCorner, texCoordMinCorner, texCoordMaxCorner, color, id); gpu::GLBackend::renderBatch(batch); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - - glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec2& minCorner, const glm::vec2& maxCorner, @@ -1315,17 +1309,18 @@ void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec2& minCorner, co batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(gpu::QUADS, 4, 0); + + batch._glDisableClientState(GL_VERTEX_ARRAY); + batch._glDisableClientState(GL_TEXTURE_COORD_ARRAY); + batch._glDisableClientState(GL_COLOR_ARRAY); + + batch._glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderQuad(const glm::vec3& minCorner, const glm::vec3& maxCorner, const glm::vec4& color, int id) { gpu::Batch batch; renderQuad(batch, minCorner, maxCorner, color, id); gpu::GLBackend::renderBatch(batch); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - - glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec3& minCorner, const glm::vec3& maxCorner, const glm::vec4& color, int id) { @@ -1397,6 +1392,11 @@ void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec3& minCorner, co batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(gpu::QUADS, 4, 0); + + batch._glDisableClientState(GL_VERTEX_ARRAY); + batch._glDisableClientState(GL_COLOR_ARRAY); + + batch._glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomLeft, @@ -1407,16 +1407,7 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom gpu::Batch batch; renderQuad(batch, topLeft, bottomLeft, bottomRight, topRight, texCoordTopLeft, texCoordBottomLeft, texCoordBottomRight, texCoordTopRight, color, id); - - glEnable(GL_TEXTURE_2D); - gpu::GLBackend::renderBatch(batch); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - - glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec3& topLeft, const glm::vec3& bottomLeft, @@ -1506,29 +1497,24 @@ void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec3& topLeft, cons details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Byte*) vertexBuffer); details.colorBuffer->append(sizeof(colors), (gpu::Byte*) colors); } - - //glBindTexture(GL_TEXTURE_2D, _currentTextureID); // this is quad specific... + + batch._glEnable(GL_TEXTURE_2D); batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(gpu::QUADS, 4, 0); - // TODO: The callers of this method (renderMagnifier and renderReticle) assume that we won't disable an unbind - // the texture after rendering. I'm not sure if this is correct in general but it's currently required for the - // oculus overlay to work. - //glBindTexture(GL_TEXTURE_2D, 0); - //glDisable(GL_TEXTURE_2D); + batch._glDisableClientState(GL_VERTEX_ARRAY); + batch._glDisableClientState(GL_TEXTURE_COORD_ARRAY); + batch._glDisableClientState(GL_COLOR_ARRAY); + + batch._glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& end, const glm::vec4& color, int id) { gpu::Batch batch; renderDashedLine(batch, start, end, color, id); gpu::GLBackend::renderBatch(batch); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - - glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderDashedLine(gpu::Batch& batch, const glm::vec3& start, const glm::vec3& end, const glm::vec4& color, int id) { @@ -1634,6 +1620,11 @@ void GeometryCache::renderDashedLine(gpu::Batch& batch, const glm::vec3& start, batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(gpu::LINES, details.vertices, 0); + + batch._glDisableClientState(GL_VERTEX_ARRAY); + batch._glDisableClientState(GL_COLOR_ARRAY); + + batch._glBindBuffer(GL_ARRAY_BUFFER, 0); } @@ -1690,10 +1681,6 @@ void GeometryCache::renderLine(const glm::vec3& p1, const glm::vec3& p2, gpu::Batch batch; renderLine(batch, p1, p2, color1, color2, id); gpu::GLBackend::renderBatch(batch); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderLine(gpu::Batch& batch, const glm::vec3& p1, const glm::vec3& p2, @@ -1778,16 +1765,17 @@ void GeometryCache::renderLine(gpu::Batch& batch, const glm::vec3& p1, const glm batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(gpu::LINES, 2, 0); + + batch._glDisableClientState(GL_VERTEX_ARRAY); + batch._glDisableClientState(GL_COLOR_ARRAY); + + batch._glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderLine(const glm::vec2& p1, const glm::vec2& p2, const glm::vec4& color1, const glm::vec4& color2, int id) { gpu::Batch batch; renderLine(batch, p1, p2, color1, color2, id); gpu::GLBackend::renderBatch(batch); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderLine(gpu::Batch& batch, const glm::vec2& p1, const glm::vec2& p2, @@ -1872,6 +1860,11 @@ void GeometryCache::renderLine(gpu::Batch& batch, const glm::vec2& p1, const glm batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(gpu::LINES, 2, 0); + + batch._glDisableClientState(GL_VERTEX_ARRAY); + batch._glDisableClientState(GL_COLOR_ARRAY); + + batch._glBindBuffer(GL_ARRAY_BUFFER, 0); } From b11525debf90cc5395aee9df5e3bb17d87eb72ba Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Sat, 16 May 2015 04:03:46 +0200 Subject: [PATCH 19/23] Add missing batch args --- libraries/render-utils/src/DeferredLightingEffect.cpp | 8 ++++---- libraries/render-utils/src/GeometryCache.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index fa9f1aaa21..3940ccf05b 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -113,7 +113,7 @@ void DeferredLightingEffect::renderSolidSphere(float radius, int slices, int sta void DeferredLightingEffect::renderSolidSphere(gpu::Batch& batch, float radius, int slices, int stacks, const glm::vec4& color) { bindSimpleProgram(); - DependencyManager::get()->renderSphere(radius, slices, stacks, color); + DependencyManager::get()->renderSphere(batch, radius, slices, stacks, color); releaseSimpleProgram(); } @@ -137,7 +137,7 @@ void DeferredLightingEffect::renderSolidCube(float size, const glm::vec4& color) void DeferredLightingEffect::renderSolidCube(gpu::Batch& batch, float size, const glm::vec4& color) { bindSimpleProgram(); - DependencyManager::get()->renderSolidCube(size, color); + DependencyManager::get()->renderSolidCube(batch, size, color); releaseSimpleProgram(); } @@ -149,7 +149,7 @@ void DeferredLightingEffect::renderWireCube(float size, const glm::vec4& color) void DeferredLightingEffect::renderWireCube(gpu::Batch& batch, float size, const glm::vec4& color) { bindSimpleProgram(); - DependencyManager::get()->renderWireCube(size, color); + DependencyManager::get()->renderWireCube(batch, size, color); releaseSimpleProgram(); } @@ -163,7 +163,7 @@ void DeferredLightingEffect::renderLine(const glm::vec3& p1, const glm::vec3& p2 void DeferredLightingEffect::renderLine(gpu::Batch& batch, const glm::vec3& p1, const glm::vec3& p2, const glm::vec4& color1, const glm::vec4& color2) { bindSimpleProgram(); - DependencyManager::get()->renderLine(p1, p2, color1, color2); + DependencyManager::get()->renderLine(batch, p1, p2, color1, color2); releaseSimpleProgram(); } diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 574b58e23b..83301b6a6f 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -492,7 +492,7 @@ void GeometryCache::renderGrid(gpu::Batch& batch, int xDivisions, int yDivisions void GeometryCache::renderGrid(int x, int y, int width, int height, int rows, int cols, const glm::vec4& color, int id) { gpu::Batch batch; - renderGrid(x, y, width, height, rows, cols, color, id); + renderGrid(batch, x, y, width, height, rows, cols, color, id); gpu::GLBackend::renderBatch(batch); } From 4bb1b1a02f5f3faed2970a2910ba9d9446e5a16a Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Sat, 16 May 2015 04:25:51 +0200 Subject: [PATCH 20/23] TextureCache::setPrimaryDrawBuffers can take a Batch --- libraries/render-utils/src/TextureCache.cpp | 8 +++++++- libraries/render-utils/src/TextureCache.h | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/libraries/render-utils/src/TextureCache.cpp b/libraries/render-utils/src/TextureCache.cpp index 2f793755d7..4eac2e29a3 100644 --- a/libraries/render-utils/src/TextureCache.cpp +++ b/libraries/render-utils/src/TextureCache.cpp @@ -247,6 +247,12 @@ GLuint TextureCache::getPrimarySpecularTextureID() { } void TextureCache::setPrimaryDrawBuffers(bool color, bool normal, bool specular) { + gpu::Batch batch; + setPrimaryDrawBuffers(batch, color, normal, specular); + gpu::GLBackend::renderBatch(batch); +} + +void TextureCache::setPrimaryDrawBuffers(gpu::Batch batch, bool color, bool normal, bool specular) { GLenum buffers[3]; int bufferCount = 0; if (color) { @@ -258,7 +264,7 @@ void TextureCache::setPrimaryDrawBuffers(bool color, bool normal, bool specular) if (specular) { buffers[bufferCount++] = GL_COLOR_ATTACHMENT2; } - glDrawBuffers(bufferCount, buffers); + batch._glDrawBuffers(bufferCount, buffers); } gpu::FramebufferPointer TextureCache::getSecondaryFramebuffer() { diff --git a/libraries/render-utils/src/TextureCache.h b/libraries/render-utils/src/TextureCache.h index 3ff184c621..5957bd7864 100644 --- a/libraries/render-utils/src/TextureCache.h +++ b/libraries/render-utils/src/TextureCache.h @@ -12,6 +12,7 @@ #ifndef hifi_TextureCache_h #define hifi_TextureCache_h +#include #include #include #include @@ -78,6 +79,7 @@ public: /// Enables or disables draw buffers on the primary framebuffer. Note: the primary framebuffer must be bound. void setPrimaryDrawBuffers(bool color, bool normal = false, bool specular = false); + void setPrimaryDrawBuffers(gpu::Batch batch, bool color, bool normal = false, bool specular = false); /// Returns a pointer to the secondary framebuffer object, used as an additional render target when performing full /// screen effects. From b8fffdb2ef93dd9d7b72754e354a354eb0d65551 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Sat, 16 May 2015 04:26:57 +0200 Subject: [PATCH 21/23] bind/releaseSimpleProgram takes Batch --- .../src/DeferredLightingEffect.cpp | 33 +++++++++++++------ .../render-utils/src/DeferredLightingEffect.h | 2 ++ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 3940ccf05b..b12fcc03a6 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -99,12 +99,25 @@ void DeferredLightingEffect::bindSimpleProgram() { glDisable(GL_BLEND); } +void DeferredLightingEffect::bindSimpleProgram(gpu::Batch& batch) { + DependencyManager::get()->setPrimaryDrawBuffers(batch, true, true, true); + batch._glUseProgram(_simpleProgram.programId()); + batch._glUniform1f(_glowIntensityLocation, DependencyManager::get()->getIntensity()); + batch._glDisable(GL_BLEND); +} + void DeferredLightingEffect::releaseSimpleProgram() { glEnable(GL_BLEND); _simpleProgram.release(); DependencyManager::get()->setPrimaryDrawBuffers(true, false, false); } +void DeferredLightingEffect::releaseSimpleProgram(gpu::Batch& batch) { + batch._glEnable(GL_BLEND); + batch._glUseProgram(0); + DependencyManager::get()->setPrimaryDrawBuffers(batch, true, false, false); +} + void DeferredLightingEffect::renderSolidSphere(float radius, int slices, int stacks, const glm::vec4& color) { gpu::Batch batch; renderSolidSphere(batch, radius, slices, stacks, color); @@ -112,9 +125,9 @@ void DeferredLightingEffect::renderSolidSphere(float radius, int slices, int sta } void DeferredLightingEffect::renderSolidSphere(gpu::Batch& batch, float radius, int slices, int stacks, const glm::vec4& color) { - bindSimpleProgram(); + bindSimpleProgram(batch); DependencyManager::get()->renderSphere(batch, radius, slices, stacks, color); - releaseSimpleProgram(); + releaseSimpleProgram(batch); } void DeferredLightingEffect::renderWireSphere(float radius, int slices, int stacks, const glm::vec4& color) { @@ -124,9 +137,9 @@ void DeferredLightingEffect::renderWireSphere(float radius, int slices, int stac } void DeferredLightingEffect::renderWireSphere(gpu::Batch& batch, float radius, int slices, int stacks, const glm::vec4& color) { - bindSimpleProgram(); + bindSimpleProgram(batch); DependencyManager::get()->renderSphere(batch, radius, slices, stacks, color, false); - releaseSimpleProgram(); + releaseSimpleProgram(batch); } void DeferredLightingEffect::renderSolidCube(float size, const glm::vec4& color) { @@ -136,9 +149,9 @@ void DeferredLightingEffect::renderSolidCube(float size, const glm::vec4& color) } void DeferredLightingEffect::renderSolidCube(gpu::Batch& batch, float size, const glm::vec4& color) { - bindSimpleProgram(); + bindSimpleProgram(batch); DependencyManager::get()->renderSolidCube(batch, size, color); - releaseSimpleProgram(); + releaseSimpleProgram(batch); } void DeferredLightingEffect::renderWireCube(float size, const glm::vec4& color) { @@ -148,9 +161,9 @@ void DeferredLightingEffect::renderWireCube(float size, const glm::vec4& color) } void DeferredLightingEffect::renderWireCube(gpu::Batch& batch, float size, const glm::vec4& color) { - bindSimpleProgram(); + bindSimpleProgram(batch); DependencyManager::get()->renderWireCube(batch, size, color); - releaseSimpleProgram(); + releaseSimpleProgram(batch); } void DeferredLightingEffect::renderLine(const glm::vec3& p1, const glm::vec3& p2, @@ -162,9 +175,9 @@ void DeferredLightingEffect::renderLine(const glm::vec3& p1, const glm::vec3& p2 void DeferredLightingEffect::renderLine(gpu::Batch& batch, const glm::vec3& p1, const glm::vec3& p2, const glm::vec4& color1, const glm::vec4& color2) { - bindSimpleProgram(); + bindSimpleProgram(batch); DependencyManager::get()->renderLine(batch, p1, p2, color1, color2); - releaseSimpleProgram(); + releaseSimpleProgram(batch); } diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index e979aeeb9c..367963b1c9 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -38,9 +38,11 @@ public: /// Sets up the state necessary to render static untextured geometry with the simple program. void bindSimpleProgram(); + void bindSimpleProgram(gpu::Batch& batch); /// Tears down the state necessary to render static untextured geometry with the simple program. void releaseSimpleProgram(); + void releaseSimpleProgram(gpu::Batch& batch); //// Renders a solid sphere with the simple program. void renderSolidSphere(float radius, int slices, int stacks, const glm::vec4& color); From 6e642ed0405055b4742322077325a705188e4973 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Sat, 16 May 2015 04:31:42 +0200 Subject: [PATCH 22/23] Missing & --- libraries/render-utils/src/TextureCache.cpp | 2 +- libraries/render-utils/src/TextureCache.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/render-utils/src/TextureCache.cpp b/libraries/render-utils/src/TextureCache.cpp index 4eac2e29a3..3b27ca7c0d 100644 --- a/libraries/render-utils/src/TextureCache.cpp +++ b/libraries/render-utils/src/TextureCache.cpp @@ -252,7 +252,7 @@ void TextureCache::setPrimaryDrawBuffers(bool color, bool normal, bool specular) gpu::GLBackend::renderBatch(batch); } -void TextureCache::setPrimaryDrawBuffers(gpu::Batch batch, bool color, bool normal, bool specular) { +void TextureCache::setPrimaryDrawBuffers(gpu::Batch& batch, bool color, bool normal, bool specular) { GLenum buffers[3]; int bufferCount = 0; if (color) { diff --git a/libraries/render-utils/src/TextureCache.h b/libraries/render-utils/src/TextureCache.h index 5957bd7864..848a0ce4d8 100644 --- a/libraries/render-utils/src/TextureCache.h +++ b/libraries/render-utils/src/TextureCache.h @@ -79,7 +79,7 @@ public: /// Enables or disables draw buffers on the primary framebuffer. Note: the primary framebuffer must be bound. void setPrimaryDrawBuffers(bool color, bool normal = false, bool specular = false); - void setPrimaryDrawBuffers(gpu::Batch batch, bool color, bool normal = false, bool specular = false); + void setPrimaryDrawBuffers(gpu::Batch& batch, bool color, bool normal = false, bool specular = false); /// Returns a pointer to the secondary framebuffer object, used as an additional render target when performing full /// screen effects. From 7185589407167d09516b86241cda14ccd3ca8395 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Sat, 16 May 2015 04:42:15 +0200 Subject: [PATCH 23/23] Add optional Batch to RenderArgs --- libraries/shared/src/RenderArgs.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libraries/shared/src/RenderArgs.h b/libraries/shared/src/RenderArgs.h index 3019535d2a..d322cd63ae 100644 --- a/libraries/shared/src/RenderArgs.h +++ b/libraries/shared/src/RenderArgs.h @@ -14,6 +14,9 @@ class ViewFrustum; class OctreeRenderer; +namespace gpu { +class Batch; +} class RenderArgs { public: @@ -34,6 +37,7 @@ public: RenderMode renderMode = DEFAULT_RENDER_MODE, RenderSide renderSide = MONO, DebugFlags debugFlags = RENDER_DEBUG_NONE, + gpu::Batch* batch = nullptr, int elementsTouched = 0, int itemsRendered = 0, @@ -58,6 +62,7 @@ public: _renderMode(renderMode), _renderSide(renderSide), _debugFlags(debugFlags), + _batch(batch), _elementsTouched(elementsTouched), _itemsRendered(itemsRendered), @@ -84,6 +89,7 @@ public: RenderMode _renderMode; RenderSide _renderSide; DebugFlags _debugFlags; + gpu::Batch* _batch; int _elementsTouched; int _itemsRendered;