Ver código fonte

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

[Web] Fix checking for OpenGL extensions with Emscripten 3.1.51 and later
Rémi Verschelde 1 ano atrás
pai
commit
1a0190270f
1 arquivos alterados com 22 adições e 0 exclusões
  1. 22 0
      drivers/gles3/storage/config.cpp

+ 22 - 0
drivers/gles3/storage/config.cpp

@@ -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");