From e0d338b58373762ca57f457ee0c29f3c754b100a Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 29 Oct 2010 16:27:22 +0000 Subject: [PATCH] - added more texture compression supported types - some in progress work related to texture reloading --- source/glest_game/game/game.cpp | 3 + source/glest_game/game/game.h | 1 + source/glest_game/main/main.cpp | 2 +- source/glest_game/main/program.cpp | 7 +- source/glest_game/main/program.h | 2 + .../include/graphics/gl/texture_gl.h | 8 +- source/shared_lib/include/graphics/texture.h | 2 +- .../sources/graphics/gl/texture_gl.cpp | 236 ++++++++++++++++-- .../sources/graphics/texture_manager.cpp | 3 + 9 files changed, 241 insertions(+), 23 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 3583e8a6..61f98aba 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -45,6 +45,7 @@ Game::Game(Program *program, const GameSettings *gameSettings): { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + this->program = program; Unit::setGame(this); original_updateFps = GameConstants::updateFps; @@ -136,6 +137,8 @@ Game::~Game() { Unit::setGame(NULL); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] ==== END GAME ==== getCurrentPixelByteCount() = %llu\n",__FILE__,__FUNCTION__,__LINE__,(long long unsigned int)renderer.getCurrentPixelByteCount()); + //this->program->reInitGl(); + //renderer.reinitAll(); } bool Game::quitTriggered() { diff --git a/source/glest_game/game/game.h b/source/glest_game/game/game.h index 89fdba1c..5765853b 100644 --- a/source/glest_game/game/game.h +++ b/source/glest_game/game/game.h @@ -109,6 +109,7 @@ private: int renderFpsAvgTest; bool photoModeEnabled; + Program *program; public: Game(Program *program, const GameSettings *gameSettings); diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index b12b4c0f..71686795 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -347,7 +347,7 @@ void MainWindow::eventKeyDown(char key){ SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] ALT-ENTER pressed\n",__FILE__,__FUNCTION__,__LINE__); // This stupidity only required in win32. - // We reload the textures so that + // We reload the textures so that the canvas paints textures properly #ifdef WIN32 if(Window::getAllowAltEnterFullscreenToggle() == true) { Renderer &renderer= Renderer::getInstance(); diff --git a/source/glest_game/main/program.cpp b/source/glest_game/main/program.cpp index fb6613ca..24a41dad 100644 --- a/source/glest_game/main/program.cpp +++ b/source/glest_game/main/program.cpp @@ -661,5 +661,10 @@ void Program::showMessage(const char *msg) { //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); } - +void Program::reInitGl() { + if(window != NULL) { + Config &config= Config::getInstance(); + window->initGl(config.getInt("ColorBits"), config.getInt("DepthBits"), config.getInt("StencilBits"),config.getBool("HardwareAcceleration","false"),config.getBool("FullScreenAntiAliasing","false")); + } +} }}//end namespace diff --git a/source/glest_game/main/program.h b/source/glest_game/main/program.h index 78b56711..3e93242c 100644 --- a/source/glest_game/main/program.h +++ b/source/glest_game/main/program.h @@ -161,6 +161,8 @@ public: void renderProgramMsgBox(); bool isInSpecialKeyCaptureEvent() { return programState->isInSpecialKeyCaptureEvent(); } + void reInitGl(); + private: void setDisplaySettings(); diff --git a/source/shared_lib/include/graphics/gl/texture_gl.h b/source/shared_lib/include/graphics/gl/texture_gl.h index 384a1905..10273ef6 100644 --- a/source/shared_lib/include/graphics/gl/texture_gl.h +++ b/source/shared_lib/include/graphics/gl/texture_gl.h @@ -43,7 +43,7 @@ public: virtual ~Texture1DGl(); virtual void init(Filter filter, int maxAnisotropy= 1); - virtual void end(); + virtual void end(bool deletePixelBuffer=true); }; // ===================================================== @@ -56,7 +56,7 @@ public: virtual ~Texture2DGl(); virtual void init(Filter filter, int maxAnisotropy= 1); - virtual void end(); + virtual void end(bool deletePixelBuffer=true); }; // ===================================================== @@ -70,7 +70,7 @@ public: virtual ~Texture3DGl(); virtual void init(Filter filter, int maxAnisotropy= 1); - virtual void end(); + virtual void end(bool deletePixelBuffer=true); }; // ===================================================== @@ -84,7 +84,7 @@ public: virtual ~TextureCubeGl(); virtual void init(Filter filter, int maxAnisotropy= 1); - virtual void end(); + virtual void end(bool deletePixelBuffer=true); }; }}}//end namespace diff --git a/source/shared_lib/include/graphics/texture.h b/source/shared_lib/include/graphics/texture.h index a1295ffb..58a97531 100644 --- a/source/shared_lib/include/graphics/texture.h +++ b/source/shared_lib/include/graphics/texture.h @@ -79,7 +79,7 @@ public: void setFormat(Format format) {this->format= format;} virtual void init(Filter filter= fBilinear, int maxAnisotropy= 1)=0; - virtual void end()=0; + virtual void end(bool deletePixelBuffer=true)=0; virtual string getPath() const = 0; virtual void deletePixels() = 0; virtual uint64 getPixelByteCount() const = 0; diff --git a/source/shared_lib/sources/graphics/gl/texture_gl.cpp b/source/shared_lib/sources/graphics/gl/texture_gl.cpp index e3178daa..ab641af6 100644 --- a/source/shared_lib/sources/graphics/gl/texture_gl.cpp +++ b/source/shared_lib/sources/graphics/gl/texture_gl.cpp @@ -14,7 +14,8 @@ #include "opengl.h" #include #include - +#include "conversion.h" +#include #include "leak_dumper.h" using namespace std; @@ -22,11 +23,12 @@ using namespace std; namespace Shared{ namespace Graphics{ namespace Gl{ using namespace Platform; +using namespace Shared::Util; const uint64 MIN_BYTES_TO_COMPRESS = 12; static std::string getSupportCompressedTextureFormatString(int format) { - std::string result = intToStr(format); + std::string result = intToStr(format) + "[" + intToHex(format) + "]"; switch(format) { case GL_COMPRESSED_ALPHA: result = "GL_COMPRESSED_ALPHA"; @@ -58,6 +60,182 @@ static std::string getSupportCompressedTextureFormatString(int format) { case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: result = "GL_COMPRESSED_RGBA_S3TC_DXT5_EXT"; break; + +/* + case GL_COMPRESSED_SRGB: + result = "GL_COMPRESSED_SRGB"; + break; + + case GL_COMPRESSED_SRGB_ALPHA: + result = "GL_COMPRESSED_SRGB_ALPHA"; + break; + + case GL_COMPRESSED_SLUMINANCE: + result = "GL_COMPRESSED_SLUMINANCE"; + break; + + case GL_COMPRESSED_SLUMINANCE_ALPHA: + result = "GL_COMPRESSED_SLUMINANCE_ALPHA"; + break; + + case GL_COMPRESSED_RED: + result = "GL_COMPRESSED_RED"; + break; + + case GL_COMPRESSED_RG: + result = "GL_COMPRESSED_RG"; + break; + + case GL_COMPRESSED_RED_RGTC1: + result = "GL_COMPRESSED_RED_RGTC1"; + break; + + case GL_COMPRESSED_SIGNED_RED_RGTC1: + result = "GL_COMPRESSED_SIGNED_RED_RGTC1"; + break; + + case GL_COMPRESSED_RG_RGTC2: + result = "GL_COMPRESSED_RG_RGTC2"; + break; + + case GL_COMPRESSED_SIGNED_RG_RGTC2: + result = "GL_COMPRESSED_SIGNED_RG_RGTC2"; + break; + + case GL_COMPRESSED_RGBA_BPTC_UNORM_ARB: + result = "GL_COMPRESSED_RGBA_BPTC_UNORM_ARB"; + break; + + case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB: + result = "GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB"; + break; + + case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB: + result = "GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB"; + break; + + case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB: + result = "GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB"; + break; +*/ + case GL_COMPRESSED_RGB_FXT1_3DFX: + result = "GL_COMPRESSED_RGB_FXT1_3DFX"; + break; + + case GL_COMPRESSED_RGBA_FXT1_3DFX: + result = "GL_COMPRESSED_RGBA_FXT1_3DFX"; + break; + +/* + case GL_COMPRESSED_SRGB_EXT: + result = "GL_COMPRESSED_SRGB_EXT"; + break; + + case GL_COMPRESSED_SRGB_ALPHA_EXT: + result = "GL_COMPRESSED_SRGB_ALPHA_EXT"; + break; + + case GL_COMPRESSED_SLUMINANCE_EXT: + result = "GL_COMPRESSED_SLUMINANCE_EXT"; + break; + + case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT: + result = "GL_COMPRESSED_SLUMINANCE_ALPHA_EXT"; + break; + + case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: + result = "GL_COMPRESSED_SRGB_S3TC_DXT1_EXT"; + break; + + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: + result = "GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT"; + break; + + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: + result = "GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT"; + break; + + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: + result = "GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT"; + break; + + + case GL_COMPRESSED_LUMINANCE_LATC1_EXT: + result = "GL_COMPRESSED_LUMINANCE_LATC1_EXT"; + break; + + case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT: + result = "GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT"; + break; + + case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT: + result = "GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT"; + break; + + case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT: + result = "GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT"; + break; + + case GL_COMPRESSED_RED_RGTC1_EXT: + result = "GL_COMPRESSED_RED_RGTC1_EXT"; + break; + + case GL_COMPRESSED_SIGNED_RED_RGTC1_EXT: + result = "GL_COMPRESSED_SIGNED_RED_RGTC1_EXT"; + break; + + case GL_COMPRESSED_RED_GREEN_RGTC2_EXT: + result = "GL_COMPRESSED_RED_GREEN_RGTC2_EXT"; + break; + + case GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT: + result = "GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT"; + break; +*/ + +/* +#define GL_COMPRESSED_SRGB 0x8C48 +#define GL_COMPRESSED_SRGB_ALPHA 0x8C49 + +#define GL_COMPRESSED_SLUMINANCE 0x8C4A +#define GL_COMPRESSED_SLUMINANCE_ALPHA 0x8C4B + +#define GL_COMPRESSED_RED 0x8225 +#define GL_COMPRESSED_RG 0x8226 + +#define GL_COMPRESSED_RED_RGTC1 0x8DBB +#define GL_COMPRESSED_SIGNED_RED_RGTC1 0x8DBC +#define GL_COMPRESSED_RG_RGTC2 0x8DBD +#define GL_COMPRESSED_SIGNED_RG_RGTC2 0x8DBE + +#define GL_COMPRESSED_RGBA_BPTC_UNORM_ARB 0x8E8C +#define GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB 0x8E8D +#define GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB 0x8E8E +#define GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB 0x8E8F + +#define GL_COMPRESSED_RGB_FXT1_3DFX 0x86B0 +#define GL_COMPRESSED_RGBA_FXT1_3DFX 0x86B1 + +#define GL_COMPRESSED_SRGB_EXT 0x8C48 +#define GL_COMPRESSED_SRGB_ALPHA_EXT 0x8C49 +#define GL_COMPRESSED_SLUMINANCE_EXT 0x8C4A +#define GL_COMPRESSED_SLUMINANCE_ALPHA_EXT 0x8C4B +#define GL_COMPRESSED_SRGB_S3TC_DXT1_EXT 0x8C4C +#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT 0x8C4D +#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT 0x8C4E +#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT 0x8C4F + +#define GL_COMPRESSED_LUMINANCE_LATC1_EXT 0x8C70 +#define GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT 0x8C71 +#define GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT 0x8C72 +#define GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT 0x8C73 + +#define GL_COMPRESSED_RED_RGTC1_EXT 0x8DBB +#define GL_COMPRESSED_SIGNED_RED_RGTC1_EXT 0x8DBC +#define GL_COMPRESSED_RED_GREEN_RGTC2_EXT 0x8DBD +#define GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT 0x8DBE +*/ + } return result; } @@ -115,18 +293,38 @@ GLint toCompressionFormatGl(GLint format) { //GL_COMPRESSED_RGBA_S3TC_DXT3_EXT //GL_COMPRESSED_RGBA_S3TC_DXT5_EXT +#define GL_COMPRESSED_RGB_FXT1_3DFX 0x86B0 +#define GL_COMPRESSED_RGBA_FXT1_3DFX 0x86B1 + switch(format) { case GL_LUMINANCE: case GL_LUMINANCE8: return GL_COMPRESSED_LUMINANCE; case GL_RGB: case GL_RGB8: - return GL_COMPRESSED_RGB; - //return GL_COMPRESSED_RGB_S3TC_DXT1_EXT; + if(std::find(supportedCompressionFormats.begin(),supportedCompressionFormats.end(),GL_COMPRESSED_RGB_S3TC_DXT1_EXT) != supportedCompressionFormats.end()) { + return GL_COMPRESSED_RGB_S3TC_DXT1_EXT; + } + else if(std::find(supportedCompressionFormats.begin(),supportedCompressionFormats.end(),GL_COMPRESSED_RGB) != supportedCompressionFormats.end()) { + return GL_COMPRESSED_RGB; + } + else if(std::find(supportedCompressionFormats.begin(),supportedCompressionFormats.end(),GL_COMPRESSED_RGB_FXT1_3DFX) != supportedCompressionFormats.end()) { + return GL_COMPRESSED_RGB_FXT1_3DFX; + } + case GL_RGBA: case GL_RGBA8: - return GL_COMPRESSED_RGBA; - //return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; + + if(std::find(supportedCompressionFormats.begin(),supportedCompressionFormats.end(),GL_COMPRESSED_RGBA_S3TC_DXT5_EXT) != supportedCompressionFormats.end()) { + return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; + } + else if(std::find(supportedCompressionFormats.begin(),supportedCompressionFormats.end(),GL_COMPRESSED_RGBA) != supportedCompressionFormats.end()) { + return GL_COMPRESSED_RGBA; + } + else if(std::find(supportedCompressionFormats.begin(),supportedCompressionFormats.end(),GL_COMPRESSED_RGBA_FXT1_3DFX) != supportedCompressionFormats.end()) { + return GL_COMPRESSED_RGBA_FXT1_3DFX; + } + case GL_ALPHA: case GL_ALPHA8: return GL_COMPRESSED_ALPHA; @@ -291,14 +489,16 @@ void Texture1DGl::init(Filter filter, int maxAnisotropy) { assertGl(); } -void Texture1DGl::end() { +void Texture1DGl::end(bool deletePixelBuffer) { if(inited == true) { assertGl(); glDeleteTextures(1, &handle); assertGl(); handle=0; inited=false; - deletePixels(); + if(deletePixelBuffer == true) { + deletePixels(); + } } } @@ -386,7 +586,7 @@ void Texture2DGl::init(Filter filter, int maxAnisotropy) { assertGl(); } -void Texture2DGl::end() { +void Texture2DGl::end(bool deletePixelBuffer) { if(inited == true) { //printf("==> Deleting GL Texture [%s] handle = %d\n",getPath().c_str(),handle); assertGl(); @@ -394,7 +594,9 @@ void Texture2DGl::end() { assertGl(); handle=0; inited=false; - deletePixels(); + if(deletePixelBuffer == true) { + deletePixels(); + } } } @@ -457,15 +659,16 @@ void Texture3DGl::init(Filter filter, int maxAnisotropy) { assertGl(); } -void Texture3DGl::end() { +void Texture3DGl::end(bool deletePixelBuffer) { if(inited == true) { assertGl(); glDeleteTextures(1, &handle); assertGl(); - handle=0; inited=false; - deletePixels(); + if(deletePixelBuffer == true) { + deletePixels(); + } } } @@ -555,15 +758,16 @@ void TextureCubeGl::init(Filter filter, int maxAnisotropy) { assertGl(); } -void TextureCubeGl::end() { +void TextureCubeGl::end(bool deletePixelBuffer) { if(inited == true) { assertGl(); glDeleteTextures(1, &handle); assertGl(); - handle=0; inited=false; - deletePixels(); + if(deletePixelBuffer == true) { + deletePixels(); + } } } diff --git a/source/shared_lib/sources/graphics/texture_manager.cpp b/source/shared_lib/sources/graphics/texture_manager.cpp index 98854db2..d1f1a248 100644 --- a/source/shared_lib/sources/graphics/texture_manager.cpp +++ b/source/shared_lib/sources/graphics/texture_manager.cpp @@ -84,6 +84,9 @@ void TextureManager::init(bool forceInit) { if(forceInit == true) { texture->reseInitState(); } + if(forceInit == true) { + texture->end(false); + } texture->init(textureFilter, maxAnisotropy); } }