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
This commit is contained in:
Sam Gateau 2014-10-03 16:55:58 -07:00
parent aa1af0e144
commit 738369e21f
52 changed files with 158 additions and 41 deletions

View file

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

0
domain-server/resources/web/assignment/js/ace/ace.js Executable file → Normal file
View file

View file

View file

View file

View file

0
domain-server/resources/web/js/form2js.min.js vendored Executable file → Normal file
View file

0
examples/move.js Executable file → Normal file
View file

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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");

View file

@ -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();
}
}

View file

@ -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();

View file

@ -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");

View file

@ -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();
}

0
interface/src/Stars.cpp Executable file → Normal file
View file

0
interface/src/Stars.h Executable file → Normal file
View file

View file

@ -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();
}

View file

@ -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();
}
}

0
interface/src/avatar/Avatar.h Executable file → Normal file
View file

View file

@ -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();
}
}

0
interface/src/avatar/Hand.h Executable file → Normal file
View file

View file

@ -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();
}

View file

@ -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<CapsuleShape*>(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);

View file

@ -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();
}

View file

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

View file

@ -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<GLuint, GLuint> VerticesIndices;
QHash<IntPair, VerticesIndices> _hemisphereVBOs;
QHash<IntPair, VerticesIndices> _sphereVBOs;
QHash<IntPair, VerticesIndices> _squareVBOs;
QHash<IntPair, VerticesIndices> _halfCylinderVBOs;
QHash<IntPair, QOpenGLBuffer> _gridBuffers;

0
interface/src/starfield/Config.h Executable file → Normal file
View file

0
interface/src/starfield/Controller.cpp Executable file → Normal file
View file

0
interface/src/starfield/Controller.h Executable file → Normal file
View file

0
interface/src/starfield/data/GpuVertex.cpp Executable file → Normal file
View file

0
interface/src/starfield/data/GpuVertex.h Executable file → Normal file
View file

0
interface/src/starfield/data/InputVertex.cpp Executable file → Normal file
View file

0
interface/src/starfield/data/InputVertex.h Executable file → Normal file
View file

0
interface/src/starfield/data/Tile.h Executable file → Normal file
View file

0
interface/src/starfield/renderer/Renderer.cpp Executable file → Normal file
View file

0
interface/src/starfield/renderer/Renderer.h Executable file → Normal file
View file

0
interface/src/starfield/renderer/Tiling.h Executable file → Normal file
View file

0
interface/src/starfield/renderer/VertexOrder.cpp Executable file → Normal file
View file

0
interface/src/starfield/renderer/VertexOrder.h Executable file → Normal file
View file

View file

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

View file

@ -15,6 +15,7 @@
#include <SharedUtil.h>
#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);
}

0
libraries/avatars/src/AvatarData.h Executable file → Normal file
View file

0
libraries/avatars/src/HandData.h Executable file → Normal file
View file

0
libraries/embedded-webserver/src/HTTPConnection.cpp Executable file → Normal file
View file

0
libraries/embedded-webserver/src/HTTPManager.cpp Executable file → Normal file
View file

0
libraries/embedded-webserver/src/HTTPManager.h Executable file → Normal file
View file

0
libraries/octree/src/Plane.cpp Executable file → Normal file
View file

0
libraries/octree/src/Plane.h Executable file → Normal file
View file

0
tools/samples/cube1.hio Executable file → Normal file
View file

0
tools/samples/oneRedVoxel.hio Executable file → Normal file
View file

0
tools/samples/single.hio Executable file → Normal file
View file