From 738369e21f04adb8e265345a4890e686db935c67 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Fri, 3 Oct 2014 16:55:58 -0700 Subject: [PATCH] Replacing glutSolidSphere by a cached Geometry Instead of calling glutSolidSphere, just call Application::getInstance()->getGeometryCache()->renderSphere(...) - replaced all the instances of "glutSolidSphere" - Changed the atmosphere shaders so instead of drawing a sphere of the size of the atmosphere, we draw a unit sphere, the vertices get scaled at the right radius in th vertex shader using fOuterRadius --- CMakeLists.txt | 2 +- .../resources/web/assignment/js/ace/ace.js | 0 .../web/assignment/js/ace/mode-javascript.js | 0 .../assignment/js/ace/snippets/javascript.js | 0 .../web/assignment/js/ace/theme-twilight.js | 0 .../assignment/js/ace/worker-javascript.js | 0 domain-server/resources/web/js/form2js.min.js | 0 examples/move.js | 0 .../resources/shaders/SkyFromAtmosphere.vert | 6 +- interface/resources/shaders/SkyFromSpace.vert | 6 +- interface/src/Application.cpp | 14 ++- interface/src/BuckyBalls.cpp | 3 +- interface/src/Environment.cpp | 2 +- interface/src/Menu.cpp | 2 +- interface/src/MetavoxelSystem.cpp | 2 +- interface/src/Stars.cpp | 0 interface/src/Stars.h | 0 interface/src/Util.cpp | 15 +-- interface/src/avatar/Avatar.cpp | 7 +- interface/src/avatar/Avatar.h | 0 interface/src/avatar/Hand.cpp | 4 +- interface/src/avatar/Hand.h | 0 interface/src/avatar/MyAvatar.cpp | 4 +- interface/src/avatar/SkeletonModel.cpp | 18 +-- .../src/renderer/DeferredLightingEffect.cpp | 2 +- interface/src/renderer/GeometryCache.cpp | 105 ++++++++++++++++++ interface/src/renderer/GeometryCache.h | 2 + interface/src/starfield/Config.h | 0 interface/src/starfield/Controller.cpp | 0 interface/src/starfield/Controller.h | 0 interface/src/starfield/data/GpuVertex.cpp | 0 interface/src/starfield/data/GpuVertex.h | 0 interface/src/starfield/data/InputVertex.cpp | 0 interface/src/starfield/data/InputVertex.h | 0 interface/src/starfield/data/Tile.h | 0 interface/src/starfield/renderer/Renderer.cpp | 0 interface/src/starfield/renderer/Renderer.h | 0 interface/src/starfield/renderer/Tiling.h | 0 .../src/starfield/renderer/VertexOrder.cpp | 0 .../src/starfield/renderer/VertexOrder.h | 0 interface/src/ui/MetavoxelEditor.cpp | 2 +- interface/src/ui/overlays/Sphere3DOverlay.cpp | 3 +- libraries/avatars/src/AvatarData.h | 0 libraries/avatars/src/HandData.h | 0 .../embedded-webserver/src/HTTPConnection.cpp | 0 .../embedded-webserver/src/HTTPManager.cpp | 0 .../embedded-webserver/src/HTTPManager.h | 0 libraries/octree/src/Plane.cpp | 0 libraries/octree/src/Plane.h | 0 tools/samples/cube1.hio | Bin tools/samples/oneRedVoxel.hio | Bin tools/samples/single.hio | Bin 52 files changed, 158 insertions(+), 41 deletions(-) mode change 100755 => 100644 domain-server/resources/web/assignment/js/ace/ace.js mode change 100755 => 100644 domain-server/resources/web/assignment/js/ace/mode-javascript.js mode change 100755 => 100644 domain-server/resources/web/assignment/js/ace/snippets/javascript.js mode change 100755 => 100644 domain-server/resources/web/assignment/js/ace/theme-twilight.js mode change 100755 => 100644 domain-server/resources/web/assignment/js/ace/worker-javascript.js mode change 100755 => 100644 domain-server/resources/web/js/form2js.min.js mode change 100755 => 100644 examples/move.js mode change 100755 => 100644 interface/src/Stars.cpp mode change 100755 => 100644 interface/src/Stars.h mode change 100755 => 100644 interface/src/avatar/Avatar.h mode change 100755 => 100644 interface/src/avatar/Hand.h mode change 100755 => 100644 interface/src/starfield/Config.h mode change 100755 => 100644 interface/src/starfield/Controller.cpp mode change 100755 => 100644 interface/src/starfield/Controller.h mode change 100755 => 100644 interface/src/starfield/data/GpuVertex.cpp mode change 100755 => 100644 interface/src/starfield/data/GpuVertex.h mode change 100755 => 100644 interface/src/starfield/data/InputVertex.cpp mode change 100755 => 100644 interface/src/starfield/data/InputVertex.h mode change 100755 => 100644 interface/src/starfield/data/Tile.h mode change 100755 => 100644 interface/src/starfield/renderer/Renderer.cpp mode change 100755 => 100644 interface/src/starfield/renderer/Renderer.h mode change 100755 => 100644 interface/src/starfield/renderer/Tiling.h mode change 100755 => 100644 interface/src/starfield/renderer/VertexOrder.cpp mode change 100755 => 100644 interface/src/starfield/renderer/VertexOrder.h mode change 100755 => 100644 libraries/avatars/src/AvatarData.h mode change 100755 => 100644 libraries/avatars/src/HandData.h mode change 100755 => 100644 libraries/embedded-webserver/src/HTTPConnection.cpp mode change 100755 => 100644 libraries/embedded-webserver/src/HTTPManager.cpp mode change 100755 => 100644 libraries/embedded-webserver/src/HTTPManager.h mode change 100755 => 100644 libraries/octree/src/Plane.cpp mode change 100755 => 100644 libraries/octree/src/Plane.h mode change 100755 => 100644 tools/samples/cube1.hio mode change 100755 => 100644 tools/samples/oneRedVoxel.hio mode change 100755 => 100644 tools/samples/single.hio diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c0bfb0892..5f245884fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ if (WIN32) # set path for Microsoft SDKs # if get build error about missing 'glu32' this path is likely wrong # Uncomment the line with 8.1 if running Windows 8.1 - #set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "C:\\Program Files (x86)\\Windows Kits\\8.1\\Lib\\winv6.3\\um\\x86") + set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "C:\\Program Files (x86)\\Windows Kits\\8.1\\Lib\\winv6.3\\um\\x86") set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1 ") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") elseif (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) diff --git a/domain-server/resources/web/assignment/js/ace/ace.js b/domain-server/resources/web/assignment/js/ace/ace.js old mode 100755 new mode 100644 diff --git a/domain-server/resources/web/assignment/js/ace/mode-javascript.js b/domain-server/resources/web/assignment/js/ace/mode-javascript.js old mode 100755 new mode 100644 diff --git a/domain-server/resources/web/assignment/js/ace/snippets/javascript.js b/domain-server/resources/web/assignment/js/ace/snippets/javascript.js old mode 100755 new mode 100644 diff --git a/domain-server/resources/web/assignment/js/ace/theme-twilight.js b/domain-server/resources/web/assignment/js/ace/theme-twilight.js old mode 100755 new mode 100644 diff --git a/domain-server/resources/web/assignment/js/ace/worker-javascript.js b/domain-server/resources/web/assignment/js/ace/worker-javascript.js old mode 100755 new mode 100644 diff --git a/domain-server/resources/web/js/form2js.min.js b/domain-server/resources/web/js/form2js.min.js old mode 100755 new mode 100644 diff --git a/examples/move.js b/examples/move.js old mode 100755 new mode 100644 diff --git a/interface/resources/shaders/SkyFromAtmosphere.vert b/interface/resources/shaders/SkyFromAtmosphere.vert index 31c1ea958a..e04868de1d 100644 --- a/interface/resources/shaders/SkyFromAtmosphere.vert +++ b/interface/resources/shaders/SkyFromAtmosphere.vert @@ -35,6 +35,7 @@ uniform vec3 v3CameraPos; // The camera's current position uniform vec3 v3LightPos; // The direction vector to the light source uniform vec3 v3InvWavelength; // 1 / pow(wavelength, 4) for the red, green, and blue channels +uniform float fOuterRadius; // The outer (atmosphere) radius uniform float fInnerRadius; // The inner (planetary) radius uniform float fKrESun; // Kr * ESun uniform float fKmESun; // Km * ESun @@ -44,6 +45,7 @@ uniform float fScale; // 1 / (fOuterRadius - fInnerRadius) uniform float fScaleDepth; // The scale depth (i.e. the altitude at which the atmosphere's average density is found) uniform float fScaleOverScaleDepth; // fScale / fScaleDepth + const int nSamples = 2; const float fSamples = 2.0; @@ -59,7 +61,7 @@ float scale(float fCos) void main(void) { // Get the ray from the camera to the vertex, and its length (which is the far point of the ray passing through the atmosphere) - position = gl_Vertex.xyz; + position = gl_Vertex.xyz * fOuterRadius; - gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; + gl_Position = gl_ModelViewProjectionMatrix * vec4(position, 1.0); } diff --git a/interface/resources/shaders/SkyFromSpace.vert b/interface/resources/shaders/SkyFromSpace.vert index 0c06c90cf8..6740d1909e 100644 --- a/interface/resources/shaders/SkyFromSpace.vert +++ b/interface/resources/shaders/SkyFromSpace.vert @@ -32,10 +32,12 @@ // Copyright (c) 2004 Sean O'Neil // +uniform float fOuterRadius; // The outer (atmosphere) radius + varying vec3 position; void main(void) { - position = gl_Vertex.xyz; - gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; + position = gl_Vertex.xyz * fOuterRadius; + gl_Position = gl_ModelViewProjectionMatrix * vec4(position, 1.0); } diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index ec40056299..d5cf14f8ce 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -876,8 +876,12 @@ void Application::keyPressEvent(QKeyEvent* event) { break; case Qt::Key_W: - _myAvatar->setDriveKeys(FWD, 1.f); - break; + if (isOption && !isShifted && !isMeta) { + Menu::getInstance()->triggerOption(MenuOption::Wireframe); + } else { + _myAvatar->setDriveKeys(FWD, 1.f); + } + break; case Qt::Key_S: if (isShifted && isMeta && !isOption) { @@ -2886,10 +2890,8 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) { // draw a red sphere float originSphereRadius = 0.05f; glColor3f(1,0,0); - glPushMatrix(); - glutSolidSphere(originSphereRadius, 15, 15); - glPopMatrix(); - + _geometryCache.renderSphere(originSphereRadius, 15, 15); + // draw the audio reflector overlay { PerformanceTimer perfTimer("audio"); diff --git a/interface/src/BuckyBalls.cpp b/interface/src/BuckyBalls.cpp index 1bc093283a..893e74f083 100644 --- a/interface/src/BuckyBalls.cpp +++ b/interface/src/BuckyBalls.cpp @@ -11,6 +11,7 @@ #include "BuckyBalls.h" +#include "Application.h" #include "Util.h" #include "world.h" #include "devices/SixenseManager.h" @@ -171,7 +172,7 @@ void BuckyBalls::render() { } glPushMatrix(); glTranslatef(_bballPosition[i].x, _bballPosition[i].y, _bballPosition[i].z); - glutSolidSphere(_bballRadius[i], 15, 15); + Application::getInstance()->getGeometryCache()->renderSphere(_bballRadius[i], 15, 15); glPopMatrix(); } } diff --git a/interface/src/Environment.cpp b/interface/src/Environment.cpp index 67337f963c..6eae464957 100644 --- a/interface/src/Environment.cpp +++ b/interface/src/Environment.cpp @@ -261,7 +261,7 @@ void Environment::renderAtmosphere(Camera& camera, const EnvironmentData& data) glDepthMask(GL_FALSE); glDisable(GL_DEPTH_TEST); - glutSolidSphere(data.getAtmosphereOuterRadius(), 100, 50); + Application::getInstance()->getGeometryCache()->renderSphere(1.f, 100, 50); //Draw a unit sphere glDepthMask(GL_TRUE); program->release(); diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 94af1ad80a..d24c837f73 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -385,7 +385,7 @@ Menu::Menu() : 0, appInstance->getGlowEffect(), SLOT(cycleRenderMode())); - addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Wireframe, 0, false); + addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Wireframe, Qt::ALT | Qt::Key_W, false); addActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::LodTools, Qt::SHIFT | Qt::Key_L, this, SLOT(lodTools())); QMenu* avatarDebugMenu = developerMenu->addMenu("Avatar"); diff --git a/interface/src/MetavoxelSystem.cpp b/interface/src/MetavoxelSystem.cpp index ae82e57017..4662fdafa6 100644 --- a/interface/src/MetavoxelSystem.cpp +++ b/interface/src/MetavoxelSystem.cpp @@ -2339,7 +2339,7 @@ void SphereRenderer::renderUnclipped(float alpha, Mode mode) { glm::vec3 axis = glm::axis(rotation); glRotatef(glm::angle(rotation), axis.x, axis.y, axis.z); - glutSolidSphere(sphere->getScale(), 10, 10); + Application::getInstance()->getGeometryCache()->renderSphere(sphere->getScale(), 10, 10); glPopMatrix(); } diff --git a/interface/src/Stars.cpp b/interface/src/Stars.cpp old mode 100755 new mode 100644 diff --git a/interface/src/Stars.h b/interface/src/Stars.h old mode 100755 new mode 100644 diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index b219509ccd..9d7f5518d0 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -27,6 +27,7 @@ #include "ui/TextRenderer.h" #include "VoxelConstants.h" #include "world.h" +#include "Application.h" #include "Util.h" @@ -112,13 +113,13 @@ void drawVector(glm::vec3 * vector) { glPushMatrix(); glColor3f(1,0,0); glTranslatef(vector->x, 0, 0); - glutSolidSphere(0.02, 10, 10); + Application::getInstance()->getGeometryCache()->renderSphere(0.02f, 10, 10); glColor3f(0,1,0); glTranslatef(-vector->x, vector->y, 0); - glutSolidSphere(0.02, 10, 10); + Application::getInstance()->getGeometryCache()->renderSphere(0.02f, 10, 10); glColor3f(0,0,1); glTranslatef(0, -vector->y, vector->z); - glutSolidSphere(0.02, 10, 10); + Application::getInstance()->getGeometryCache()->renderSphere(0.02f, 10, 10); glPopMatrix(); } @@ -155,22 +156,22 @@ void renderWorldBox() { glPushMatrix(); glTranslatef(MARKER_DISTANCE, 0, 0); glColor3fv(red); - glutSolidSphere(MARKER_RADIUS, 10, 10); + Application::getInstance()->getGeometryCache()->renderSphere(MARKER_RADIUS, 10, 10); glPopMatrix(); glPushMatrix(); glTranslatef(0, MARKER_DISTANCE, 0); glColor3fv(green); - glutSolidSphere(MARKER_RADIUS, 10, 10); + Application::getInstance()->getGeometryCache()->renderSphere(MARKER_RADIUS, 10, 10); glPopMatrix(); glPushMatrix(); glTranslatef(0, 0, MARKER_DISTANCE); glColor3fv(blue); - glutSolidSphere(MARKER_RADIUS, 10, 10); + Application::getInstance()->getGeometryCache()->renderSphere(MARKER_RADIUS, 10, 10); glPopMatrix(); glPushMatrix(); glColor3fv(gray); glTranslatef(MARKER_DISTANCE, 0, MARKER_DISTANCE); - glutSolidSphere(MARKER_RADIUS, 10, 10); + Application::getInstance()->getGeometryCache()->renderSphere(MARKER_RADIUS, 10, 10); glPopMatrix(); } diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 2b72fe2c23..cd76550b59 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -399,8 +399,8 @@ void Avatar::render(const glm::vec3& cameraPosition, RenderMode renderMode, bool } else { glTranslatef(_position.x, getDisplayNamePosition().y + LOOK_AT_INDICATOR_OFFSET, _position.z); } - glutSolidSphere(LOOK_AT_INDICATOR_RADIUS, 15, 15); - glPopMatrix(); + Application::getInstance()->getGeometryCache()->renderSphere(LOOK_AT_INDICATOR_RADIUS, 15, 15); + glPopMatrix(); } } @@ -427,7 +427,8 @@ void Avatar::render(const glm::vec3& cameraPosition, RenderMode renderMode, bool glPushMatrix(); glTranslatef(_position.x, _position.y, _position.z); glScalef(height, height, height); - glutSolidSphere(sphereRadius, 15, 15); + Application::getInstance()->getGeometryCache()->renderSphere(sphereRadius, 15, 15); + glPopMatrix(); } } diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h old mode 100755 new mode 100644 diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index 5ef1fbafea..9bddcd1730 100644 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -114,7 +114,7 @@ void Hand::render(bool isMine, Model::RenderMode renderMode) { glPushMatrix(); glTranslatef(position.x, position.y, position.z); glColor3f(0.0f, 1.0f, 0.0f); - glutSolidSphere(PALM_COLLISION_RADIUS * _owningAvatar->getScale(), 10, 10); + Application::getInstance()->getGeometryCache()->renderSphere(PALM_COLLISION_RADIUS * _owningAvatar->getScale(), 10, 10); glPopMatrix(); } } @@ -179,7 +179,7 @@ void Hand::renderHandTargets(bool isMine) { Avatar::renderJointConnectingCone(root, offsetFromPalm, PALM_DISK_RADIUS, 0.0f); glPushMatrix(); glTranslatef(root.x, root.y, root.z); - glutSolidSphere(PALM_BALL_RADIUS, 20.0f, 20.0f); + Application::getInstance()->getGeometryCache()->renderSphere(PALM_BALL_RADIUS, 20.0f, 20.0f); glPopMatrix(); } } diff --git a/interface/src/avatar/Hand.h b/interface/src/avatar/Hand.h old mode 100755 new mode 100644 diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index f7aa8a2bd6..83ff284887 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -399,7 +399,7 @@ void MyAvatar::renderDebugBodyPoints() { glPushMatrix(); glColor4f(0, 1, 0, .5f); glTranslatef(position.x, position.y, position.z); - glutSolidSphere(0.2, 10, 10); + Application::getInstance()->getGeometryCache()->renderSphere(0.2, 10, 10); glPopMatrix(); // Head Sphere @@ -407,7 +407,7 @@ void MyAvatar::renderDebugBodyPoints() { glPushMatrix(); glColor4f(0, 1, 0, .5f); glTranslatef(position.x, position.y, position.z); - glutSolidSphere(0.15, 10, 10); + Application::getInstance()->getGeometryCache()->renderSphere(0.15, 10, 10); glPopMatrix(); } diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index a1fccf1a10..61bee4b4c5 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -554,9 +554,9 @@ void SkeletonModel::renderRagdoll() { glTranslatef(position.x, position.y, position.z); // draw each point as a yellow hexagon with black border glColor4f(0.0f, 0.0f, 0.0f, alpha); - glutSolidSphere(radius2, BALL_SUBDIVISIONS, BALL_SUBDIVISIONS); + Application::getInstance()->getGeometryCache()->renderSphere(radius2, BALL_SUBDIVISIONS, BALL_SUBDIVISIONS); glColor4f(1.0f, 1.0f, 0.0f, alpha); - glutSolidSphere(radius1, BALL_SUBDIVISIONS, BALL_SUBDIVISIONS); + Application::getInstance()->getGeometryCache()->renderSphere(radius1, BALL_SUBDIVISIONS, BALL_SUBDIVISIONS); glPopMatrix(); } glPopMatrix(); @@ -847,7 +847,7 @@ void SkeletonModel::renderBoundingCollisionShapes(float alpha) { endPoint = endPoint - _translation; glTranslatef(endPoint.x, endPoint.y, endPoint.z); glColor4f(0.6f, 0.6f, 0.8f, alpha); - glutSolidSphere(_boundingShape.getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS); + Application::getInstance()->getGeometryCache()->renderSphere(_boundingShape.getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS); // draw a yellow sphere at the capsule startpoint glm::vec3 startPoint; @@ -856,7 +856,7 @@ void SkeletonModel::renderBoundingCollisionShapes(float alpha) { glm::vec3 axis = endPoint - startPoint; glTranslatef(-axis.x, -axis.y, -axis.z); glColor4f(0.8f, 0.8f, 0.6f, alpha); - glutSolidSphere(_boundingShape.getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS); + Application::getInstance()->getGeometryCache()->renderSphere(_boundingShape.getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS); // draw a green cylinder between the two points glm::vec3 origin(0.0f); @@ -889,7 +889,7 @@ void SkeletonModel::renderJointCollisionShapes(float alpha) { glTranslatef(position.x, position.y, position.z); // draw a grey sphere at shape position glColor4f(0.75f, 0.75f, 0.75f, alpha); - glutSolidSphere(shape->getBoundingRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS); + Application::getInstance()->getGeometryCache()->renderSphere(shape->getBoundingRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS); } else if (shape->getType() == CAPSULE_SHAPE) { CapsuleShape* capsule = static_cast(shape); @@ -898,8 +898,8 @@ void SkeletonModel::renderJointCollisionShapes(float alpha) { capsule->getEndPoint(endPoint); endPoint = endPoint - simulationTranslation; glTranslatef(endPoint.x, endPoint.y, endPoint.z); - glColor4f(0.6f, 0.6f, 0.8f, alpha); - glutSolidSphere(capsule->getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS); + glColor4f(0.6f, 0.6f, 0.8f, alpha); + Application::getInstance()->getGeometryCache()->renderSphere(capsule->getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS); // draw a yellow sphere at the capsule startpoint glm::vec3 startPoint; @@ -907,8 +907,8 @@ void SkeletonModel::renderJointCollisionShapes(float alpha) { startPoint = startPoint - simulationTranslation; glm::vec3 axis = endPoint - startPoint; glTranslatef(-axis.x, -axis.y, -axis.z); - glColor4f(0.8f, 0.8f, 0.6f, alpha); - glutSolidSphere(capsule->getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS); + glColor4f(0.8f, 0.8f, 0.6f, alpha); + Application::getInstance()->getGeometryCache()->renderSphere(capsule->getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS); // draw a green cylinder between the two points glm::vec3 origin(0.0f); diff --git a/interface/src/renderer/DeferredLightingEffect.cpp b/interface/src/renderer/DeferredLightingEffect.cpp index 585fa9b31c..46fb889c75 100644 --- a/interface/src/renderer/DeferredLightingEffect.cpp +++ b/interface/src/renderer/DeferredLightingEffect.cpp @@ -51,7 +51,7 @@ void DeferredLightingEffect::releaseSimpleProgram() { void DeferredLightingEffect::renderSolidSphere(float radius, int slices, int stacks) { bindSimpleProgram(); - glutSolidSphere(radius, slices, stacks); + Application::getInstance()->getGeometryCache()->renderSphere(radius, slices, stacks); releaseSimpleProgram(); } diff --git a/interface/src/renderer/GeometryCache.cpp b/interface/src/renderer/GeometryCache.cpp index 7c3c2dc1ca..1eecebcea2 100644 --- a/interface/src/renderer/GeometryCache.cpp +++ b/interface/src/renderer/GeometryCache.cpp @@ -110,6 +110,111 @@ void GeometryCache::renderHemisphere(int slices, int stacks) { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } + +void GeometryCache::renderSphere(float radius, int slices, int stacks) { + VerticesIndices& vbo = _sphereVBOs[IntPair(slices, stacks)]; + int vertices = slices * (stacks - 1) + 2; + int indices = slices * 2 * 3 * (stacks - 1) + slices * 2 * 3; + if (vbo.first == 0) { + GLfloat* vertexData = new GLfloat[vertices * 3]; + GLfloat* vertex = vertexData; + + // south pole + *(vertex++) = 0.0f; + *(vertex++) = 0.0f; + *(vertex++) = -1.0f; + + //add stacks vertices climbing up Y axis + for (int i = 1; i < stacks; i++) { + float phi = PI * (float)i / (float)(stacks) - PI_OVER_TWO; + float z = sinf(phi), radius = cosf(phi); + + for (int j = 0; j < slices; j++) { + float theta = TWO_PI * (float)j / (float)slices; + + *(vertex++) = sinf(theta) * radius; + *(vertex++) = cosf(theta) * radius; + *(vertex++) = z; + } + } + + // north pole + *(vertex++) = 0.0f; + *(vertex++) = 0.0f; + *(vertex++) = 1.0f; + + glGenBuffers(1, &vbo.first); + glBindBuffer(GL_ARRAY_BUFFER, vbo.first); + const int BYTES_PER_VERTEX = 3 * sizeof(GLfloat); + glBufferData(GL_ARRAY_BUFFER, vertices * BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW); + delete[] vertexData; + + GLushort* indexData = new GLushort[indices]; + GLushort* index = indexData; + + // South cap + GLushort bottom = 0; + GLushort top = 1; + for (int i = 0; i < slices; i++) { + *(index++) = bottom; + *(index++) = top + i; + *(index++) = top + (i + 1) % slices; + } + + // (stacks - 2) ribbons + for (int i = 0; i < stacks - 2; i++) { + bottom = i * slices + 1; + top = bottom + slices; + for (int j = 0; j < slices; j++) { + int next = (j + 1) % slices; + + *(index++) = bottom + j; + *(index++) = top + next; + *(index++) = top + j; + + *(index++) = bottom + j; + *(index++) = bottom + next; + *(index++) = top + next; + } + } + + // north cap + bottom = (stacks - 2) * slices + 1; + top = bottom + slices; + for (int i = 0; i < slices; i++) { + *(index++) = bottom + i; + *(index++) = bottom + (i + 1) % slices; + *(index++) = top; + } + + glGenBuffers(1, &vbo.second); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); + const int BYTES_PER_INDEX = sizeof(GLushort); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); + delete[] indexData; + + } else { + glBindBuffer(GL_ARRAY_BUFFER, vbo.first); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); + } + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_NORMAL_ARRAY); + + glVertexPointer(3, GL_FLOAT, 0, 0); + glNormalPointer(GL_FLOAT, 0, 0); + + glPushMatrix(); + glScalef(radius, radius, radius); + glDrawRangeElementsEXT(GL_TRIANGLES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); + glPopMatrix(); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_NORMAL_ARRAY); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); +} + void GeometryCache::renderSquare(int xDivisions, int yDivisions) { VerticesIndices& vbo = _squareVBOs[IntPair(xDivisions, yDivisions)]; int xVertices = xDivisions + 1; diff --git a/interface/src/renderer/GeometryCache.h b/interface/src/renderer/GeometryCache.h index 647e0592fd..e0ada10e5b 100644 --- a/interface/src/renderer/GeometryCache.h +++ b/interface/src/renderer/GeometryCache.h @@ -39,6 +39,7 @@ public: virtual ~GeometryCache(); void renderHemisphere(int slices, int stacks); + void renderSphere(float radius, int slices, int stacks); void renderSquare(int xDivisions, int yDivisions); void renderHalfCylinder(int slices, int stacks); void renderGrid(int xDivisions, int yDivisions); @@ -67,6 +68,7 @@ private: typedef QPair VerticesIndices; QHash _hemisphereVBOs; + QHash _sphereVBOs; QHash _squareVBOs; QHash _halfCylinderVBOs; QHash _gridBuffers; diff --git a/interface/src/starfield/Config.h b/interface/src/starfield/Config.h old mode 100755 new mode 100644 diff --git a/interface/src/starfield/Controller.cpp b/interface/src/starfield/Controller.cpp old mode 100755 new mode 100644 diff --git a/interface/src/starfield/Controller.h b/interface/src/starfield/Controller.h old mode 100755 new mode 100644 diff --git a/interface/src/starfield/data/GpuVertex.cpp b/interface/src/starfield/data/GpuVertex.cpp old mode 100755 new mode 100644 diff --git a/interface/src/starfield/data/GpuVertex.h b/interface/src/starfield/data/GpuVertex.h old mode 100755 new mode 100644 diff --git a/interface/src/starfield/data/InputVertex.cpp b/interface/src/starfield/data/InputVertex.cpp old mode 100755 new mode 100644 diff --git a/interface/src/starfield/data/InputVertex.h b/interface/src/starfield/data/InputVertex.h old mode 100755 new mode 100644 diff --git a/interface/src/starfield/data/Tile.h b/interface/src/starfield/data/Tile.h old mode 100755 new mode 100644 diff --git a/interface/src/starfield/renderer/Renderer.cpp b/interface/src/starfield/renderer/Renderer.cpp old mode 100755 new mode 100644 diff --git a/interface/src/starfield/renderer/Renderer.h b/interface/src/starfield/renderer/Renderer.h old mode 100755 new mode 100644 diff --git a/interface/src/starfield/renderer/Tiling.h b/interface/src/starfield/renderer/Tiling.h old mode 100755 new mode 100644 diff --git a/interface/src/starfield/renderer/VertexOrder.cpp b/interface/src/starfield/renderer/VertexOrder.cpp old mode 100755 new mode 100644 diff --git a/interface/src/starfield/renderer/VertexOrder.h b/interface/src/starfield/renderer/VertexOrder.h old mode 100755 new mode 100644 diff --git a/interface/src/ui/MetavoxelEditor.cpp b/interface/src/ui/MetavoxelEditor.cpp index bb62bee9a1..7cd34ae333 100644 --- a/interface/src/ui/MetavoxelEditor.cpp +++ b/interface/src/ui/MetavoxelEditor.cpp @@ -1415,7 +1415,7 @@ void SphereTool::render() { glEnable(GL_CULL_FACE); - glutSolidSphere(_radius->value(), 10, 10); + Application::getInstance()->getGeometryCache()->renderSphere(_radius->value(), 10, 10); glDisable(GL_CULL_FACE); diff --git a/interface/src/ui/overlays/Sphere3DOverlay.cpp b/interface/src/ui/overlays/Sphere3DOverlay.cpp index c2ac92f45c..40be8007ad 100644 --- a/interface/src/ui/overlays/Sphere3DOverlay.cpp +++ b/interface/src/ui/overlays/Sphere3DOverlay.cpp @@ -15,6 +15,7 @@ #include #include "Sphere3DOverlay.h" +#include "Application.h" Sphere3DOverlay::Sphere3DOverlay() { } @@ -39,7 +40,7 @@ void Sphere3DOverlay::render() { glLineWidth(_lineWidth); const int slices = 15; if (_isSolid) { - glutSolidSphere(_size, slices, slices); + Application::getInstance()->getGeometryCache()->renderSphere(_size, slices, slices); } else { glutWireSphere(_size, slices, slices); } diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h old mode 100755 new mode 100644 diff --git a/libraries/avatars/src/HandData.h b/libraries/avatars/src/HandData.h old mode 100755 new mode 100644 diff --git a/libraries/embedded-webserver/src/HTTPConnection.cpp b/libraries/embedded-webserver/src/HTTPConnection.cpp old mode 100755 new mode 100644 diff --git a/libraries/embedded-webserver/src/HTTPManager.cpp b/libraries/embedded-webserver/src/HTTPManager.cpp old mode 100755 new mode 100644 diff --git a/libraries/embedded-webserver/src/HTTPManager.h b/libraries/embedded-webserver/src/HTTPManager.h old mode 100755 new mode 100644 diff --git a/libraries/octree/src/Plane.cpp b/libraries/octree/src/Plane.cpp old mode 100755 new mode 100644 diff --git a/libraries/octree/src/Plane.h b/libraries/octree/src/Plane.h old mode 100755 new mode 100644 diff --git a/tools/samples/cube1.hio b/tools/samples/cube1.hio old mode 100755 new mode 100644 diff --git a/tools/samples/oneRedVoxel.hio b/tools/samples/oneRedVoxel.hio old mode 100755 new mode 100644 diff --git a/tools/samples/single.hio b/tools/samples/single.hio old mode 100755 new mode 100644