diff options
author | Bartosz Taudul <wolf@nereid.pl> | 2022-10-15 13:56:19 +0300 |
---|---|---|
committer | Bartosz Taudul <wolf@nereid.pl> | 2022-10-15 13:56:19 +0300 |
commit | fdb130651de99cbe67116351808c91e09c08c014 (patch) | |
tree | 5f6082ab20a4b31d2c14b0506bb27aac1da93eb3 | |
parent | 5b1c1119c501e583f5a486809b837b657fc462c8 (diff) |
Detect if hardware supports S3TC.
-rw-r--r-- | profiler/src/main.cpp | 1 | ||||
-rw-r--r-- | server/TracyTexture.cpp | 28 | ||||
-rw-r--r-- | server/TracyTexture.hpp | 1 |
3 files changed, 29 insertions, 1 deletions
diff --git a/profiler/src/main.cpp b/profiler/src/main.cpp index 6035b590..a579564b 100644 --- a/profiler/src/main.cpp +++ b/profiler/src/main.cpp @@ -221,6 +221,7 @@ int main( int argc, char** argv ) ImGuiTracyContext imguiContext; Backend backend( title, DrawContents, &mainThreadTasks ); + tracy::InitTexture(); iconTex = tracy::MakeTexture(); iconThread.join(); backend.SetIcon( iconPx, iconX, iconY ); diff --git a/server/TracyTexture.cpp b/server/TracyTexture.cpp index 1fa748c2..dd07751f 100644 --- a/server/TracyTexture.cpp +++ b/server/TracyTexture.cpp @@ -1,6 +1,7 @@ #include <inttypes.h> #ifdef __EMSCRIPTEN__ +# include <emscripten/html5.h> # include <GLES2/gl2.h> #else # include "../profiler/src/imgui/imgui_impl_opengl3_loader.h" @@ -14,6 +15,28 @@ namespace tracy { +static bool s_hardwareS3tc; + +void InitTexture() +{ +#ifdef __EMSCRIPTEN__ + s_hardwareS3tc = emscripten_webgl_enable_extension( emscripten_webgl_get_current_context(), "WEBGL_compressed_texture_s3tc" ); +#else + s_hardwareS3tc = false; + GLint num; + glGetIntegerv( GL_NUM_EXTENSIONS, &num ); + for( GLint i=0; i<num; i++ ) + { + auto ext = (const char*)glGetStringi( GL_EXTENSIONS, GLuint( i ) ); + if( strcmp( ext, "GL_EXT_texture_compression_s3tc" ) == 0 ) + { + s_hardwareS3tc = true; + break; + } + } +#endif +} + void* MakeTexture() { GLuint tex; @@ -36,7 +59,10 @@ void UpdateTexture( void* _tex, const char* data, int w, int h ) { auto tex = (GLuint)(intptr_t)_tex; glBindTexture( GL_TEXTURE_2D, tex ); - glCompressedTexImage2D( GL_TEXTURE_2D, 0, COMPRESSED_RGB_S3TC_DXT1_EXT, w, h, 0, w * h / 2, data ); + if( s_hardwareS3tc ) + { + glCompressedTexImage2D( GL_TEXTURE_2D, 0, COMPRESSED_RGB_S3TC_DXT1_EXT, w, h, 0, w * h / 2, data ); + } } void UpdateTextureRGBA( void* _tex, void* data, int w, int h ) diff --git a/server/TracyTexture.hpp b/server/TracyTexture.hpp index 128834da..bcc8a455 100644 --- a/server/TracyTexture.hpp +++ b/server/TracyTexture.hpp @@ -6,6 +6,7 @@ namespace tracy { +void InitTexture(); void* MakeTexture(); void FreeTexture( void* tex, void(*runOnMainThread)(std::function<void()>, bool) ); void UpdateTexture( void* tex, const char* data, int w, int h ); |