Animated textures updated for compatibility with asynchronous texture streamer
--HG-- branch : nfb
This commit is contained in:
@@ -47,7 +47,7 @@ KRTextureAnimated::KRTextureAnimated(KRContext &context, std::string name) : KRT
|
|||||||
int second_comma_pos = name.find(",", first_comma_pos + 1);
|
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_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());
|
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)
|
long KRTextureAnimated::getMemRequiredForSize(int max_dim)
|
||||||
{
|
{
|
||||||
int target_dim = max_dim;
|
return 0; // Memory is allocated by individual frame textures
|
||||||
if(target_dim < m_min_lod_max_dim) target_dim = m_min_lod_max_dim;
|
|
||||||
|
|
||||||
long memoryRequired = 0;
|
|
||||||
for(int i=0; i<m_frame_count; i++) {
|
|
||||||
KRTexture2D *frame_texture = textureForFrame(i);
|
|
||||||
if(frame_texture) {
|
|
||||||
memoryRequired += frame_texture->getMemRequiredForSize(target_dim);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return memoryRequired;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -108,12 +98,14 @@ void KRTextureAnimated::resetPoolExpiry()
|
|||||||
KRTexture2D *frame_texture = textureForFrame(i);
|
KRTexture2D *frame_texture = textureForFrame(i);
|
||||||
if(frame_texture) {
|
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
|
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)
|
void KRTextureAnimated::bind(GLuint texture_unit)
|
||||||
{
|
{
|
||||||
|
resetPoolExpiry();
|
||||||
KRTexture::bind(texture_unit);
|
KRTexture::bind(texture_unit);
|
||||||
int frame_number = (int)floor(fmodf(getContext().getAbsoluteTime() * m_frame_rate,m_frame_count));
|
int frame_number = (int)floor(fmodf(getContext().getAbsoluteTime() * m_frame_rate,m_frame_count));
|
||||||
KRTexture2D *frame_texture = textureForFrame(frame_number);
|
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
|
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
|
||||||
|
}
|
||||||
@@ -50,6 +50,7 @@ public:
|
|||||||
virtual long getReferencedMemSize();
|
virtual long getReferencedMemSize();
|
||||||
|
|
||||||
virtual bool isAnimated();
|
virtual bool isAnimated();
|
||||||
|
virtual void resize(int max_dim);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual bool createGLTexture(int lod_max_dim);
|
virtual bool createGLTexture(int lod_max_dim);
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ KRTexture *KRTextureManager::getTexture(const std::string &name) {
|
|||||||
if(itr == m_textures.end()) {
|
if(itr == m_textures.end()) {
|
||||||
if(lowerName.length() <= 8) {
|
if(lowerName.length() <= 8) {
|
||||||
return NULL;
|
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
|
// This is an animated texture, create KRTextureAnimated's on-demand
|
||||||
KRTextureAnimated *pTexture = new KRTextureAnimated(getContext(), lowerName);
|
KRTextureAnimated *pTexture = new KRTextureAnimated(getContext(), lowerName);
|
||||||
m_textures[lowerName] = pTexture;
|
m_textures[lowerName] = pTexture;
|
||||||
@@ -185,10 +185,8 @@ void KRTextureManager::selectTexture(int iTextureUnit, KRTexture *pTexture) {
|
|||||||
if(m_boundTextures[iTextureUnit] != pTexture || is_animated) {
|
if(m_boundTextures[iTextureUnit] != pTexture || is_animated) {
|
||||||
_setActiveTexture(iTextureUnit);
|
_setActiveTexture(iTextureUnit);
|
||||||
if(pTexture != NULL) {
|
if(pTexture != NULL) {
|
||||||
m_poolTextures.erase(pTexture);
|
primeTexture(pTexture);
|
||||||
if(m_activeTextures.find(pTexture) == m_activeTextures.end()) {
|
|
||||||
m_activeTextures.insert(pTexture);
|
|
||||||
}
|
|
||||||
pTexture->bind(iTextureUnit);
|
pTexture->bind(iTextureUnit);
|
||||||
|
|
||||||
} else {
|
} 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() {
|
long KRTextureManager::getMemUsed() {
|
||||||
return m_textureMemUsed;
|
return m_textureMemUsed;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ public:
|
|||||||
KRTextureManager(KRContext &context);
|
KRTextureManager(KRContext &context);
|
||||||
virtual ~KRTextureManager();
|
virtual ~KRTextureManager();
|
||||||
|
|
||||||
|
void primeTexture(KRTexture *pTexture);
|
||||||
void selectTexture(int iTextureUnit, KRTexture *pTexture);
|
void selectTexture(int iTextureUnit, KRTexture *pTexture);
|
||||||
|
|
||||||
KRTexture *loadTexture(const char *szName, const char *szExtension, KRDataBlock *data);
|
KRTexture *loadTexture(const char *szName, const char *szExtension, KRDataBlock *data);
|
||||||
|
|||||||
Reference in New Issue
Block a user