From ef42203481b67d9f368dee3484f84345bd2f8960 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 17 Dec 2014 15:58:52 -0800 Subject: [PATCH 1/4] add wire cube implementation to GeometryCache and DeferredLightingEffect --- libraries/render-utils/src/DeferredLightingEffect.cpp | 2 +- libraries/render-utils/src/GeometryCache.cpp | 8 ++++++-- libraries/render-utils/src/GeometryCache.h | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 14d383418f..065ca3a741 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -68,7 +68,7 @@ void DeferredLightingEffect::renderSolidSphere(float radius, int slices, int sta void DeferredLightingEffect::renderWireSphere(float radius, int slices, int stacks) { bindSimpleProgram(); - glutWireSphere(radius, slices, stacks); + DependencyManager::get()->renderSphere(radius, slices, stacks, false); releaseSimpleProgram(); } diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 56092945a2..a770d942fe 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -119,7 +119,7 @@ const int NUM_COORDS_PER_VERTEX = 3; 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) { +void GeometryCache::renderSphere(float radius, int slices, int stacks, bool solid) { VerticesIndices& vbo = _sphereVBOs[IntPair(slices, stacks)]; int vertices = slices * (stacks - 1) + 2; int indices = slices * stacks * NUM_VERTICES_PER_TRIANGULATED_QUAD; @@ -211,7 +211,11 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks) { glPushMatrix(); glScalef(radius, radius, radius); - glDrawRangeElementsEXT(GL_TRIANGLES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); + if (solid) { + glDrawRangeElementsEXT(GL_TRIANGLES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); + } else { + glDrawRangeElementsEXT(GL_LINES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); + } glPopMatrix(); glDisableClientState(GL_VERTEX_ARRAY); diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 97f24f94a3..f0045c10bf 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -38,7 +38,7 @@ class GeometryCache : public ResourceCache { public: void renderHemisphere(int slices, int stacks); - void renderSphere(float radius, int slices, int stacks); + void renderSphere(float radius, int slices, int stacks, bool solid = true); void renderSquare(int xDivisions, int yDivisions); void renderHalfCylinder(int slices, int stacks); void renderCone(float base, float height, int slices, int stacks); From 11b44000998e222f3a2f523da63d58077a28a403 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 18 Dec 2014 11:20:17 -0800 Subject: [PATCH 2/4] move all glut-ness to geometry cache --- interface/src/Application.cpp | 2 +- interface/src/avatar/Hand.cpp | 2 +- interface/src/ui/MetavoxelEditor.cpp | 6 +- interface/src/ui/NodeBounds.cpp | 4 +- interface/src/ui/overlays/Sphere3DOverlay.cpp | 6 +- interface/src/voxels/VoxelFade.cpp | 3 +- .../src/RenderableBoxEntityItem.cpp | 78 +++---------------- .../src/DeferredLightingEffect.cpp | 6 +- .../render-utils/src/DeferredLightingEffect.h | 3 +- libraries/render-utils/src/GeometryCache.cpp | 10 +++ libraries/render-utils/src/GeometryCache.h | 2 + 11 files changed, 37 insertions(+), 85 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 4df23d2f7e..577f830495 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3575,7 +3575,7 @@ void Application::renderViewFrustum(ViewFrustum& viewFrustum) { glPushMatrix(); glColor4f(1, 1, 0, 1); glTranslatef(position.x, position.y, position.z); // where we actually want it! - glutWireSphere(keyholeRadius, 20, 20); + DependencyManager::get()->renderSphere(keyholeRadius, 20, 20, false); glPopMatrix(); } } diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index 91d59ae2fa..0ea0d1b725 100644 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -153,7 +153,7 @@ void Hand::renderHandTargets(bool isMine) { const float collisionRadius = 0.05f; glColor4f(0.5f,0.5f,0.5f, alpha); - glutWireSphere(collisionRadius, 10.0f, 10.0f); + DependencyManager::get()->renderSphere(collisionRadius, 10, 10, false); glPopMatrix(); } } diff --git a/interface/src/ui/MetavoxelEditor.cpp b/interface/src/ui/MetavoxelEditor.cpp index f0516ab955..1a440570b7 100644 --- a/interface/src/ui/MetavoxelEditor.cpp +++ b/interface/src/ui/MetavoxelEditor.cpp @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -492,12 +493,11 @@ void BoxTool::render() { glColor4f(GRID_BRIGHTNESS, GRID_BRIGHTNESS, GRID_BRIGHTNESS, BOX_ALPHA); } glEnable(GL_CULL_FACE); - glutSolidCube(1.0); + DependencyManager::get()->renderSolidCube(1.0f); glDisable(GL_CULL_FACE); } glColor3f(GRID_BRIGHTNESS, GRID_BRIGHTNESS, GRID_BRIGHTNESS); - glutWireCube(1.0); - + DependencyManager::get()->renderWireCube(1.0f); glPopMatrix(); } diff --git a/interface/src/ui/NodeBounds.cpp b/interface/src/ui/NodeBounds.cpp index b0d3ddd14f..c529f6bbf3 100644 --- a/interface/src/ui/NodeBounds.cpp +++ b/interface/src/ui/NodeBounds.cpp @@ -12,6 +12,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include + #include "Application.h" #include "Util.h" @@ -132,7 +134,7 @@ void NodeBounds::draw() { getColorForNodeType(selectedNode->getType(), red, green, blue); glColor4f(red, green, blue, 0.2f); - glutSolidCube(1.0); + DependencyManager::get()->renderSolidCube(1.0f); glPopMatrix(); diff --git a/interface/src/ui/overlays/Sphere3DOverlay.cpp b/interface/src/ui/overlays/Sphere3DOverlay.cpp index 522902194f..3e30ec033d 100644 --- a/interface/src/ui/overlays/Sphere3DOverlay.cpp +++ b/interface/src/ui/overlays/Sphere3DOverlay.cpp @@ -62,11 +62,7 @@ void Sphere3DOverlay::render(RenderArgs* args) { glm::vec3 positionToCenter = center - position; glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); glScalef(dimensions.x, dimensions.y, dimensions.z); - if (_isSolid) { - DependencyManager::get()->renderSphere(1.0f, SLICES, SLICES); - } else { - glutWireSphere(1.0f, SLICES, SLICES); - } + DependencyManager::get()->renderSphere(1.0f, SLICES, SLICES, _isSolid); glPopMatrix(); glPopMatrix(); diff --git a/interface/src/voxels/VoxelFade.cpp b/interface/src/voxels/VoxelFade.cpp index 367090291c..7bb3be67ab 100644 --- a/interface/src/voxels/VoxelFade.cpp +++ b/interface/src/voxels/VoxelFade.cpp @@ -12,6 +12,7 @@ #include "InterfaceConfig.h" #include +#include #include #include "Application.h" @@ -47,7 +48,7 @@ void VoxelFade::render() { voxelDetails.y + voxelDetails.s * 0.5f, voxelDetails.z + voxelDetails.s * 0.5f); glLineWidth(1.0f); - glutSolidCube(voxelDetails.s); + DependencyManager::get()->renderSolidCube(voxelDetails.s); glLineWidth(1.0f); glPopMatrix(); glEnable(GL_LIGHTING); diff --git a/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp b/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp index bb0de0ce6d..276db09477 100644 --- a/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp @@ -28,79 +28,23 @@ void RenderableBoxEntityItem::render(RenderArgs* args) { glm::vec3 position = getPositionInMeters(); glm::vec3 center = getCenter() * (float)TREE_SCALE; glm::vec3 dimensions = getDimensions() * (float)TREE_SCALE; - glm::vec3 halfDimensions = dimensions / 2.0f; glm::quat rotation = getRotation(); - const bool useGlutCube = true; const float MAX_COLOR = 255.0f; - if (useGlutCube) { - glColor4f(getColor()[RED_INDEX] / MAX_COLOR, getColor()[GREEN_INDEX] / MAX_COLOR, - getColor()[BLUE_INDEX] / MAX_COLOR, getLocalRenderAlpha()); + glColor4f(getColor()[RED_INDEX] / MAX_COLOR, getColor()[GREEN_INDEX] / MAX_COLOR, + getColor()[BLUE_INDEX] / MAX_COLOR, getLocalRenderAlpha()); + glPushMatrix(); + glTranslatef(position.x, position.y, position.z); + glm::vec3 axis = glm::axis(rotation); + glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); glPushMatrix(); - glTranslatef(position.x, position.y, position.z); - glm::vec3 axis = glm::axis(rotation); - glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); - glPushMatrix(); - glm::vec3 positionToCenter = center - position; - glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); - glScalef(dimensions.x, dimensions.y, dimensions.z); - DependencyManager::get()->renderSolidCube(1.0f); - glPopMatrix(); + glm::vec3 positionToCenter = center - position; + glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); + glScalef(dimensions.x, dimensions.y, dimensions.z); + DependencyManager::get()->renderSolidCube(1.0f); glPopMatrix(); - } else { - static GLfloat vertices[] = { 1, 1, 1, -1, 1, 1, -1,-1, 1, 1,-1, 1, // v0,v1,v2,v3 (front) - 1, 1, 1, 1,-1, 1, 1,-1,-1, 1, 1,-1, // v0,v3,v4,v5 (right) - 1, 1, 1, 1, 1,-1, -1, 1,-1, -1, 1, 1, // v0,v5,v6,v1 (top) - -1, 1, 1, -1, 1,-1, -1,-1,-1, -1,-1, 1, // v1,v6,v7,v2 (left) - -1,-1,-1, 1,-1,-1, 1,-1, 1, -1,-1, 1, // v7,v4,v3,v2 (bottom) - 1,-1,-1, -1,-1,-1, -1, 1,-1, 1, 1,-1 }; // v4,v7,v6,v5 (back) + glPopMatrix(); - // normal array - static GLfloat normals[] = { 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, // v0,v1,v2,v3 (front) - 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, // v0,v3,v4,v5 (right) - 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, // v0,v5,v6,v1 (top) - -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, // v1,v6,v7,v2 (left) - 0,-1, 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, // v7,v4,v3,v2 (bottom) - 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, 0,-1 }; // v4,v7,v6,v5 (back) - - // index array of vertex array for glDrawElements() & glDrawRangeElement() - static GLubyte indices[] = { 0, 1, 2, 2, 3, 0, // front - 4, 5, 6, 6, 7, 4, // right - 8, 9,10, 10,11, 8, // top - 12,13,14, 14,15,12, // left - 16,17,18, 18,19,16, // bottom - 20,21,22, 22,23,20 }; // back - - - - glEnableClientState(GL_NORMAL_ARRAY); - glEnableClientState(GL_VERTEX_ARRAY); - glNormalPointer(GL_FLOAT, 0, normals); - glVertexPointer(3, GL_FLOAT, 0, vertices); - - glColor4f(getColor()[RED_INDEX] / MAX_COLOR, getColor()[GREEN_INDEX] / MAX_COLOR, - getColor()[BLUE_INDEX] / MAX_COLOR, getLocalRenderAlpha()); - - DependencyManager::get()->bindSimpleProgram(); - - glPushMatrix(); - glTranslatef(position.x, position.y, position.z); - glm::vec3 axis = glm::axis(rotation); - glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); - glPushMatrix(); - glm::vec3 positionToCenter = center - position; - glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); - // we need to do half the size because the geometry in the VBOs are from -1,-1,-1 to 1,1,1 - glScalef(halfDimensions.x, halfDimensions.y, halfDimensions.z); - glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, indices); - glPopMatrix(); - glPopMatrix(); - - DependencyManager::get()->releaseSimpleProgram(); - - glDisableClientState(GL_VERTEX_ARRAY); // disable vertex arrays - glDisableClientState(GL_NORMAL_ARRAY); - } }; diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 065ca3a741..0dd6f9d0b8 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -12,8 +12,6 @@ // include this before QOpenGLFramebufferObject, which includes an earlier version of OpenGL #include -#include // TODO - we need to get rid of this ASAP - #include #include @@ -74,13 +72,13 @@ void DeferredLightingEffect::renderWireSphere(float radius, int slices, int stac void DeferredLightingEffect::renderSolidCube(float size) { bindSimpleProgram(); - glutSolidCube(size); + DependencyManager::get()->renderSolidCube(size); releaseSimpleProgram(); } void DeferredLightingEffect::renderWireCube(float size) { bindSimpleProgram(); - glutWireCube(size); + DependencyManager::get()->renderWireCube(size); releaseSimpleProgram(); } diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index 7ace3448d7..4f3b930a09 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -30,8 +30,7 @@ public: void init(AbstractViewStateInterface* viewState); - /// Returns a reference to a simple program suitable for rendering static - /// untextured geometry (such as that generated by glutSolidSphere, etc.) + /// Returns a reference to a simple program suitable for rendering static untextured geometry ProgramObject& getSimpleProgram() { return _simpleProgram; } /// Sets up the state necessary to render static untextured geometry with the simple program. diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index a770d942fe..e31ae2333a 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -11,6 +11,7 @@ // include this before QOpenGLBuffer, which includes an earlier version of OpenGL #include +#include // TODO - we need to get rid of this ASAP #include @@ -507,6 +508,15 @@ void GeometryCache::renderGrid(int xDivisions, int yDivisions) { buffer.release(); } +void GeometryCache::renderSolidCube(float size) { + glutSolidCube(size); +} + +void GeometryCache::renderWireCube(float size) { + glutWireCube(size); +} + + QSharedPointer GeometryCache::getGeometry(const QUrl& url, const QUrl& fallback, bool delayLoad) { return getResource(url, fallback, delayLoad).staticCast(); } diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index f0045c10bf..92e65718ab 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -43,6 +43,8 @@ public: void renderHalfCylinder(int slices, int stacks); void renderCone(float base, float height, int slices, int stacks); void renderGrid(int xDivisions, int yDivisions); + void renderSolidCube(float size); + void renderWireCube(float size); /// Loads geometry from the specified URL. /// \param fallback a fallback URL to load if the desired one is unavailable From 26bcca95c90e650076b23b7c4b69dd2780a9e278 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 18 Dec 2014 15:42:02 -0800 Subject: [PATCH 3/4] remove glutWireCube() --- libraries/render-utils/src/GeometryCache.cpp | 60 +++++++++++++++++++- libraries/render-utils/src/GeometryCache.h | 2 + 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index e31ae2333a..d28702fa20 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -513,7 +513,65 @@ void GeometryCache::renderSolidCube(float size) { } void GeometryCache::renderWireCube(float size) { - glutWireCube(size); + VerticesIndices& vbo = _wireCubeVBOs[size]; + const int FLOATS_PER_VERTEX = 3; + const int VERTICES_PER_EDGE = 2; + const int TOP_EDGES = 4; + const int BOTTOM_EDGES = 4; + const int SIDE_EDGES = 4; + const int vertices = 8; + const int indices = (TOP_EDGES + BOTTOM_EDGES + SIDE_EDGES) * VERTICES_PER_EDGE; + if (vbo.first == 0) { + int vertexPoints = vertices * FLOATS_PER_VERTEX; + GLfloat* vertexData = new GLfloat[vertexPoints]; // only vertices, no normals because we're a wire cube + GLfloat* vertex = vertexData; + float halfSize = size / 2.0f; + + static GLfloat cannonicalVertices[] = + { 1, 1, 1, 1, 1,-1, -1, 1,-1, -1, 1, 1, // v0, v1, v2, v3 (top) + 1,-1, 1, 1,-1,-1, -1,-1,-1, -1,-1, 1 // v4, v5, v6, v7 (bottom) + }; + + // index array of vertex array for glDrawRangeElement() as a GL_LINES for each edge + const GLubyte LINE_BREAK = static_cast(-1); + static GLubyte cannonicalIndices[indices] = { + 0, 1, 1, 2, 2, 3, 3, 0, // (top) + 4, 5, 5, 6, 6, 7, 7, 4, // (bottom) + 0, 4, 1, 5, 2, 6, 3, 7, // (side edges) + }; + + for (int i = 0; i < vertexPoints; i++) { + vertex[i] = cannonicalVertices[i] * halfSize; + } + + glGenBuffers(1, &vbo.first); + glBindBuffer(GL_ARRAY_BUFFER, vbo.first); + glBufferData(GL_ARRAY_BUFFER, vertices * NUM_BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW); + delete[] vertexData; + + GLushort* indexData = new GLushort[indices]; + GLushort* index = indexData; + for (int i = 0; i < indices; i++) { + index[i] = cannonicalIndices[i]; + } + + glGenBuffers(1, &vbo.second); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_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); + glVertexPointer(FLOATS_PER_VERTEX, GL_FLOAT, FLOATS_PER_VERTEX * sizeof(float), 0); + glDrawRangeElementsEXT(GL_LINES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); + glDisableClientState(GL_VERTEX_ARRAY); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + } diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 92e65718ab..514ee03c79 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -68,6 +68,8 @@ private: QHash _squareVBOs; QHash _halfCylinderVBOs; QHash _coneVBOs; + QHash _wireCubeVBOs; + QHash _solidCubeVBOs; QHash _gridBuffers; QHash > _networkGeometry; From 8091564a731f3ea08a275197b3935ce0e5078ae2 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 18 Dec 2014 16:12:30 -0800 Subject: [PATCH 4/4] remove all glut --- interface/src/Application.cpp | 2 - interface/src/Util.cpp | 6 -- libraries/gpu/src/gpu/GLUTConfig.h | 25 ------ libraries/render-utils/src/GeometryCache.cpp | 95 +++++++++++++++++++- 4 files changed, 91 insertions(+), 37 deletions(-) delete mode 100644 libraries/gpu/src/gpu/GLUTConfig.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d502e380b5..a7b91db315 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -537,8 +537,6 @@ void Application::initializeGL() { } else { isInitialized = true; } - int argc = 0; - glutInit(&argc, 0); #endif #ifdef WIN32 diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 38f18e96d9..d795964c5c 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -33,12 +33,6 @@ using namespace std; -// no clue which versions are affected... -#define WORKAROUND_BROKEN_GLUT_STROKES -// see http://www.opengl.org/resources/libraries/glut/spec3/node78.html - - - void renderWorldBox() { // Show edge of world float red[] = {1, 0, 0}; diff --git a/libraries/gpu/src/gpu/GLUTConfig.h b/libraries/gpu/src/gpu/GLUTConfig.h deleted file mode 100644 index 214f2bb2b0..0000000000 --- a/libraries/gpu/src/gpu/GLUTConfig.h +++ /dev/null @@ -1,25 +0,0 @@ -// -// GPUConfig.h -// libraries/gpu/src/gpu -// -// Created by Brad Hefta-Gaub on 12/17/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#ifndef gpu__GLUTConfig__ -#define gpu__GLUTConfig__ - -// TODO: remove these once we migrate away from GLUT calls -#if defined(__APPLE__) -#include -#elif defined(WIN32) -#include -#else -#include -#endif - - -#endif // gpu__GLUTConfig__ diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index d28702fa20..2837568ef5 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -11,7 +11,6 @@ // include this before QOpenGLBuffer, which includes an earlier version of OpenGL #include -#include // TODO - we need to get rid of this ASAP #include @@ -509,7 +508,97 @@ void GeometryCache::renderGrid(int xDivisions, int yDivisions) { } void GeometryCache::renderSolidCube(float size) { - glutSolidCube(size); + VerticesIndices& vbo = _solidCubeVBOs[size]; + const int FLOATS_PER_VERTEX = 3; + const int VERTICES_PER_FACE = 4; + const int NUMBER_OF_FACES = 6; + const int TRIANGLES_PER_FACE = 2; + const int VERTICES_PER_TRIANGLE = 3; + const int vertices = NUMBER_OF_FACES * VERTICES_PER_FACE * FLOATS_PER_VERTEX; + const int indices = NUMBER_OF_FACES * TRIANGLES_PER_FACE * VERTICES_PER_TRIANGLE; + const int vertexPoints = vertices * FLOATS_PER_VERTEX; + if (vbo.first == 0) { + GLfloat* vertexData = new GLfloat[vertexPoints * 2]; // vertices and normals + GLfloat* vertex = vertexData; + float halfSize = size / 2.0f; + + static GLfloat cannonicalVertices[vertexPoints] = + { 1, 1, 1, -1, 1, 1, -1,-1, 1, 1,-1, 1, // v0,v1,v2,v3 (front) + 1, 1, 1, 1,-1, 1, 1,-1,-1, 1, 1,-1, // v0,v3,v4,v5 (right) + 1, 1, 1, 1, 1,-1, -1, 1,-1, -1, 1, 1, // v0,v5,v6,v1 (top) + -1, 1, 1, -1, 1,-1, -1,-1,-1, -1,-1, 1, // v1,v6,v7,v2 (left) + -1,-1,-1, 1,-1,-1, 1,-1, 1, -1,-1, 1, // v7,v4,v3,v2 (bottom) + 1,-1,-1, -1,-1,-1, -1, 1,-1, 1, 1,-1 }; // v4,v7,v6,v5 (back) + + // normal array + static GLfloat cannonicalNormals[vertexPoints] = + { 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, // v0,v1,v2,v3 (front) + 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, // v0,v3,v4,v5 (right) + 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, // v0,v5,v6,v1 (top) + -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, // v1,v6,v7,v2 (left) + 0,-1, 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, // v7,v4,v3,v2 (bottom) + 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, 0,-1 }; // v4,v7,v6,v5 (back) + + // index array of vertex array for glDrawElements() & glDrawRangeElement() + static GLubyte cannonicalIndices[indices] = + { 0, 1, 2, 2, 3, 0, // front + 4, 5, 6, 6, 7, 4, // right + 8, 9,10, 10,11, 8, // top + 12,13,14, 14,15,12, // left + 16,17,18, 18,19,16, // bottom + 20,21,22, 22,23,20 }; // back + + + + GLfloat* cannonicalVertex = &cannonicalVertices[0]; + GLfloat* cannonicalNormal = &cannonicalNormals[0]; + + for (int i = 0; i < vertices; i++) { + //normals + *(vertex++) = *cannonicalNormal++; + *(vertex++) = *cannonicalNormal++; + *(vertex++) = *cannonicalNormal++; + + // vertices + *(vertex++) = halfSize * *cannonicalVertex++; + *(vertex++) = halfSize * *cannonicalVertex++; + *(vertex++) = halfSize * *cannonicalVertex++; + + } + + glGenBuffers(1, &vbo.first); + glBindBuffer(GL_ARRAY_BUFFER, vbo.first); + glBufferData(GL_ARRAY_BUFFER, vertices * NUM_BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW); + delete[] vertexData; + + GLushort* indexData = new GLushort[indices]; + GLushort* index = indexData; + for (int i = 0; i < indices; i++) { + index[i] = cannonicalIndices[i]; + } + + glGenBuffers(1, &vbo.second); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_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); + + glNormalPointer(GL_FLOAT, 6 * sizeof(float), 0); + glVertexPointer(3, GL_FLOAT, (6 * sizeof(float)), (const void *)(3 * sizeof(float))); + + glDrawRangeElementsEXT(GL_TRIANGLES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_NORMAL_ARRAY); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } void GeometryCache::renderWireCube(float size) { @@ -533,7 +622,6 @@ void GeometryCache::renderWireCube(float size) { }; // index array of vertex array for glDrawRangeElement() as a GL_LINES for each edge - const GLubyte LINE_BREAK = static_cast(-1); static GLubyte cannonicalIndices[indices] = { 0, 1, 1, 2, 2, 3, 3, 0, // (top) 4, 5, 5, 6, 6, 7, 7, 4, // (bottom) @@ -571,7 +659,6 @@ void GeometryCache::renderWireCube(float size) { glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - }