diff --git a/KREngine/kraken/KRTextureAnimated.cpp b/KREngine/kraken/KRTextureAnimated.cpp index a38d970..c25028a 100644 --- a/KREngine/kraken/KRTextureAnimated.cpp +++ b/KREngine/kraken/KRTextureAnimated.cpp @@ -47,7 +47,7 @@ KRTextureAnimated::KRTextureAnimated(KRContext &context, std::string name) : KRT int second_comma_pos = name.find(",", first_comma_pos + 1); - m_texture_base_name = name.substr(8, first_comma_pos - 9); + m_texture_base_name = name.substr(8, first_comma_pos - 8); m_frame_count = atoi(name.substr(first_comma_pos+1, second_comma_pos - first_comma_pos -1).c_str()); m_frame_rate = atof(name.substr(second_comma_pos+1).c_str()); @@ -87,17 +87,7 @@ bool KRTextureAnimated::createGLTexture(int lod_max_dim) long KRTextureAnimated::getMemRequiredForSize(int max_dim) { - int target_dim = max_dim; - if(target_dim < m_min_lod_max_dim) target_dim = m_min_lod_max_dim; - - long memoryRequired = 0; - for(int i=0; igetMemRequiredForSize(target_dim); - } - } - return memoryRequired; + return 0; // Memory is allocated by individual frame textures } @@ -108,12 +98,14 @@ void KRTextureAnimated::resetPoolExpiry() KRTexture2D *frame_texture = textureForFrame(i); if(frame_texture) { frame_texture->resetPoolExpiry(); // Ensure that frames of animated textures do not expire from the texture pool prematurely, as they are referenced indirectly + getContext().getTextureManager()->primeTexture(frame_texture); } } } void KRTextureAnimated::bind(GLuint texture_unit) { + resetPoolExpiry(); KRTexture::bind(texture_unit); int frame_number = (int)floor(fmodf(getContext().getAbsoluteTime() * m_frame_rate,m_frame_count)); KRTexture2D *frame_texture = textureForFrame(frame_number); @@ -154,3 +146,7 @@ bool KRTextureAnimated::save(KRDataBlock &data) return true; // Animated textures are just references; there are no files to output } +void KRTextureAnimated::resize(int max_dim) +{ + // Purposely not calling the superclass method +} \ No newline at end of file diff --git a/KREngine/kraken/KRTextureAnimated.h b/KREngine/kraken/KRTextureAnimated.h index 8e458b9..9e685b6 100644 --- a/KREngine/kraken/KRTextureAnimated.h +++ b/KREngine/kraken/KRTextureAnimated.h @@ -50,6 +50,7 @@ public: virtual long getReferencedMemSize(); virtual bool isAnimated(); + virtual void resize(int max_dim); private: virtual bool createGLTexture(int lod_max_dim); diff --git a/KREngine/kraken/KRTextureManager.cpp b/KREngine/kraken/KRTextureManager.cpp index b7b8bfa..74b718f 100644 --- a/KREngine/kraken/KRTextureManager.cpp +++ b/KREngine/kraken/KRTextureManager.cpp @@ -161,7 +161,7 @@ KRTexture *KRTextureManager::getTexture(const std::string &name) { if(itr == m_textures.end()) { if(lowerName.length() <= 8) { return NULL; - } else if(lowerName.substr(8).compare("animate:") == 0) { + } else if(lowerName.compare(0, 8, "animate:", 0, 8) == 0) { // This is an animated texture, create KRTextureAnimated's on-demand KRTextureAnimated *pTexture = new KRTextureAnimated(getContext(), lowerName); m_textures[lowerName] = pTexture; @@ -185,10 +185,8 @@ void KRTextureManager::selectTexture(int iTextureUnit, KRTexture *pTexture) { if(m_boundTextures[iTextureUnit] != pTexture || is_animated) { _setActiveTexture(iTextureUnit); if(pTexture != NULL) { - m_poolTextures.erase(pTexture); - if(m_activeTextures.find(pTexture) == m_activeTextures.end()) { - m_activeTextures.insert(pTexture); - } + primeTexture(pTexture); + pTexture->bind(iTextureUnit); } else { @@ -199,6 +197,14 @@ void KRTextureManager::selectTexture(int iTextureUnit, KRTexture *pTexture) { } +void KRTextureManager::primeTexture(KRTexture *pTexture) +{ + m_poolTextures.erase(pTexture); + if(m_activeTextures.find(pTexture) == m_activeTextures.end()) { + m_activeTextures.insert(pTexture); + } +} + long KRTextureManager::getMemUsed() { return m_textureMemUsed; } diff --git a/KREngine/kraken/KRTextureManager.h b/KREngine/kraken/KRTextureManager.h index b55a473..cdf8b99 100644 --- a/KREngine/kraken/KRTextureManager.h +++ b/KREngine/kraken/KRTextureManager.h @@ -46,6 +46,7 @@ public: KRTextureManager(KRContext &context); virtual ~KRTextureManager(); + void primeTexture(KRTexture *pTexture); void selectTexture(int iTextureUnit, KRTexture *pTexture); KRTexture *loadTexture(const char *szName, const char *szExtension, KRDataBlock *data);