Skip to content

Commit e6e3bf2

Browse files
committed
Include GL extension fliter/allowlist if and only if its needed
1 parent 9888e61 commit e6e3bf2

File tree

6 files changed

+82
-73
lines changed

6 files changed

+82
-73
lines changed

src/library_glemu.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@
66

77
var LibraryGLEmulation = {
88
// GL emulation: provides misc. functionality not present in OpenGL ES 2.0 or WebGL
9-
$GLEmulation__deps: ['$GLImmediateSetup', 'glEnable', 'glDisable', 'glIsEnabled', 'glGetBooleanv', 'glGetIntegerv', 'glGetString', 'glCreateShader', 'glShaderSource', 'glCompileShader', 'glAttachShader', 'glDetachShader', 'glUseProgram', 'glDeleteProgram', 'glBindAttribLocation', 'glLinkProgram', 'glBindBuffer', 'glGetFloatv', 'glHint', 'glEnableVertexAttribArray', 'glDisableVertexAttribArray', 'glVertexAttribPointer', 'glActiveTexture', '$stringToNewUTF8', '$ptrToString'],
9+
$GLEmulation__deps: ['$GLImmediateSetup', 'glEnable', 'glDisable',
10+
'glIsEnabled', 'glGetBooleanv', 'glGetIntegerv', 'glGetString',
11+
'glCreateShader', 'glShaderSource', 'glCompileShader', 'glAttachShader',
12+
'glDetachShader', 'glUseProgram', 'glDeleteProgram', 'glBindAttribLocation',
13+
'glLinkProgram', 'glBindBuffer', 'glGetFloatv', 'glHint',
14+
'glEnableVertexAttribArray', 'glDisableVertexAttribArray',
15+
'glVertexAttribPointer', 'glActiveTexture', '$stringToNewUTF8',
16+
'$ptrToString', '$getEmscriptenSupportedExtensions',
17+
],
1018
$GLEmulation__postset:
1119
#if MAYBE_CLOSURE_COMPILER
1220
// Forward declare GL functions that are overridden by GLEmulation here to appease Closure compiler.
@@ -394,7 +402,7 @@ var LibraryGLEmulation = {
394402
if (GL.stringCache[name_]) return GL.stringCache[name_];
395403
switch (name_) {
396404
case 0x1F03 /* GL_EXTENSIONS */: // Add various extensions that we can support
397-
var ret = stringToNewUTF8((GLctx.getSupportedExtensions() || []).join(' ') +
405+
var ret = stringToNewUTF8(getEmscriptenSupportedExtensions(GLctx).join(' ') +
398406
' GL_EXT_texture_env_combine GL_ARB_texture_env_crossbar GL_ATI_texture_env_combine3 GL_NV_texture_env_combine4 GL_EXT_texture_env_dot3 GL_ARB_multitexture GL_ARB_vertex_buffer_object GL_EXT_framebuffer_object GL_ARB_vertex_program GL_ARB_fragment_program GL_ARB_shading_language_100 GL_ARB_shader_objects GL_ARB_vertex_shader GL_ARB_fragment_shader GL_ARB_texture_cube_map GL_EXT_draw_range_elements' +
399407
(GL.currentContext.compressionExt ? ' GL_ARB_texture_compression GL_EXT_texture_compression_s3tc' : '') +
400408
(GL.currentContext.anisotropicExt ? ' GL_EXT_texture_filter_anisotropic' : '')

src/library_glew.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121

2222
var LibraryGLEW = {
23-
$GLEW__deps: ['glGetString', '$stringToNewUTF8', '$UTF8ToString'],
23+
$GLEW__deps: ['glGetString', '$stringToNewUTF8', '$UTF8ToString', '$glGetExtensions'],
2424
$GLEW: {
2525
isLinaroFork: 1,
2626
extensions: null,
@@ -99,7 +99,7 @@ var LibraryGLEW = {
9999
},
100100

101101
extensionIsSupported(name) {
102-
GLEW.extensions ||= GL.getExtensions();
102+
GLEW.extensions ||= glGetExtensions();
103103

104104
if (GLEW.extensions.includes(name))
105105
return 1;

src/library_glfw.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,9 +1467,9 @@ var LibraryGLFW = {
14671467
GLFW.initialTime = GLFW.getTime() - time;
14681468
},
14691469

1470-
glfwExtensionSupported__deps: ['glGetString'],
1470+
glfwExtensionSupported__deps: ['glGetString', 'glGetExtensions'],
14711471
glfwExtensionSupported: (extension) => {
1472-
GLFW.extensions ||= GL.getExtensions();
1472+
GLFW.extensions ||= glGetExtensions();
14731473

14741474
if (GLFW.extensions.includes(extension)) return 1;
14751475

src/library_html5_webgl.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,9 @@ var LibraryHtml5WebGL = {
439439
},
440440

441441
emscripten_webgl_get_supported_extensions__proxy: 'sync_on_current_webgl_context_thread',
442-
emscripten_webgl_get_supported_extensions__deps: ['$stringToNewUTF8'],
442+
emscripten_webgl_get_supported_extensions__deps: ['$stringToNewUTF8', '$getEmscriptenSupportedExtensions'],
443443
emscripten_webgl_get_supported_extensions: () =>
444-
stringToNewUTF8(GLctx.getSupportedExtensions().join(' ')),
444+
stringToNewUTF8(getEmscriptenSupportedExtensions(GLctx).join(' ')),
445445

446446
emscripten_webgl_get_program_parameter_d__proxy: 'sync_on_current_webgl_context_thread',
447447
emscripten_webgl_get_program_parameter_d: (program, param) =>

src/library_webgl.js

Lines changed: 64 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,54 @@ 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+
var supportedExtensionsForGetProcAddress = [
141+
#if MIN_WEBGL_VERSION == 1
142+
// WebGL 1 extensions
143+
'ANGLE_instanced_arrays',
144+
'EXT_blend_minmax',
145+
'EXT_disjoint_timer_query',
146+
'EXT_frag_depth',
147+
'EXT_shader_texture_lod',
148+
'EXT_sRGB',
149+
'OES_element_index_uint',
150+
'OES_fbo_render_mipmap',
151+
'OES_standard_derivatives',
152+
'OES_texture_float',
153+
'OES_texture_half_float',
154+
'OES_texture_half_float_linear',
155+
'OES_vertex_array_object',
156+
'WEBGL_color_buffer_float',
157+
'WEBGL_depth_texture',
158+
'WEBGL_draw_buffers',
159+
#endif
160+
#if MAX_WEBGL_VERSION >= 2
161+
// WebGL 2 extensions
162+
'EXT_color_buffer_float',
163+
'EXT_disjoint_timer_query_webgl2',
164+
'EXT_texture_norm16',
165+
'WEBGL_clip_cull_distance',
166+
#endif
167+
// WebGL 1 and WebGL 2 extensions
168+
'EXT_color_buffer_half_float',
169+
'EXT_float_blend',
170+
'EXT_texture_compression_bptc',
171+
'EXT_texture_compression_rgtc',
172+
'EXT_texture_filter_anisotropic',
173+
'KHR_parallel_shader_compile',
174+
'OES_texture_float_linear',
175+
'WEBGL_compressed_texture_s3tc',
176+
'WEBGL_compressed_texture_s3tc_srgb',
177+
'WEBGL_debug_renderer_info',
178+
'WEBGL_debug_shaders',
179+
'WEBGL_lose_context',
180+
'WEBGL_multi_draw',
181+
];
182+
// .getSupportedExtensions() can return null if context is lost, so coerce to empty array.
183+
return (ctx.getSupportedExtensions() || []).filter(ext => supportedExtensionsForGetProcAddress.includes(ext));;
184+
},
185+
138186
$GL__postset: 'var GLctx;',
139187
#if GL_SUPPORT_AUTOMATIC_ENABLE_EXTENSIONS
140188
// If GL_SUPPORT_AUTOMATIC_ENABLE_EXTENSIONS is enabled, GL.initExtensions() will call to initialize these.
@@ -739,58 +787,6 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
739787
disableHalfFloatExtensionIfBroken(ctx);
740788
#endif
741789

742-
// If end user enables *glGetProcAddress() functionality, then we must filter out
743-
// all future WebGL extensions from being passed to the user, and only restrict to advertising
744-
// extensions that the *glGetProcAddress() function knows to handle.
745-
#if GL_ENABLE_GET_PROC_ADDRESS
746-
var _allSupportedExtensions = ctx.getSupportedExtensions;
747-
var supportedExtensionsForGetProcAddress = [
748-
#if MIN_WEBGL_VERSION == 1
749-
// WebGL 1 extensions
750-
'ANGLE_instanced_arrays',
751-
'EXT_blend_minmax',
752-
'EXT_disjoint_timer_query',
753-
'EXT_frag_depth',
754-
'EXT_shader_texture_lod',
755-
'EXT_sRGB',
756-
'OES_element_index_uint',
757-
'OES_fbo_render_mipmap',
758-
'OES_standard_derivatives',
759-
'OES_texture_float',
760-
'OES_texture_half_float',
761-
'OES_texture_half_float_linear',
762-
'OES_vertex_array_object',
763-
'WEBGL_color_buffer_float',
764-
'WEBGL_depth_texture',
765-
'WEBGL_draw_buffers',
766-
#endif
767-
#if MAX_WEBGL_VERSION >= 2
768-
// WebGL 2 extensions
769-
'EXT_color_buffer_float',
770-
'EXT_disjoint_timer_query_webgl2',
771-
'EXT_texture_norm16',
772-
'WEBGL_clip_cull_distance',
773-
#endif
774-
// WebGL 1 and WebGL 2 extensions
775-
'EXT_color_buffer_half_float',
776-
'EXT_float_blend',
777-
'EXT_texture_compression_bptc',
778-
'EXT_texture_compression_rgtc',
779-
'EXT_texture_filter_anisotropic',
780-
'KHR_parallel_shader_compile',
781-
'OES_texture_float_linear',
782-
'WEBGL_compressed_texture_s3tc',
783-
'WEBGL_compressed_texture_s3tc_srgb',
784-
'WEBGL_debug_renderer_info',
785-
'WEBGL_debug_shaders',
786-
'WEBGL_lose_context',
787-
'WEBGL_multi_draw',
788-
];
789-
ctx.getSupportedExtensions = function() {
790-
return (_allSupportedExtensions.apply(this) || []).filter(ext => supportedExtensionsForGetProcAddress.includes(ext));
791-
}
792-
#endif
793-
794790
return handle;
795791
},
796792

@@ -1219,14 +1215,16 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
12191215
},
12201216
#endif
12211217

1222-
getExtensions() {
1223-
// .getSupportedExtensions() can return null if context is lost, so coerce to empty array.
1224-
var exts = GLctx.getSupportedExtensions() || [];
1218+
},
1219+
1220+
$glGetExtensions__internal: true,
1221+
$glGetExtensions__deps: ['$getEmscriptenSupportedExtensions'],
1222+
$glGetExtensions(ctx) {
1223+
var exts = getEmscriptenSupportedExtensions(ctx);
12251224
#if GL_EXTENSIONS_IN_PREFIXED_FORMAT
1226-
exts = exts.concat(exts.map((e) => "GL_" + e));
1225+
exts = exts.concat(exts.map((e) => "GL_" + e));
12271226
#endif
1228-
return exts;
1229-
},
1227+
return exts;
12301228
},
12311229

12321230
glPixelStorei: (pname, param) => {
@@ -1236,13 +1234,13 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
12361234
GLctx.pixelStorei(pname, param);
12371235
},
12381236

1239-
glGetString__deps: ['$stringToNewUTF8'],
1237+
glGetString__deps: ['$stringToNewUTF8', '$glGetExtensions'],
12401238
glGetString: (name_) => {
12411239
var ret = GL.stringCache[name_];
12421240
if (!ret) {
12431241
switch (name_) {
12441242
case 0x1F03 /* GL_EXTENSIONS */:
1245-
ret = stringToNewUTF8(GL.getExtensions().join(' '));
1243+
ret = stringToNewUTF8(glGetExtensions().join(' '));
12461244
break;
12471245
case 0x1F00 /* GL_VENDOR */:
12481246
case 0x1F01 /* GL_RENDERER */:
@@ -1304,7 +1302,11 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
13041302
return ret;
13051303
},
13061304

1307-
$emscriptenWebGLGet__deps: ['$writeI53ToI64'],
1305+
$emscriptenWebGLGet__deps: ['$writeI53ToI64',
1306+
#if MAX_WEBGL_VERSION >= 2
1307+
'$getEmscriptenSupportedExtensions'
1308+
#endif
1309+
],
13081310
$emscriptenWebGLGet: (name_, p, type) => {
13091311
// Guard against user passing a null pointer.
13101312
// Note that GLES2 spec does not say anything about how passing a null
@@ -1367,8 +1369,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
13671369
return;
13681370
}
13691371
#endif
1370-
// .getSupportedExtensions() can return null if context is lost, so coerce to empty array.
1371-
var exts = GLctx.getSupportedExtensions() || [];
1372+
var exts = getEmscriptenSupportedExtensions(GLctx);
13721373
#if GL_EXTENSIONS_IN_PREFIXED_FORMAT
13731374
// each extension is duplicated, first in unprefixed WebGL form, and
13741375
// then a second time with "GL_" prefix.

src/library_webgl2.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
var LibraryWebGL2 = {
8-
glGetStringi__deps: ['$stringToNewUTF8'],
8+
glGetStringi__deps: ['$glGetExtensions', '$stringToNewUTF8'],
99
glGetStringi: (name, index) => {
1010
if (GL.currentContext.version < 2) {
1111
GL.recordError(0x502 /* GL_INVALID_OPERATION */); // Calling GLES3/WebGL2 function with a GLES2/WebGL1 context
@@ -24,7 +24,7 @@ var LibraryWebGL2 = {
2424
}
2525
switch (name) {
2626
case 0x1F03 /* GL_EXTENSIONS */:
27-
var exts = GL.getExtensions().map((e) => stringToNewUTF8(e));
27+
var exts = glGetExtensions().map((e) => stringToNewUTF8(e));
2828
stringiCache = GL.stringiCache[name] = exts;
2929
if (index < 0 || index >= stringiCache.length) {
3030
GL.recordError(0x501/*GL_INVALID_VALUE*/);

0 commit comments

Comments
 (0)