Browse Source

- Added ability to force the texture manager to upload the bitmap to a texture again.

MelvMay-GG 12 years ago
parent
commit
e1d8626

+ 5 - 0
engine/source/2d/assets/ImageAsset.cc

@@ -1016,6 +1016,11 @@ void ImageAsset::calculateImage( void )
     // Clear frames.
     mFrames.clear();
 
+    // If we have an existing texture and we're setting to the same bitmap then force the texture manager
+    // to refresh the texture itself.
+    if ( !mImageTextureHandle.IsNull() && dStricmp(mImageTextureHandle.getTextureKey(), mImageFile) == 0 )
+        TextureManager::refresh( mImageFile );
+
     // Get image texture.
     mImageTextureHandle.set( mImageFile, TextureHandle::BitmapTexture, true, getForce16Bit() );
 

+ 13 - 0
engine/source/graphics/TextureDictionary.cc

@@ -43,6 +43,19 @@ void TextureDictionary::create()
         smTable[i] = NULL;
 }
 
+//-----------------------------------------------------------------------------
+
+TextureObject* TextureDictionary::find( StringTableEntry textureKey )
+{
+    U32 key = HashPointer(textureKey) % smHashTableSize;
+    TextureObject *walk = smTable[key];
+    for(; walk; walk = walk->hashNext)
+    {
+        if(walk->mTextureKey == textureKey)
+            break;
+    }
+    return walk;
+}
 
 //-----------------------------------------------------------------------------
 

+ 3 - 2
engine/source/graphics/TextureDictionary.h

@@ -40,8 +40,9 @@ public:
     static void destroy();
 
     static void insert(TextureObject *object);
-    static TextureObject *find(StringTableEntry textureKey, TextureHandle::TextureHandleType type, bool clamp);
-    static void remove(TextureObject *object);
+    static TextureObject* find( StringTableEntry textureKey );
+    static TextureObject* find( StringTableEntry textureKey, TextureHandle::TextureHandleType type, bool clamp );
+    static void remove( TextureObject *object );
 };
 
 #endif // _TEXTURE_DICTIONARY_H_

+ 1 - 1
engine/source/graphics/TextureHandle.h

@@ -119,7 +119,7 @@ public:
         BitmapTexture = 100,
 
         /// Same as BitmapTexture except that the bitmap is kept which occupies main memory however
-        /// it does not required loading if textures need to be restored.
+        /// it does not require loading if textures need to be restored.
         BitmapKeepTexture = 200,
     };
 

+ 32 - 0
engine/source/graphics/TextureManager.cc

@@ -689,6 +689,38 @@ void TextureManager::refresh( TextureObject* pTextureObject )
 
 //--------------------------------------------------------------------------------------------------------------------
 
+void TextureManager::refresh( const char *textureName )
+{
+    // Finish if no texture name specified.
+    AssertFatal( textureName != NULL, "Texture Manager:  Cannot refresh a NULL texture name." );
+
+    // Find the texture object.
+    TextureObject* pTextureObject = TextureDictionary::find( textureName );
+
+    // Finish if no texture for this texture name.
+    if ( pTextureObject == NULL )
+        return;
+
+    // Finish if the texture object is a kept bitmap.
+    if ( pTextureObject->getHandleType() == TextureHandle::BitmapKeepTexture )
+        return;
+
+    // Load the bitmap.
+    GBitmap* pBitmap = loadBitmap( pTextureObject->mTextureKey );
+
+    // Finish if bitmap could not be loaded.
+    if ( pBitmap == NULL )
+        return;
+
+    // Register texture.
+    TextureObject* pNewTextureObject = registerTexture(pTextureObject->mTextureKey, pBitmap, pTextureObject->mHandleType, pTextureObject->mClamp);
+
+    // Sanity!
+    AssertFatal(pNewTextureObject == pTextureObject, "A new texture was returned during refresh.");
+}
+
+//--------------------------------------------------------------------------------------------------------------------
+
 void TextureManager::createGLName( TextureObject* pTextureObject )
 {
     // Finish if not appropriate.

+ 2 - 1
engine/source/graphics/TextureManager.h

@@ -56,7 +56,7 @@ public:
     {
         BeginZombification,
         BeginResurrection,
-        EndResurrection
+        EndResurrection,
     };
 
     typedef void (*TextureEventCallback)(const TextureEventCode eventCode, void *userData);
@@ -93,6 +93,7 @@ public:
     static void killManager();
     static void resurrectManager();
     static void flush();
+    static void refresh( const char *textureName );
     static S32 getBitmapResidentSize( void ) { return mBitmapResidentSize; }
     static S32 getTextureResidentSize( void ) { return mTextureResidentSize; }
     static S32 getTextureResidentWasteSize( void ) { return mTextureResidentWasteSize; }