From 8da46ef9dcf2773dbfb284457acefa63170b7432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 2 Oct 2024 22:04:54 +0200 Subject: [PATCH] GL: advertise fake MAGNUM_compressed_texture_astc_{ldr,hdr}. Because everything is a trash fire. Ugh. --- doc/opengl-support.dox | 1 + src/Magnum/GL/Context.cpp | 2 + src/Magnum/GL/Extensions.h | 3 ++ .../GL/Implementation/driverSpecific.cpp | 46 +++++++++++++++++++ 4 files changed, 52 insertions(+) diff --git a/doc/opengl-support.dox b/doc/opengl-support.dox index 5502a3ec9..983accc90 100644 --- a/doc/opengl-support.dox +++ b/doc/opengl-support.dox @@ -580,6 +580,7 @@ Extension | Status @webgl_extension{EXT,depth_clamp} | done @webgl_extension{EXT,texture_mirror_clamp_to_edge} | done @webgl_extension{KHR,parallel_shader_compile} | done +`MAGNUM_compressed_texture_astc_ldr`, \n `MAGNUM_compressed_texture_astc_hdr` \n @m_span{m-text m-dim} Pseudo-extension denoting support for \n @webgl_extension{WEBGL,compressed_texture_astc} LDR and HDR profile @m_endspan | done @webgl_extension{NV,shader_noperspective_interpolation} | done (shading language only) @webgl_extension{OES,texture_float_linear} | done @webgl_extension{OES,draw_buffers_indexed} \n (originally named `EXT_draw_buffers_indexed`) | done diff --git a/src/Magnum/GL/Context.cpp b/src/Magnum/GL/Context.cpp index 57dea1ab3..a0a18d52b 100644 --- a/src/Magnum/GL/Context.cpp +++ b/src/Magnum/GL/Context.cpp @@ -300,6 +300,8 @@ constexpr Extension ExtensionList[]{ Extensions::EXT::texture_norm16{}, #endif Extensions::KHR::parallel_shader_compile{}, + Extensions::MAGNUM::compressed_texture_astc_hdr{}, + Extensions::MAGNUM::compressed_texture_astc_ldr{}, #ifndef MAGNUM_TARGET_GLES2 Extensions::NV::shader_noperspective_interpolation{}, Extensions::OES::draw_buffers_indexed{}, diff --git a/src/Magnum/GL/Extensions.h b/src/Magnum/GL/Extensions.h index 9de9cc8ed..fbf1d8f3c 100644 --- a/src/Magnum/GL/Extensions.h +++ b/src/Magnum/GL/Extensions.h @@ -365,6 +365,7 @@ namespace ANGLE { /* WEBGL_compressed_texture_etc1 (24) not exposed as the ES OES_compressed_ETC1_RGB8_texture extension isn't exposed either */ _extension(49,WEBGL,compressed_texture_etc, GLES200, None) // #29 + /* Also MAGNUM_compressed_texture_astc{_ldr,_hdr} below */ _extension(50,WEBGL,compressed_texture_astc, GLES200, None) // #30 _extension(51,WEBGL,compressed_texture_s3tc_srgb, GLES200, None) // #32 _extension(52,WEBGL,multi_draw, GLES200, None) // #40 @@ -390,6 +391,8 @@ namespace ANGLE { #ifndef MAGNUM_TARGET_GLES2 _extension(61,MAGNUM,shader_vertex_id, GLES300, GLES300) #endif + _extension(62,MAGNUM,compressed_texture_astc_ldr,GLES200, None) + _extension(63,MAGNUM,compressed_texture_astc_hdr,GLES200, None) } #else namespace ANDROID { diff --git a/src/Magnum/GL/Implementation/driverSpecific.cpp b/src/Magnum/GL/Implementation/driverSpecific.cpp index e4148ad5d..b6f4daf81 100644 --- a/src/Magnum/GL/Implementation/driverSpecific.cpp +++ b/src/Magnum/GL/Implementation/driverSpecific.cpp @@ -762,6 +762,52 @@ void Context::setupDriverWorkarounds() { #endif #endif + /* WEBGL_compressed_texture_astc has an extremely silly way of reporting + whether the LDR or HDR profile is supported. All other platforms simply + expose a _hdr / _ldr variants of the extension, here I have to call some + fucking getter. Restore sanity and provide this info in fake + Magnum-specific MAGNUM_compressed_texture_astc_ldr / _hdr extensions + instead. + + What's the most funny about this is that the extension at + https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_astc/ + explicitly says that + The intent of the getSupportedProfiles function is to allow easy + reconstruction of the underlying OpenGL or OpenGL ES extension strings + for environments like Emscripten, by prepending the string GL_KHR_texture_compression_astc_ to the returned profile names. + Which ... is a noble _intent_, but it only misses one small thing, to + have someone actually TELL THE EMSCRIPTEN DEVS TO IMPLEMENT SUCH A + THING!!! Which of course never happened. Since 2015. Goddamit. + + And even then, still, why couldn't you just do it like ALL OTHER + PLATFORMS? WHY SUCH A STUPID SPECIAL CASE?! */ + #ifdef MAGNUM_TARGET_WEBGL + if(isExtensionSupported()) { + /* Unlike other EM_ASM() macros, this one isn't put into a JS library + as it neither has any dependencies nor has code that may benefit + from settings-based preprocessing done for minification */ + #pragma GCC diagnostic push + /* Fun. It's either -Wdollar-in-identifier-extension if an argument is + used, or -Wgnu-zero-variadic-macro-arguments if not, OR + -Wc++20-extensions if it's a different Clang version. TRASH FIRE. */ + #pragma GCC diagnostic ignored "-Wdollar-in-identifier-extension" + const UnsignedInt which = EM_ASM_INT({ + /* If this feels like peeking into some undocumented Emscripten + internals that are likely going to change randomly at some point + in the future, it's because it's indeed peeking into some + undocumented Emscripten internals that are likely going to + change randomly at some point in the future. HAVE FUN. */ + var supported = GL.contexts[$0].GLctx.getExtension('WEBGL_compressed_texture_astc').getSupportedProfiles(); + return + (supported.indexOf('ldr') >= 0 ? 1 : 0)| + (supported.indexOf('hdr') >= 0 ? 2 : 0); + }, emscripten_webgl_get_current_context()); + #pragma GCC diagnostic pop + _extensionStatus.set(Extensions::MAGNUM::compressed_texture_astc_ldr::Index, which & 0x01); + _extensionStatus.set(Extensions::MAGNUM::compressed_texture_astc_hdr::Index, which & 0x02); + } + #endif + #undef _setRequiredVersion #ifndef MAGNUM_TARGET_GLES