reduce calls to DependencyManager::get<> where possible

This commit is contained in:
ZappoMan 2014-12-15 11:40:17 -08:00
parent 90c1132dd5
commit 3bc1321549
5 changed files with 38 additions and 28 deletions

View file

@ -1177,10 +1177,11 @@ void VoxelBuffer::render(bool cursor) {
if (!_materials.isEmpty()) { if (!_materials.isEmpty()) {
_networkTextures.resize(_materials.size()); _networkTextures.resize(_materials.size());
TextureCache* textureCache = DependencyManager::get<TextureCache>();
for (int i = 0; i < _materials.size(); i++) { for (int i = 0; i < _materials.size(); i++) {
const SharedObjectPointer material = _materials.at(i); const SharedObjectPointer material = _materials.at(i);
if (material) { if (material) {
_networkTextures[i] = DependencyManager::get<TextureCache>()->getTexture( _networkTextures[i] = textureCache->getTexture(
static_cast<MaterialObject*>(material.data())->getDiffuse(), SPLAT_TEXTURE); static_cast<MaterialObject*>(material.data())->getDiffuse(), SPLAT_TEXTURE);
} }
} }
@ -2231,10 +2232,11 @@ void HeightfieldNodeRenderer::render(const HeightfieldNodePointer& node, const g
const QVector<SharedObjectPointer>& materials = node->getMaterial()->getMaterials(); const QVector<SharedObjectPointer>& materials = node->getMaterial()->getMaterials();
_networkTextures.resize(materials.size()); _networkTextures.resize(materials.size());
TextureCache* textureCache = DependencyManager::get<TextureCache>();
for (int i = 0; i < materials.size(); i++) { for (int i = 0; i < materials.size(); i++) {
const SharedObjectPointer& material = materials.at(i); const SharedObjectPointer& material = materials.at(i);
if (material) { if (material) {
_networkTextures[i] = DependencyManager::get<TextureCache>()->getTexture( _networkTextures[i] = textureCache->getTexture(
static_cast<MaterialObject*>(material.data())->getDiffuse(), SPLAT_TEXTURE); static_cast<MaterialObject*>(material.data())->getDiffuse(), SPLAT_TEXTURE);
} }
} }

View file

@ -117,15 +117,16 @@ void DeferredLightingEffect::addSpotLight(const glm::vec3& position, float radiu
void DeferredLightingEffect::prepare() { void DeferredLightingEffect::prepare() {
// clear the normal and specular buffers // clear the normal and specular buffers
DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(false, true, false); TextureCache* textureCache = DependencyManager::get<TextureCache>();
textureCache->setPrimaryDrawBuffers(false, true, false);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(false, false, true); textureCache->setPrimaryDrawBuffers(false, false, true);
// clearing to zero alpha for specular causes problems on my Nvidia card; clear to lowest non-zero value instead // clearing to zero alpha for specular causes problems on my Nvidia card; clear to lowest non-zero value instead
const float MAX_SPECULAR_EXPONENT = 128.0f; const float MAX_SPECULAR_EXPONENT = 128.0f;
glClearColor(0.0f, 0.0f, 0.0f, 1.0f / MAX_SPECULAR_EXPONENT); glClearColor(0.0f, 0.0f, 0.0f, 1.0f / MAX_SPECULAR_EXPONENT);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(true, false, false); textureCache->setPrimaryDrawBuffers(true, false, false);
} }
void DeferredLightingEffect::render() { void DeferredLightingEffect::render() {
@ -137,8 +138,10 @@ void DeferredLightingEffect::render() {
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glDisable(GL_COLOR_MATERIAL); glDisable(GL_COLOR_MATERIAL);
glDepthMask(false); glDepthMask(false);
TextureCache* textureCache = DependencyManager::get<TextureCache>();
QOpenGLFramebufferObject* primaryFBO = DependencyManager::get<TextureCache>()->getPrimaryFramebufferObject(); QOpenGLFramebufferObject* primaryFBO = textureCache->getPrimaryFramebufferObject();
primaryFBO->release(); primaryFBO->release();
QOpenGLFramebufferObject* freeFBO = Application::getInstance()->getGlowEffect()->getFreeFramebufferObject(); QOpenGLFramebufferObject* freeFBO = Application::getInstance()->getGlowEffect()->getFreeFramebufferObject();
@ -148,13 +151,13 @@ void DeferredLightingEffect::render() {
glBindTexture(GL_TEXTURE_2D, primaryFBO->texture()); glBindTexture(GL_TEXTURE_2D, primaryFBO->texture());
glActiveTexture(GL_TEXTURE1); glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, DependencyManager::get<TextureCache>()->getPrimaryNormalTextureID()); glBindTexture(GL_TEXTURE_2D, textureCache->getPrimaryNormalTextureID());
glActiveTexture(GL_TEXTURE2); glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, DependencyManager::get<TextureCache>()->getPrimarySpecularTextureID()); glBindTexture(GL_TEXTURE_2D, textureCache->getPrimarySpecularTextureID());
glActiveTexture(GL_TEXTURE3); glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D, DependencyManager::get<TextureCache>()->getPrimaryDepthTextureID()); glBindTexture(GL_TEXTURE_2D, textureCache->getPrimaryDepthTextureID());
// get the viewport side (left, right, both) // get the viewport side (left, right, both)
int viewport[4]; int viewport[4];
@ -173,7 +176,7 @@ void DeferredLightingEffect::render() {
bool shadowsEnabled = Menu::getInstance()->getShadowsEnabled(); bool shadowsEnabled = Menu::getInstance()->getShadowsEnabled();
if (shadowsEnabled) { if (shadowsEnabled) {
glActiveTexture(GL_TEXTURE4); glActiveTexture(GL_TEXTURE4);
glBindTexture(GL_TEXTURE_2D, DependencyManager::get<TextureCache>()->getShadowDepthTextureID()); glBindTexture(GL_TEXTURE_2D, textureCache->getShadowDepthTextureID());
program = &_directionalLightShadowMap; program = &_directionalLightShadowMap;
locations = &_directionalLightShadowMapLocations; locations = &_directionalLightShadowMapLocations;
@ -188,7 +191,7 @@ void DeferredLightingEffect::render() {
program->bind(); program->bind();
} }
program->setUniformValue(locations->shadowScale, program->setUniformValue(locations->shadowScale,
1.0f / DependencyManager::get<TextureCache>()->getShadowFramebufferObject()->width()); 1.0f / textureCache->getShadowFramebufferObject()->width());
} else { } else {
program->bind(); program->bind();

View file

@ -699,6 +699,7 @@ void NetworkGeometry::clearLoadPriority(const QPointer<QObject>& owner) {
void NetworkGeometry::setTextureWithNameToURL(const QString& name, const QUrl& url) { void NetworkGeometry::setTextureWithNameToURL(const QString& name, const QUrl& url) {
if (_meshes.size() > 0) { if (_meshes.size() > 0) {
TextureCache* textureCache = DependencyManager::get<TextureCache>();
for (int i = 0; i < _meshes.size(); i++) { for (int i = 0; i < _meshes.size(); i++) {
NetworkMesh& mesh = _meshes[i]; NetworkMesh& mesh = _meshes[i];
for (int j = 0; j < mesh.parts.size(); j++) { for (int j = 0; j < mesh.parts.size(); j++) {
@ -707,19 +708,19 @@ void NetworkGeometry::setTextureWithNameToURL(const QString& name, const QUrl& u
QSharedPointer<NetworkTexture> matchingTexture = QSharedPointer<NetworkTexture>(); QSharedPointer<NetworkTexture> matchingTexture = QSharedPointer<NetworkTexture>();
if (part.diffuseTextureName == name) { if (part.diffuseTextureName == name) {
part.diffuseTexture = part.diffuseTexture =
DependencyManager::get<TextureCache>()->getTexture(url, DEFAULT_TEXTURE, textureCache->getTexture(url, DEFAULT_TEXTURE,
_geometry.meshes[i].isEye, QByteArray()); _geometry.meshes[i].isEye, QByteArray());
part.diffuseTexture->setLoadPriorities(_loadPriorities); part.diffuseTexture->setLoadPriorities(_loadPriorities);
} else if (part.normalTextureName == name) { } else if (part.normalTextureName == name) {
part.normalTexture = DependencyManager::get<TextureCache>()->getTexture(url, DEFAULT_TEXTURE, part.normalTexture = textureCache->getTexture(url, DEFAULT_TEXTURE,
false, QByteArray()); false, QByteArray());
part.normalTexture->setLoadPriorities(_loadPriorities); part.normalTexture->setLoadPriorities(_loadPriorities);
} else if (part.specularTextureName == name) { } else if (part.specularTextureName == name) {
part.specularTexture = DependencyManager::get<TextureCache>()->getTexture(url, DEFAULT_TEXTURE, part.specularTexture = textureCache->getTexture(url, DEFAULT_TEXTURE,
false, QByteArray()); false, QByteArray());
part.specularTexture->setLoadPriorities(_loadPriorities); part.specularTexture->setLoadPriorities(_loadPriorities);
} else if (part.emissiveTextureName == name) { } else if (part.emissiveTextureName == name) {
part.emissiveTexture = DependencyManager::get<TextureCache>()->getTexture(url, DEFAULT_TEXTURE, part.emissiveTexture = textureCache->getTexture(url, DEFAULT_TEXTURE,
false, QByteArray()); false, QByteArray());
part.emissiveTexture->setLoadPriorities(_loadPriorities); part.emissiveTexture->setLoadPriorities(_loadPriorities);
} }
@ -912,6 +913,8 @@ void NetworkGeometry::reinsert() {
void NetworkGeometry::setGeometry(const FBXGeometry& geometry) { void NetworkGeometry::setGeometry(const FBXGeometry& geometry) {
_geometry = geometry; _geometry = geometry;
TextureCache* textureCache = DependencyManager::get<TextureCache>();
foreach (const FBXMesh& mesh, _geometry.meshes) { foreach (const FBXMesh& mesh, _geometry.meshes) {
NetworkMesh networkMesh; NetworkMesh networkMesh;
@ -920,28 +923,28 @@ void NetworkGeometry::setGeometry(const FBXGeometry& geometry) {
foreach (const FBXMeshPart& part, mesh.parts) { foreach (const FBXMeshPart& part, mesh.parts) {
NetworkMeshPart networkPart; NetworkMeshPart networkPart;
if (!part.diffuseTexture.filename.isEmpty()) { if (!part.diffuseTexture.filename.isEmpty()) {
networkPart.diffuseTexture = DependencyManager::get<TextureCache>()->getTexture( networkPart.diffuseTexture = textureCache->getTexture(
_textureBase.resolved(QUrl(part.diffuseTexture.filename)), DEFAULT_TEXTURE, _textureBase.resolved(QUrl(part.diffuseTexture.filename)), DEFAULT_TEXTURE,
mesh.isEye, part.diffuseTexture.content); mesh.isEye, part.diffuseTexture.content);
networkPart.diffuseTextureName = part.diffuseTexture.name; networkPart.diffuseTextureName = part.diffuseTexture.name;
networkPart.diffuseTexture->setLoadPriorities(_loadPriorities); networkPart.diffuseTexture->setLoadPriorities(_loadPriorities);
} }
if (!part.normalTexture.filename.isEmpty()) { if (!part.normalTexture.filename.isEmpty()) {
networkPart.normalTexture = DependencyManager::get<TextureCache>()->getTexture( networkPart.normalTexture = textureCache->getTexture(
_textureBase.resolved(QUrl(part.normalTexture.filename)), NORMAL_TEXTURE, _textureBase.resolved(QUrl(part.normalTexture.filename)), NORMAL_TEXTURE,
false, part.normalTexture.content); false, part.normalTexture.content);
networkPart.normalTextureName = part.normalTexture.name; networkPart.normalTextureName = part.normalTexture.name;
networkPart.normalTexture->setLoadPriorities(_loadPriorities); networkPart.normalTexture->setLoadPriorities(_loadPriorities);
} }
if (!part.specularTexture.filename.isEmpty()) { if (!part.specularTexture.filename.isEmpty()) {
networkPart.specularTexture = DependencyManager::get<TextureCache>()->getTexture( networkPart.specularTexture = textureCache->getTexture(
_textureBase.resolved(QUrl(part.specularTexture.filename)), SPECULAR_TEXTURE, _textureBase.resolved(QUrl(part.specularTexture.filename)), SPECULAR_TEXTURE,
false, part.specularTexture.content); false, part.specularTexture.content);
networkPart.specularTextureName = part.specularTexture.name; networkPart.specularTextureName = part.specularTexture.name;
networkPart.specularTexture->setLoadPriorities(_loadPriorities); networkPart.specularTexture->setLoadPriorities(_loadPriorities);
} }
if (!part.emissiveTexture.filename.isEmpty()) { if (!part.emissiveTexture.filename.isEmpty()) {
networkPart.emissiveTexture = DependencyManager::get<TextureCache>()->getTexture( networkPart.emissiveTexture = textureCache->getTexture(
_textureBase.resolved(QUrl(part.emissiveTexture.filename)), EMISSIVE_TEXTURE, _textureBase.resolved(QUrl(part.emissiveTexture.filename)), EMISSIVE_TEXTURE,
false, part.emissiveTexture.content); false, part.emissiveTexture.content);
networkPart.emissiveTextureName = part.emissiveTexture.name; networkPart.emissiveTextureName = part.emissiveTexture.name;

View file

@ -122,7 +122,8 @@ static void maybeRelease(QOpenGLFramebufferObject* fbo) {
QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) { QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) {
PerformanceTimer perfTimer("glowEffect"); PerformanceTimer perfTimer("glowEffect");
QOpenGLFramebufferObject* primaryFBO = DependencyManager::get<TextureCache>()->getPrimaryFramebufferObject(); TextureCache* textureCache = DependencyManager::get<TextureCache>();
QOpenGLFramebufferObject* primaryFBO = textureCache->getPrimaryFramebufferObject();
primaryFBO->release(); primaryFBO->release();
glBindTexture(GL_TEXTURE_2D, primaryFBO->texture()); glBindTexture(GL_TEXTURE_2D, primaryFBO->texture());
@ -138,7 +139,7 @@ QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) {
glDepthMask(GL_FALSE); glDepthMask(GL_FALSE);
QOpenGLFramebufferObject* destFBO = toTexture ? QOpenGLFramebufferObject* destFBO = toTexture ?
DependencyManager::get<TextureCache>()->getSecondaryFramebufferObject() : NULL; textureCache->getSecondaryFramebufferObject() : NULL;
if (!Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect) || _isEmpty) { if (!Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect) || _isEmpty) {
// copy the primary to the screen // copy the primary to the screen
if (destFBO && QOpenGLFramebufferObject::hasOpenGLFramebufferBlit()) { if (destFBO && QOpenGLFramebufferObject::hasOpenGLFramebufferBlit()) {
@ -160,9 +161,9 @@ QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) {
} else { } else {
// diffuse into the secondary/tertiary (alternating between frames) // diffuse into the secondary/tertiary (alternating between frames)
QOpenGLFramebufferObject* oldDiffusedFBO = QOpenGLFramebufferObject* oldDiffusedFBO =
DependencyManager::get<TextureCache>()->getSecondaryFramebufferObject(); textureCache->getSecondaryFramebufferObject();
QOpenGLFramebufferObject* newDiffusedFBO = QOpenGLFramebufferObject* newDiffusedFBO =
DependencyManager::get<TextureCache>()->getTertiaryFramebufferObject(); textureCache->getTertiaryFramebufferObject();
if (_isOddFrame) { if (_isOddFrame) {
qSwap(oldDiffusedFBO, newDiffusedFBO); qSwap(oldDiffusedFBO, newDiffusedFBO);
} }

View file

@ -2324,7 +2324,8 @@ int Model::renderMeshesFromList(QVector<int>& list, gpu::Batch& batch, RenderMod
bool dontCullOutOfViewMeshParts = Menu::getInstance()->isOptionChecked(MenuOption::DontCullOutOfViewMeshParts); bool dontCullOutOfViewMeshParts = Menu::getInstance()->isOptionChecked(MenuOption::DontCullOutOfViewMeshParts);
bool cullTooSmallMeshParts = !Menu::getInstance()->isOptionChecked(MenuOption::DontCullTooSmallMeshParts); bool cullTooSmallMeshParts = !Menu::getInstance()->isOptionChecked(MenuOption::DontCullTooSmallMeshParts);
bool dontReduceMaterialSwitches = Menu::getInstance()->isOptionChecked(MenuOption::DontReduceMaterialSwitches); bool dontReduceMaterialSwitches = Menu::getInstance()->isOptionChecked(MenuOption::DontReduceMaterialSwitches);
TextureCache* textureCache = DependencyManager::get<TextureCache>();
QString lastMaterialID; QString lastMaterialID;
int meshPartsRendered = 0; int meshPartsRendered = 0;
updateVisibleJointStates(); updateVisibleJointStates();
@ -2446,7 +2447,7 @@ int Model::renderMeshesFromList(QVector<int>& list, gpu::Batch& batch, RenderMod
if (showDiffuse && diffuseMap) { if (showDiffuse && diffuseMap) {
GLBATCH(glBindTexture)(GL_TEXTURE_2D, diffuseMap->getID()); GLBATCH(glBindTexture)(GL_TEXTURE_2D, diffuseMap->getID());
} else { } else {
GLBATCH(glBindTexture)(GL_TEXTURE_2D, DependencyManager::get<TextureCache>()->getWhiteTextureID()); GLBATCH(glBindTexture)(GL_TEXTURE_2D, textureCache->getWhiteTextureID());
} }
if (locations->texcoordMatrices >= 0) { if (locations->texcoordMatrices >= 0) {
@ -2464,7 +2465,7 @@ int Model::renderMeshesFromList(QVector<int>& list, gpu::Batch& batch, RenderMod
GLBATCH(glActiveTexture)(GL_TEXTURE1); GLBATCH(glActiveTexture)(GL_TEXTURE1);
Texture* normalMap = networkPart.normalTexture.data(); Texture* normalMap = networkPart.normalTexture.data();
GLBATCH(glBindTexture)(GL_TEXTURE_2D, !normalMap ? GLBATCH(glBindTexture)(GL_TEXTURE_2D, !normalMap ?
DependencyManager::get<TextureCache>()->getBlueTextureID() : normalMap->getID()); textureCache->getBlueTextureID() : normalMap->getID());
GLBATCH(glActiveTexture)(GL_TEXTURE0); GLBATCH(glActiveTexture)(GL_TEXTURE0);
} }
@ -2472,7 +2473,7 @@ int Model::renderMeshesFromList(QVector<int>& list, gpu::Batch& batch, RenderMod
GLBATCH(glActiveTexture)(GL_TEXTURE0 + locations->specularTextureUnit); GLBATCH(glActiveTexture)(GL_TEXTURE0 + locations->specularTextureUnit);
Texture* specularMap = networkPart.specularTexture.data(); Texture* specularMap = networkPart.specularTexture.data();
GLBATCH(glBindTexture)(GL_TEXTURE_2D, !specularMap ? GLBATCH(glBindTexture)(GL_TEXTURE_2D, !specularMap ?
DependencyManager::get<TextureCache>()->getWhiteTextureID() : specularMap->getID()); textureCache->getWhiteTextureID() : specularMap->getID());
GLBATCH(glActiveTexture)(GL_TEXTURE0); GLBATCH(glActiveTexture)(GL_TEXTURE0);
} }
@ -2493,7 +2494,7 @@ int Model::renderMeshesFromList(QVector<int>& list, gpu::Batch& batch, RenderMod
GLBATCH(glActiveTexture)(GL_TEXTURE0 + locations->emissiveTextureUnit); GLBATCH(glActiveTexture)(GL_TEXTURE0 + locations->emissiveTextureUnit);
Texture* emissiveMap = networkPart.emissiveTexture.data(); Texture* emissiveMap = networkPart.emissiveTexture.data();
GLBATCH(glBindTexture)(GL_TEXTURE_2D, !emissiveMap ? GLBATCH(glBindTexture)(GL_TEXTURE_2D, !emissiveMap ?
DependencyManager::get<TextureCache>()->getWhiteTextureID() : emissiveMap->getID()); textureCache->getWhiteTextureID() : emissiveMap->getID());
GLBATCH(glActiveTexture)(GL_TEXTURE0); GLBATCH(glActiveTexture)(GL_TEXTURE0);
} }