move all glut-ness to geometry cache

This commit is contained in:
ZappoMan 2014-12-18 11:20:17 -08:00
parent ef42203481
commit 11b4400099
11 changed files with 37 additions and 85 deletions

View file

@ -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<GeometryCache>()->renderSphere(keyholeRadius, 20, 20, false);
glPopMatrix();
}
}

View file

@ -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<GeometryCache>()->renderSphere(collisionRadius, 10, 10, false);
glPopMatrix();
}
}

View file

@ -33,6 +33,7 @@
#include <QVBoxLayout>
#include <AttributeRegistry.h>
#include <GeometryCache.h>
#include <MetavoxelMessages.h>
#include <MetavoxelUtil.h>
#include <PathUtils.h>
@ -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<GeometryCache>()->renderSolidCube(1.0f);
glDisable(GL_CULL_FACE);
}
glColor3f(GRID_BRIGHTNESS, GRID_BRIGHTNESS, GRID_BRIGHTNESS);
glutWireCube(1.0);
DependencyManager::get<GeometryCache>()->renderWireCube(1.0f);
glPopMatrix();
}

View file

@ -12,6 +12,8 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <GeometryCache.h>
#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<GeometryCache>()->renderSolidCube(1.0f);
glPopMatrix();

View file

@ -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<GeometryCache>()->renderSphere(1.0f, SLICES, SLICES);
} else {
glutWireSphere(1.0f, SLICES, SLICES);
}
DependencyManager::get<GeometryCache>()->renderSphere(1.0f, SLICES, SLICES, _isSolid);
glPopMatrix();
glPopMatrix();

View file

@ -12,6 +12,7 @@
#include "InterfaceConfig.h"
#include <GlowEffect.h>
#include <GeometryCache.h>
#include <VoxelConstants.h>
#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<GeometryCache>()->renderSolidCube(voxelDetails.s);
glLineWidth(1.0f);
glPopMatrix();
glEnable(GL_LIGHTING);

View file

@ -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<DeferredLightingEffect>()->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<DeferredLightingEffect>()->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<DeferredLightingEffect>()->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<DeferredLightingEffect>()->releaseSimpleProgram();
glDisableClientState(GL_VERTEX_ARRAY); // disable vertex arrays
glDisableClientState(GL_NORMAL_ARRAY);
}
};

View file

@ -12,8 +12,6 @@
// include this before QOpenGLFramebufferObject, which includes an earlier version of OpenGL
#include <gpu/GPUConfig.h>
#include <gpu/GLUTConfig.h> // TODO - we need to get rid of this ASAP
#include <QOpenGLFramebufferObject>
#include <GLMHelpers.h>
@ -74,13 +72,13 @@ void DeferredLightingEffect::renderWireSphere(float radius, int slices, int stac
void DeferredLightingEffect::renderSolidCube(float size) {
bindSimpleProgram();
glutSolidCube(size);
DependencyManager::get<GeometryCache>()->renderSolidCube(size);
releaseSimpleProgram();
}
void DeferredLightingEffect::renderWireCube(float size) {
bindSimpleProgram();
glutWireCube(size);
DependencyManager::get<GeometryCache>()->renderWireCube(size);
releaseSimpleProgram();
}

View file

@ -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.

View file

@ -11,6 +11,7 @@
// include this before QOpenGLBuffer, which includes an earlier version of OpenGL
#include <gpu/GPUConfig.h>
#include <gpu/GLUTConfig.h> // TODO - we need to get rid of this ASAP
#include <cmath>
@ -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<NetworkGeometry> GeometryCache::getGeometry(const QUrl& url, const QUrl& fallback, bool delayLoad) {
return getResource(url, fallback, delayLoad).staticCast<NetworkGeometry>();
}

View file

@ -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