Skip to content

Commit

Permalink
Remove -s USE_WEBGL2=1 and replace it with -s GL_MIN_FEATURE_LEVEL=10…
Browse files Browse the repository at this point in the history
…/20 and -s GL_MAX_FEATURE_LEVEL=10/20
  • Loading branch information
juj committed Dec 12, 2019
1 parent 2fe4315 commit 5039b28
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 79 deletions.
3 changes: 3 additions & 0 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,9 @@ def is_supported_link_flag(f):
# stb_image 2.x need to have STB_IMAGE_IMPLEMENTATION defined to include the implementation when compiling
newargs.append('-DSTB_IMAGE_IMPLEMENTATION')

if shared.Settings.USE_WEBGL2:
shared.Settings.GL_MAX_FEATURE_LEVEL = 20

forced_stdlibs = []

if shared.Settings.ASMFS and final_suffix in JS_CONTAINING_ENDINGS:
Expand Down
2 changes: 1 addition & 1 deletion site/source/docs/optimizing/Optimizing-WebGL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ By default, if no special GL related linker flags are chosen, Emscripten targets

- 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.

- 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).
- 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).

How To Profile WebGL
====================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ To program against the WebGL subset of OpenGL ES, one uses the GL ES 2.0 header

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

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.
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.

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``.

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

Expand Down
6 changes: 5 additions & 1 deletion src/library_browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,14 @@ var LibraryBrowser = {
var contextAttributes = {
antialias: false,
alpha: false,
#if USE_WEBGL2 // library_browser.js defaults: use the WebGL version chosen at compile time (unless overridden below)
#if GL_MIN_FEATURE_LEVEL >= 20
majorVersion: 2,
#else
#if GL_MAX_FEATURE_LEVEL >= 20 // library_browser.js defaults: use the WebGL version chosen at compile time (unless overridden below)
majorVersion: (typeof WebGL2RenderingContext !== 'undefined') ? 2 : 1,
#else
majorVersion: 1,
#endif
#endif
};

Expand Down
4 changes: 2 additions & 2 deletions src/library_egl.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,14 @@ var LibraryEGL = {
}
contextAttribs += 8;
}
#if USE_WEBGL2
#if GL_MAX_FEATURE_LEVEL >= 20
if (glesContextVersion < 2 || glesContextVersion > 3) {
#else
if (glesContextVersion != 2) {
#endif
#if GL_ASSERTIONS
if (glesContextVersion == 3) {
err('When initializing GLES3/WebGL2 via EGL, one must build with -s USE_WEBGL2=1 !');
err('When initializing GLES3/WebGL2 via EGL, one must build with -s GL_MAX_FEATURE_LEVEL=20 !');
} else {
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!');
}
Expand Down
2 changes: 1 addition & 1 deletion src/library_glemu.js
Original file line number Diff line number Diff line change
Expand Up @@ -3339,7 +3339,7 @@ var LibraryGLEmulation = {
glRotatef: 'glRotated',

glDrawBuffer: function() { throw 'glDrawBuffer: TODO' },
#if !USE_WEBGL2
#if GL_MAX_FEATURE_LEVEL < 20
glReadBuffer: function() { throw 'glReadBuffer: TODO' },
#endif

Expand Down
Loading

0 comments on commit 5039b28

Please sign in to comment.