@@ -135,6 +135,56 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
135135 emscripten_webgl_enable_WEBGL_multi_draw__deps : [ '$webgl_enable_WEBGL_multi_draw' ] ,
136136 emscripten_webgl_enable_WEBGL_multi_draw : ( ctx ) => webgl_enable_WEBGL_multi_draw ( GL . contexts [ ctx ] . GLctx ) ,
137137
138+ $getEmscriptenSupportedExtensions__internal : true ,
139+ $getEmscriptenSupportedExtensions : function ( ctx ) {
140+ // Restrict the list of advertised extensions to those that we actually
141+ // support.
142+ var supportedExtensions = [
143+ #if MIN_WEBGL_VERSION == 1
144+ // WebGL 1 extensions
145+ 'ANGLE_instanced_arrays' ,
146+ 'EXT_blend_minmax' ,
147+ 'EXT_disjoint_timer_query' ,
148+ 'EXT_frag_depth' ,
149+ 'EXT_shader_texture_lod' ,
150+ 'EXT_sRGB' ,
151+ 'OES_element_index_uint' ,
152+ 'OES_fbo_render_mipmap' ,
153+ 'OES_standard_derivatives' ,
154+ 'OES_texture_float' ,
155+ 'OES_texture_half_float' ,
156+ 'OES_texture_half_float_linear' ,
157+ 'OES_vertex_array_object' ,
158+ 'WEBGL_color_buffer_float' ,
159+ 'WEBGL_depth_texture' ,
160+ 'WEBGL_draw_buffers' ,
161+ #endif
162+ #if MAX_WEBGL_VERSION >= 2
163+ // WebGL 2 extensions
164+ 'EXT_color_buffer_float' ,
165+ 'EXT_disjoint_timer_query_webgl2' ,
166+ 'EXT_texture_norm16' ,
167+ 'WEBGL_clip_cull_distance' ,
168+ #endif
169+ // WebGL 1 and WebGL 2 extensions
170+ 'EXT_color_buffer_half_float' ,
171+ 'EXT_float_blend' ,
172+ 'EXT_texture_compression_bptc' ,
173+ 'EXT_texture_compression_rgtc' ,
174+ 'EXT_texture_filter_anisotropic' ,
175+ 'KHR_parallel_shader_compile' ,
176+ 'OES_texture_float_linear' ,
177+ 'WEBGL_compressed_texture_s3tc' ,
178+ 'WEBGL_compressed_texture_s3tc_srgb' ,
179+ 'WEBGL_debug_renderer_info' ,
180+ 'WEBGL_debug_shaders' ,
181+ 'WEBGL_lose_context' ,
182+ 'WEBGL_multi_draw' ,
183+ ] ;
184+ // .getSupportedExtensions() can return null if context is lost, so coerce to empty array.
185+ return ( ctx . getSupportedExtensions ( ) || [ ] ) . filter ( ext => supportedExtensions . includes ( ext ) ) ;
186+ } ,
187+
138188 $GL__postset : 'var GLctx;' ,
139189#if GL_SUPPORT_AUTOMATIC_ENABLE_EXTENSIONS
140190 // If GL_SUPPORT_AUTOMATIC_ENABLE_EXTENSIONS is enabled, GL.initExtensions() will call to initialize these.
@@ -153,8 +203,9 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
153203 '$webgl_enable_WEBGL_multi_draw_instanced_base_vertex_base_instance' ,
154204#endif
155205 '$webgl_enable_WEBGL_multi_draw' ,
206+ '$getEmscriptenSupportedExtensions' ,
156207 ] ,
157- #endif
208+ #endif // GL_SUPPORT_AUTOMATIC_ENABLE_EXTENSIONS
158209 $GL : {
159210#if GL_DEBUG
160211 debug : true ,
@@ -738,60 +789,6 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
738789 }
739790 disableHalfFloatExtensionIfBroken ( ctx ) ;
740791#endif
741-
742- // If end user enables *glGetProcAddress() functionality or
743- // GL_SUPPORT_AUTOMATIC_ENABLE_EXTENSIONS, then we must filter out
744- // all future WebGL extensions from being passed to the user, and only restrict to advertising
745- // extensions that the *glGetProcAddress() function knows to handle.
746- #if GL_ENABLE_GET_PROC_ADDRESS || GL_SUPPORT_AUTOMATIC_ENABLE_EXTENSIONS
747- var _allSupportedExtensions = ctx . getSupportedExtensions ;
748- var supportedExtensionsForGetProcAddress = [
749- #if MIN_WEBGL_VERSION == 1
750- // WebGL 1 extensions
751- 'ANGLE_instanced_arrays' ,
752- 'EXT_blend_minmax' ,
753- 'EXT_disjoint_timer_query' ,
754- 'EXT_frag_depth' ,
755- 'EXT_shader_texture_lod' ,
756- 'EXT_sRGB' ,
757- 'OES_element_index_uint' ,
758- 'OES_fbo_render_mipmap' ,
759- 'OES_standard_derivatives' ,
760- 'OES_texture_float' ,
761- 'OES_texture_half_float' ,
762- 'OES_texture_half_float_linear' ,
763- 'OES_vertex_array_object' ,
764- 'WEBGL_color_buffer_float' ,
765- 'WEBGL_depth_texture' ,
766- 'WEBGL_draw_buffers' ,
767- #endif
768- #if MAX_WEBGL_VERSION >= 2
769- // WebGL 2 extensions
770- 'EXT_color_buffer_float' ,
771- 'EXT_disjoint_timer_query_webgl2' ,
772- 'EXT_texture_norm16' ,
773- 'WEBGL_clip_cull_distance' ,
774- #endif
775- // WebGL 1 and WebGL 2 extensions
776- 'EXT_color_buffer_half_float' ,
777- 'EXT_float_blend' ,
778- 'EXT_texture_compression_bptc' ,
779- 'EXT_texture_compression_rgtc' ,
780- 'EXT_texture_filter_anisotropic' ,
781- 'KHR_parallel_shader_compile' ,
782- 'OES_texture_float_linear' ,
783- 'WEBGL_compressed_texture_s3tc' ,
784- 'WEBGL_compressed_texture_s3tc_srgb' ,
785- 'WEBGL_debug_renderer_info' ,
786- 'WEBGL_debug_shaders' ,
787- 'WEBGL_lose_context' ,
788- 'WEBGL_multi_draw' ,
789- ] ;
790- ctx . getSupportedExtensions = function ( ) {
791- return ( _allSupportedExtensions . apply ( this ) || [ ] ) . filter ( ext => supportedExtensionsForGetProcAddress . includes ( ext ) ) ;
792- }
793- #endif
794-
795792 return handle ;
796793 } ,
797794
@@ -1206,10 +1203,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
12061203
12071204 webgl_enable_WEBGL_multi_draw ( GLctx ) ;
12081205
1209- // .getSupportedExtensions() can return null if context is lost, so coerce
1210- // to empty array.
1211- var exts = GLctx . getSupportedExtensions ( ) || [ ] ;
1212- exts . forEach ( ( ext ) => {
1206+ getEmscriptenSupportedExtensions ( GLctx ) . forEach ( ( ext ) => {
12131207 // WEBGL_lose_context, WEBGL_debug_renderer_info and WEBGL_debug_shaders
12141208 // are not enabled by default.
12151209 if ( ! ext . includes ( 'lose_context' ) && ! ext . includes ( 'debug' ) ) {
@@ -1220,14 +1214,16 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
12201214 } ,
12211215#endif
12221216
1223- getExtensions ( ) {
1224- // .getSupportedExtensions() can return null if context is lost, so coerce to empty array.
1225- var exts = GLctx . getSupportedExtensions ( ) || [ ] ;
1217+ } ,
1218+
1219+ $webglGetExtensions__internal : true ,
1220+ $webglGetExtensions__deps : [ '$getEmscriptenSupportedExtensions' ] ,
1221+ $webglGetExtensions ( ) {
1222+ var exts = getEmscriptenSupportedExtensions ( GLctx ) ;
12261223#if GL_EXTENSIONS_IN_PREFIXED_FORMAT
1227- exts = exts . concat ( exts . map ( ( e ) => "GL_" + e ) ) ;
1224+ exts = exts . concat ( exts . map ( ( e ) => "GL_" + e ) ) ;
12281225#endif
1229- return exts ;
1230- } ,
1226+ return exts ;
12311227 } ,
12321228
12331229 glPixelStorei : ( pname , param ) => {
@@ -1237,13 +1233,13 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
12371233 GLctx . pixelStorei ( pname , param ) ;
12381234 } ,
12391235
1240- glGetString__deps : [ '$stringToNewUTF8' ] ,
1236+ glGetString__deps : [ '$stringToNewUTF8' , '$webglGetExtensions' ] ,
12411237 glGetString : ( name_ ) => {
12421238 var ret = GL . stringCache [ name_ ] ;
12431239 if ( ! ret ) {
12441240 switch ( name_ ) {
12451241 case 0x1F03 /* GL_EXTENSIONS */ :
1246- ret = stringToNewUTF8 ( GL . getExtensions ( ) . join ( ' ' ) ) ;
1242+ ret = stringToNewUTF8 ( webglGetExtensions ( ) . join ( ' ' ) ) ;
12471243 break ;
12481244 case 0x1F00 /* GL_VENDOR */ :
12491245 case 0x1F01 /* GL_RENDERER */ :
@@ -1305,7 +1301,11 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
13051301 return ret ;
13061302 } ,
13071303
1308- $emscriptenWebGLGet__deps : [ '$writeI53ToI64' ] ,
1304+ $emscriptenWebGLGet__deps : [ '$writeI53ToI64' ,
1305+ #if MAX_WEBGL_VERSION >= 2
1306+ '$webglGetExtensions' , // For GL_NUM_EXTENSIONS
1307+ #endif
1308+ ] ,
13091309 $emscriptenWebGLGet : ( name_ , p , type ) = > {
13101310 // Guard against user passing a null pointer.
13111311 // Note that GLES2 spec does not say anything about how passing a null
@@ -1368,15 +1368,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
13681368 return ;
13691369 }
13701370#endif
1371- // .getSupportedExtensions() can return null if context is lost, so coerce to empty array.
1372- var exts = GLctx . getSupportedExtensions ( ) || [ ] ;
1373- #if GL_EXTENSIONS_IN_PREFIXED_FORMAT
1374- // each extension is duplicated, first in unprefixed WebGL form, and
1375- // then a second time with "GL_" prefix.
1376- ret = 2 * exts . length ;
1377- #else
1378- ret = exts . length ;
1379- #endif
1371+ ret = webglGetExtensions ( ) . length ;
13801372 break ;
13811373 case 0x821B : // GL_MAJOR_VERSION
13821374 case 0x821C : // GL_MINOR_VERSION
0 commit comments