Merge pull request #93560 from dsnopek/webxr-emscripten-3151

[Web] Fix checking for OpenGL extensions with Emscripten 3.1.51 and later
This commit is contained in:
Rémi Verschelde 2024-06-25 09:20:01 +02:00
commit 1a0190270f
No known key found for this signature in database
GPG Key ID: C3336907360768E1
1 changed files with 22 additions and 0 deletions

View File

@ -35,6 +35,10 @@
#include "../rasterizer_gles3.h"
#include "texture_storage.h"
#ifdef WEB_ENABLED
#include <emscripten/html5_webgl.h>
#endif
using namespace GLES3;
#define _GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
@ -44,6 +48,23 @@ Config *Config::singleton = nullptr;
Config::Config() {
singleton = this;
#ifdef WEB_ENABLED
// Starting with Emscripten 3.1.51, glGetStringi(GL_EXTENSIONS, i) will only ever return
// a fixed list of extensions, regardless of what additional extensions are enabled. This
// isn't very useful for us in determining which extensions we can rely on here. So, instead
// we use emscripten_webgl_get_supported_extensions() to get all supported extensions, which
// is what Emscripten 3.1.50 and earlier do.
{
char *extension_array_string = emscripten_webgl_get_supported_extensions();
PackedStringArray extension_array = String((const char *)extension_array_string).split(" ");
extensions.reserve(extension_array.size() * 2);
for (const String &s : extension_array) {
extensions.insert(s);
extensions.insert("GL_" + s);
}
free(extension_array_string);
}
#else
{
GLint max_extensions = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &max_extensions);
@ -55,6 +76,7 @@ Config::Config() {
extensions.insert((const char *)s);
}
}
#endif
bptc_supported = extensions.has("GL_ARB_texture_compression_bptc") || extensions.has("EXT_texture_compression_bptc");
astc_supported = extensions.has("GL_KHR_texture_compression_astc") || extensions.has("GL_OES_texture_compression_astc") || extensions.has("GL_KHR_texture_compression_astc_ldr") || extensions.has("GL_KHR_texture_compression_astc_hdr");