Skip to content

Commit eb9493c

Browse files
committed
Remove -s USE_WEBGL2=1 and replace it with -s GL_MIN_FEATURE_LEVEL=10/20 and -s GL_MAX_FEATURE_LEVEL=10/20
1 parent 2fe4315 commit eb9493c

File tree

15 files changed

+96
-78
lines changed

15 files changed

+96
-78
lines changed

emcc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,9 @@ def is_supported_link_flag(f):
12691269
# stb_image 2.x need to have STB_IMAGE_IMPLEMENTATION defined to include the implementation when compiling
12701270
newargs.append('-DSTB_IMAGE_IMPLEMENTATION')
12711271

1272+
if shared.Settings.USE_WEBGL2:
1273+
shared.Settings.GL_MAX_FEATURE_LEVEL = 20
1274+
12721275
forced_stdlibs = []
12731276

12741277
if shared.Settings.ASMFS and final_suffix in JS_CONTAINING_ENDINGS:

site/source/docs/optimizing/Optimizing-WebGL.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ By default, if no special GL related linker flags are chosen, Emscripten targets
2525

2626
- When targeting OpenGL ES 3, if one needs to render from client side memory, or the use of ``glMapBuffer*()`` API is needed, pass the linker flag ``-s FULL_ES3=1`` to emulate these features, which core WebGL 2 does not have. This emulation is expected to hurt performance, so using VBOs is recommended instead.
2727

28-
- Even if your application does not need any WebGL 2/OpenGL ES 3 features, consider porting the application to run on WebGL 2, because JavaScript side performance in WebGL 2 has been optimized to generate no temporary garbage, which has been observed to give a solid 3-7% speed improvement, as well as reducing potential stuttering at render time. To enable these optimizations, build with the linker flag ``-s USE_WEBGL2=1`` and make sure to create a WebGL 2 context at GL startup time (OpenGL ES 3 context if using EGL).
28+
- Even if your application does not need any WebGL 2/OpenGL ES 3 features, consider porting the application to run on WebGL 2, because JavaScript side performance in WebGL 2 has been optimized to generate no temporary garbage, which has been observed to give a solid 3-7% speed improvement, as well as reducing potential stuttering at render time. To enable these optimizations, build with the linker flag ``-s GL_MAX_FEATURE_LEVEL=20`` and make sure to create a WebGL 2 context at GL startup time (OpenGL ES 3 context if using EGL).
2929

3030
How To Profile WebGL
3131
====================

site/source/docs/porting/multimedia_and_graphics/OpenGL-support.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ To program against the WebGL subset of OpenGL ES, one uses the GL ES 2.0 header
2525

2626
This mode is used by default because it best matches the WebGL features brovided by browsers.
2727

28-
To target WebGL 2, pass the linker flag ``-s USE_WEBGL2=1``. Specifying this flag enables (and defaults to, unless otherwise specified at context creation time) the creation of WebGL 2 contexts at runtime, but it is still possible to create WebGL 1 contexts, so applications can choose whether to require WebGL 2 or whether to support a fallback to WebGL 1.
28+
To target WebGL 2, pass the linker flag ``-s GL_MAX_FEATURE_LEVEL=20``. Specifying this flag enables (and defaults to, unless otherwise specified at context creation time) the creation of WebGL 2 contexts at runtime, but it is still possible to create WebGL 1 contexts, so applications can choose whether to require WebGL 2 or whether to support a fallback to WebGL 1.
29+
30+
To only target WebGL 2 and drop support for WebGL 1 altogether to save code size, pass the linker flags ``-s GL_MIN_FEATURE_LEVEL=20`` and ``-s GL_MAX_FEATURE_LEVEL=20``.
2931

3032
.. _opengl-support-opengl-es2-0-emulation:
3133

src/library_browser.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,14 @@ var LibraryBrowser = {
312312
var contextAttributes = {
313313
antialias: false,
314314
alpha: false,
315-
#if USE_WEBGL2 // library_browser.js defaults: use the WebGL version chosen at compile time (unless overridden below)
315+
#if GL_MIN_FEATURE_LEVEL >= 20
316+
majorVersion: 2,
317+
#else
318+
#if GL_MAX_FEATURE_LEVEL >= 20 // library_browser.js defaults: use the WebGL version chosen at compile time (unless overridden below)
316319
majorVersion: (typeof WebGL2RenderingContext !== 'undefined') ? 2 : 1,
317320
#else
318321
majorVersion: 1,
322+
#endif
319323
#endif
320324
};
321325

src/library_egl.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,14 +345,14 @@ var LibraryEGL = {
345345
}
346346
contextAttribs += 8;
347347
}
348-
#if USE_WEBGL2
348+
#if GL_MAX_FEATURE_LEVEL >= 20
349349
if (glesContextVersion < 2 || glesContextVersion > 3) {
350350
#else
351351
if (glesContextVersion != 2) {
352352
#endif
353353
#if GL_ASSERTIONS
354354
if (glesContextVersion == 3) {
355-
err('When initializing GLES3/WebGL2 via EGL, one must build with -s USE_WEBGL2=1 !');
355+
err('When initializing GLES3/WebGL2 via EGL, one must build with -s GL_MAX_FEATURE_LEVEL=20 !');
356356
} else {
357357
err('When initializing GLES2/WebGL1 via EGL, one must pass EGL_CONTEXT_CLIENT_VERSION = 2 to GL context attributes! GLES version ' + glesContextVersion + ' is not supported!');
358358
}

src/library_glemu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3339,7 +3339,7 @@ var LibraryGLEmulation = {
33393339
glRotatef: 'glRotated',
33403340

33413341
glDrawBuffer: function() { throw 'glDrawBuffer: TODO' },
3342-
#if !USE_WEBGL2
3342+
#if GL_MAX_FEATURE_LEVEL < 20
33433343
glReadBuffer: function() { throw 'glReadBuffer: TODO' },
33443344
#endif
33453345

0 commit comments

Comments
 (0)