reduce calls to DependencyManager::get<> where possible

This commit is contained in:
ZappoMan 2014-12-15 11:28:57 -08:00
parent 049cb25f07
commit 90c1132dd5
3 changed files with 21 additions and 14 deletions

View file

@ -71,22 +71,23 @@ void renderWorldBox() {
glPushMatrix();
glTranslatef(MARKER_DISTANCE, 0, 0);
glColor3fv(red);
DependencyManager::get<GeometryCache>()->renderSphere(MARKER_RADIUS, 10, 10);
GeometryCache* geometryCache = DependencyManager::get<GeometryCache>();
geometryCache->renderSphere(MARKER_RADIUS, 10, 10);
glPopMatrix();
glPushMatrix();
glTranslatef(0, MARKER_DISTANCE, 0);
glColor3fv(green);
DependencyManager::get<GeometryCache>()->renderSphere(MARKER_RADIUS, 10, 10);
geometryCache->renderSphere(MARKER_RADIUS, 10, 10);
glPopMatrix();
glPushMatrix();
glTranslatef(0, 0, MARKER_DISTANCE);
glColor3fv(blue);
DependencyManager::get<GeometryCache>()->renderSphere(MARKER_RADIUS, 10, 10);
geometryCache->renderSphere(MARKER_RADIUS, 10, 10);
glPopMatrix();
glPushMatrix();
glColor3fv(gray);
glTranslatef(MARKER_DISTANCE, 0, MARKER_DISTANCE);
DependencyManager::get<GeometryCache>()->renderSphere(MARKER_RADIUS, 10, 10);
geometryCache->renderSphere(MARKER_RADIUS, 10, 10);
glPopMatrix();
}

View file

@ -554,6 +554,7 @@ void SkeletonModel::renderRagdoll() {
float radius1 = 0.008f;
float radius2 = 0.01f;
glm::vec3 simulationTranslation = _ragdoll->getTranslationInSimulationFrame();
GeometryCache* geometryCache = DependencyManager::get<GeometryCache>();
for (int i = 0; i < numPoints; ++i) {
glPushMatrix();
// NOTE: ragdollPoints are in simulation-frame but we want them to be model-relative
@ -561,9 +562,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);
DependencyManager::get<GeometryCache>()->renderSphere(radius2, BALL_SUBDIVISIONS, BALL_SUBDIVISIONS);
geometryCache->renderSphere(radius2, BALL_SUBDIVISIONS, BALL_SUBDIVISIONS);
glColor4f(1.0f, 1.0f, 0.0f, alpha);
DependencyManager::get<GeometryCache>()->renderSphere(radius1, BALL_SUBDIVISIONS, BALL_SUBDIVISIONS);
geometryCache->renderSphere(radius1, BALL_SUBDIVISIONS, BALL_SUBDIVISIONS);
glPopMatrix();
}
glPopMatrix();
@ -913,7 +914,8 @@ void SkeletonModel::renderBoundingCollisionShapes(float alpha) {
endPoint = endPoint - _translation;
glTranslatef(endPoint.x, endPoint.y, endPoint.z);
glColor4f(0.6f, 0.6f, 0.8f, alpha);
DependencyManager::get<GeometryCache>()->renderSphere(_boundingShape.getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS);
GeometryCache* geometryCache = DependencyManager::get<GeometryCache>();
geometryCache->renderSphere(_boundingShape.getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS);
// draw a yellow sphere at the capsule startpoint
glm::vec3 startPoint;
@ -922,7 +924,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);
DependencyManager::get<GeometryCache>()->renderSphere(_boundingShape.getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS);
geometryCache->renderSphere(_boundingShape.getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS);
// draw a green cylinder between the two points
glm::vec3 origin(0.0f);
@ -948,6 +950,8 @@ void SkeletonModel::renderJointCollisionShapes(float alpha) {
continue;
}
GeometryCache* geometryCache = DependencyManager::get<GeometryCache>();
glPushMatrix();
// shapes are stored in simulation-frame but we want position to be model-relative
if (shape->getType() == SPHERE_SHAPE) {
@ -955,7 +959,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);
DependencyManager::get<GeometryCache>()->renderSphere(shape->getBoundingRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS);
geometryCache->renderSphere(shape->getBoundingRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS);
} else if (shape->getType() == CAPSULE_SHAPE) {
CapsuleShape* capsule = static_cast<CapsuleShape*>(shape);
@ -965,7 +969,7 @@ void SkeletonModel::renderJointCollisionShapes(float alpha) {
endPoint = endPoint - simulationTranslation;
glTranslatef(endPoint.x, endPoint.y, endPoint.z);
glColor4f(0.6f, 0.6f, 0.8f, alpha);
DependencyManager::get<GeometryCache>()->renderSphere(capsule->getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS);
geometryCache->renderSphere(capsule->getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS);
// draw a yellow sphere at the capsule startpoint
glm::vec3 startPoint;
@ -974,7 +978,7 @@ void SkeletonModel::renderJointCollisionShapes(float alpha) {
glm::vec3 axis = endPoint - startPoint;
glTranslatef(-axis.x, -axis.y, -axis.z);
glColor4f(0.8f, 0.8f, 0.6f, alpha);
DependencyManager::get<GeometryCache>()->renderSphere(capsule->getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS);
geometryCache->renderSphere(capsule->getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS);
// draw a green cylinder between the two points
glm::vec3 origin(0.0f);

View file

@ -234,6 +234,8 @@ void DeferredLightingEffect::render() {
const glm::vec3& eyePoint = Application::getInstance()->getDisplayViewFrustum()->getPosition();
float nearRadius = glm::distance(eyePoint, Application::getInstance()->getDisplayViewFrustum()->getNearTopLeft());
GeometryCache* geometryCache = DependencyManager::get<GeometryCache>();
if (!_pointLights.isEmpty()) {
_pointLight.bind();
@ -241,7 +243,7 @@ void DeferredLightingEffect::render() {
_pointLight.setUniformValue(_pointLightLocations.depthScale, depthScale);
_pointLight.setUniformValue(_pointLightLocations.depthTexCoordOffset, depthTexCoordOffsetS, depthTexCoordOffsetT);
_pointLight.setUniformValue(_pointLightLocations.depthTexCoordScale, depthTexCoordScaleS, depthTexCoordScaleT);
foreach (const PointLight& light, _pointLights) {
_pointLight.setUniformValue(_pointLightLocations.radius, light.radius);
glLightfv(GL_LIGHT1, GL_AMBIENT, (const GLfloat*)&light.ambient);
@ -270,7 +272,7 @@ void DeferredLightingEffect::render() {
} else {
glTranslatef(light.position.x, light.position.y, light.position.z);
DependencyManager::get<GeometryCache>()->renderSphere(expandedRadius, 32, 32);
geometryCache->renderSphere(expandedRadius, 32, 32);
}
glPopMatrix();
@ -323,7 +325,7 @@ void DeferredLightingEffect::render() {
glm::vec3 axis = glm::axis(spotRotation);
glRotatef(glm::degrees(glm::angle(spotRotation)), axis.x, axis.y, axis.z);
glTranslatef(0.0f, 0.0f, -light.radius * (1.0f + SCALE_EXPANSION * 0.5f));
DependencyManager::get<GeometryCache>()->renderCone(expandedRadius * glm::tan(light.cutoff),
geometryCache->renderCone(expandedRadius * glm::tan(light.cutoff),
expandedRadius, 32, 1);
}