CPU Performance Optimization when texture cubes are in use

--HG--
branch : nfb
This commit is contained in:
2014-04-13 19:35:23 -07:00
parent c51552838b
commit 462d0ec6e7
2 changed files with 16 additions and 16 deletions

View File

@@ -40,11 +40,12 @@ KRTextureCube::KRTextureCube(KRContext &context, std::string name) : KRTexture(c
m_min_lod_max_dim = 64; m_min_lod_max_dim = 64;
for(int i=0; i<6; i++) { for(int i=0; i<6; i++) {
m_textures[i] = NULL;
std::string faceName = getName() + SUFFIXES[i]; std::string faceName = getName() + SUFFIXES[i];
KRTexture2D *faceTexture = (KRTexture2D *)getContext().getTextureManager()->getTexture(faceName); m_textures[i] = (KRTexture2D *)getContext().getTextureManager()->getTexture(faceName);
if(faceTexture) { if(m_textures[i]) {
if(faceTexture->getMaxMipMap() < m_max_lod_max_dim) m_max_lod_max_dim = faceTexture->getMaxMipMap(); if(m_textures[i]->getMaxMipMap() < m_max_lod_max_dim) m_max_lod_max_dim = m_textures[i]->getMaxMipMap();
if(faceTexture->getMinMipMap() > m_min_lod_max_dim) m_min_lod_max_dim = faceTexture->getMinMipMap(); if(m_textures[i]->getMinMipMap() > m_min_lod_max_dim) m_min_lod_max_dim = m_textures[i]->getMinMipMap();
} }
} }
} }
@@ -79,10 +80,9 @@ bool KRTextureCube::createGLTexture(int lod_max_dim)
for(int i=0; i<6; i++) { for(int i=0; i<6; i++) {
std::string faceName = getName() + SUFFIXES[i]; std::string faceName = getName() + SUFFIXES[i];
KRTexture2D *faceTexture = (KRTexture2D *)getContext().getTextureManager()->getTexture(faceName); if(m_textures[i]) {
if(faceTexture) { if(m_textures[i]->hasMipmaps()) bMipMaps = true;
if(faceTexture->hasMipmaps()) bMipMaps = true; m_textures[i]->uploadTexture(TARGETS[i], lod_max_dim, m_current_lod_max_dim, prev_lod_max_dim);
faceTexture->uploadTexture(TARGETS[i], lod_max_dim, m_current_lod_max_dim, prev_lod_max_dim);
} }
} }
@@ -105,10 +105,8 @@ long KRTextureCube::getMemRequiredForSize(int max_dim)
long memoryRequired = 0; long memoryRequired = 0;
for(int i=0; i<6; i++) { for(int i=0; i<6; i++) {
std::string faceName = getName() + SUFFIXES[i]; if(m_textures[i]) {
KRTexture2D *faceTexture = (KRTexture2D *)getContext().getTextureManager()->getTexture(faceName); memoryRequired += m_textures[i]->getMemRequiredForSize(target_dim);
if(faceTexture) {
memoryRequired += faceTexture->getMemRequiredForSize(target_dim);
} }
} }
return memoryRequired; return memoryRequired;
@@ -119,10 +117,8 @@ void KRTextureCube::resetPoolExpiry(float lodCoverage, texture_usage_t textureUs
{ {
KRTexture::resetPoolExpiry(lodCoverage, textureUsage); KRTexture::resetPoolExpiry(lodCoverage, textureUsage);
for(int i=0; i<6; i++) { for(int i=0; i<6; i++) {
std::string faceName = getName() + SUFFIXES[i]; if(m_textures[i]) {
KRTexture2D *faceTexture = (KRTexture2D *)getContext().getTextureManager()->getTexture(faceName); m_textures[i]->resetPoolExpiry(lodCoverage, textureUsage); // Ensure that side of cube maps do not expire from the texture pool prematurely, as they are referenced indirectly
if(faceTexture) {
faceTexture->resetPoolExpiry(lodCoverage, textureUsage); // Ensure that side of cube maps do not expire from the texture pool prematurely, as they are referenced indirectly
} }
} }
} }

View File

@@ -34,6 +34,8 @@
#include "KRTexture.h" #include "KRTexture.h"
class KRTexture2D;
class KRTextureCube : public KRTexture { class KRTextureCube : public KRTexture {
public: public:
KRTextureCube(KRContext &context, std::string name); KRTextureCube(KRContext &context, std::string name);
@@ -66,6 +68,8 @@ private:
"_positive_z", "_positive_z",
"_negative_z" "_negative_z"
}; };
KRTexture2D *m_textures[6];
}; };