Просмотр исходного кода

Added a setting to MaterialManager to not keep texture data in memory after uploading to video card

Ivan Safrin 11 лет назад
Родитель
Сommit
41908812e2

+ 1 - 0
Core/Contents/Include/PolyMaterialManager.h

@@ -101,6 +101,7 @@ namespace Polycode {
 			bool premultiplyAlphaOnLoad;
 			bool clampDefault;
 			bool mipmapsDefault;
+			bool keepTextureData;
 			
 		private:
 			std::vector<Texture*> textures;

+ 4 - 0
Core/Contents/Source/PolyGLTexture.cpp

@@ -59,6 +59,10 @@ OpenGLTexture::OpenGLTexture(unsigned int width, unsigned int height, char *text
 }
 
 void OpenGLTexture::recreateFromImageData() {
+    
+    if(!textureData) {
+        return;
+    }
 	
 	Number anisotropy = CoreServices::getInstance()->getRenderer()->getAnisotropyAmount();
 	

+ 9 - 0
Core/Contents/Source/PolyMaterialManager.cpp

@@ -38,6 +38,7 @@ MaterialManager::MaterialManager() {
 	premultiplyAlphaOnLoad = false;
 	clampDefault = false;
 	mipmapsDefault = true;
+    keepTextureData = true;
 }
 
 MaterialManager::~MaterialManager() {
@@ -176,12 +177,20 @@ Texture *MaterialManager::createNewTexture(int width, int height, bool clamp, bo
 Texture *MaterialManager::createTexture(int width, int height, char *imageData, bool clamp, bool createMipmaps, int type) {
 	Texture *newTexture = CoreServices::getInstance()->getRenderer()->createTexture(width, height, imageData,clamp, createMipmaps, type);
 	textures.push_back(newTexture);
+    if(!keepTextureData) {
+        free(newTexture->textureData);
+        newTexture->textureData = NULL;
+    }
 	return newTexture;
 }
 
 Texture *MaterialManager::createTextureFromImage(Image *image, bool clamp, bool createMipmaps) {
 	Texture *newTexture;
 	newTexture = createTexture(image->getWidth(), image->getHeight(), image->getPixels(),clamp, createMipmaps, image->getType());
+    if(!keepTextureData) {
+        free(newTexture->textureData);
+        newTexture->textureData = NULL;
+    }
 	return newTexture; 
 }