diff --git a/source/shared_lib/sources/graphics/gl/texture_gl.cpp b/source/shared_lib/sources/graphics/gl/texture_gl.cpp index fe172aab5..e3178daa8 100644 --- a/source/shared_lib/sources/graphics/gl/texture_gl.cpp +++ b/source/shared_lib/sources/graphics/gl/texture_gl.cpp @@ -10,12 +10,12 @@ // ============================================================== #include "texture_gl.h" - #include - #include "opengl.h" -#include "leak_dumper.h" #include +#include + +#include "leak_dumper.h" using namespace std; @@ -25,11 +25,83 @@ using namespace Platform; const uint64 MIN_BYTES_TO_COMPRESS = 12; +static std::string getSupportCompressedTextureFormatString(int format) { + std::string result = intToStr(format); + switch(format) { + case GL_COMPRESSED_ALPHA: + result = "GL_COMPRESSED_ALPHA"; + break; + case GL_COMPRESSED_LUMINANCE: + result = "GL_COMPRESSED_LUMINANCE"; + break; + case GL_COMPRESSED_LUMINANCE_ALPHA: + result = "GL_COMPRESSED_LUMINANCE_ALPHA"; + break; + case GL_COMPRESSED_INTENSITY: + result = "GL_COMPRESSED_INTENSITY"; + break; + case GL_COMPRESSED_RGB: + result = "GL_COMPRESSED_RGB"; + break; + case GL_COMPRESSED_RGBA: + result = "GL_COMPRESSED_RGBA"; + break; + case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: + result = "GL_COMPRESSED_RGB_S3TC_DXT1_EXT"; + break; + case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: + result = "GL_COMPRESSED_RGBA_S3TC_DXT1_EXT"; + break; + case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: + result = "GL_COMPRESSED_RGBA_S3TC_DXT3_EXT"; + break; + case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: + result = "GL_COMPRESSED_RGBA_S3TC_DXT5_EXT"; + break; + } + return result; +} + +static int getNumCompressedTextureFormats() { + int numCompressedTextureFormats = 0; + glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numCompressedTextureFormats); + return numCompressedTextureFormats; +} + +static std::vector getSupportCompressedTextureFormats() { + std::vector result; + int count = getNumCompressedTextureFormats(); + if(count > 0) { + int *formats = new int[count]; + glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS,&formats[0]); + + for(int i = 0; i < count; ++i) { + result.push_back(formats[i]); + } + delete [] formats; + } + + if(Texture::useTextureCompression == true) { + printf("------------------------------------------------\n"); + printf("**** getSupportCompressedTextureFormats() result.size() = %d, count = %d\n",(int)result.size(),count); + for(int i = 0; i < result.size(); ++i) { + printf("Texture Compression #i = %d, result[i] = %d [%s]\n",i,result[i],getSupportCompressedTextureFormatString(result[i]).c_str()); + } + printf("------------------------------------------------\n"); + } + return result; +} + GLint toCompressionFormatGl(GLint format) { if(Texture::useTextureCompression == false) { return format; } + static std::vector supportedCompressionFormats = getSupportCompressedTextureFormats(); + if(supportedCompressionFormats.size() <= 0) { + return format; + } + //GL_COMPRESSED_ALPHA <- white things but tile ok! //GL_COMPRESSED_LUMINANCE <- black tiles //GL_COMPRESSED_LUMINANCE_ALPHA <- black tiles