Skip to content

Commit

Permalink
Rename to MIN_WEBGL_VERSION and MAX_WEBGL_VERSION
Browse files Browse the repository at this point in the history
  • Loading branch information
juj committed Dec 13, 2019
1 parent 4546f24 commit b54cd4b
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@ def is_supported_link_flag(f):
newargs.append('-DSTB_IMAGE_IMPLEMENTATION')

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

forced_stdlibs = []

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 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).
- 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 MAX_WEBGL_VERSION=2`` 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,9 +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 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 target WebGL 2, pass the linker flag ``-s MAX_WEBGL_VERSION=2``. 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``.
To only target WebGL 2 and drop support for WebGL 1 altogether to save code size, pass the linker flags ``-s MIN_WEBGL_VERSION=2`` and ``-s MAX_WEBGL_VERSION=2``.

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

Expand Down
4 changes: 2 additions & 2 deletions src/library_browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,10 @@ var LibraryBrowser = {
var contextAttributes = {
antialias: false,
alpha: false,
#if GL_MIN_FEATURE_LEVEL >= 20
#if MIN_WEBGL_VERSION >= 2
majorVersion: 2,
#else
#if GL_MAX_FEATURE_LEVEL >= 20 // library_browser.js defaults: use the WebGL version chosen at compile time (unless overridden below)
#if MAX_WEBGL_VERSION >= 2 // library_browser.js defaults: use the WebGL version chosen at compile time (unless overridden below)
majorVersion: (typeof WebGL2RenderingContext !== 'undefined') ? 2 : 1,
#else
majorVersion: 1,
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 GL_MAX_FEATURE_LEVEL < 20
#if MAX_WEBGL_VERSION < 2
glReadBuffer: function() { throw 'glReadBuffer: TODO' },
#endif

Expand Down
12 changes: 6 additions & 6 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,18 +442,18 @@ var GL_POOL_TEMP_BUFFERS = 1;
// bug is only relevant to WebGL 1, the affected browsers do not support WebGL 2.
var WORKAROUND_OLD_WEBGL_UNIFORM_UPLOAD_IGNORED_OFFSET_BUG = 0;

// Deprecated. Pass -s GL_MAX_FEATURE_LEVEL=20 to target WebGL 2.0.
// Deprecated. Pass -s MAX_WEBGL_VERSION=2 to target WebGL 2.0.
var USE_WEBGL2 = 0;

// Specifies the lowest WebGL version to target. Pass -s GL_MIN_FEATURE_LEVEL=10
// to enable targeting WebGL 1, and -s GL_MIN_FEATURE_LEVEL=20 to drop support
// Specifies the lowest WebGL version to target. Pass -s MIN_WEBGL_VERSION=1
// to enable targeting WebGL 1, and -s MIN_WEBGL_VERSION=2 to drop support
// for WebGL 1.0
var GL_MIN_FEATURE_LEVEL = 10;
var MIN_WEBGL_VERSION = 1;

// Specifies the highest WebGL version to target. Pass -s GL_MAX_FEATURE_LEVEL=20
// Specifies the highest WebGL version to target. Pass -s MAX_WEBGL_VERSION=2
// to enable targeting WebGL 2. If WebGL 2 is enabled, some APIs (EGL, GLUT, SDL)
// will default to creating a WebGL 2 context if no version is specified.
var GL_MAX_FEATURE_LEVEL = 10;
var MAX_WEBGL_VERSION = 1;

// If true, emulates some WebGL 1 features on WebGL 2 contexts, meaning that
// applications that use WebGL 1/GLES 2 can initialize a WebGL 2/GLES3 context,
Expand Down
36 changes: 18 additions & 18 deletions tests/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,7 @@ def test_gles2_emulation(self, args):

@requires_graphics_hardware
def test_clientside_vertex_arrays_es3(self):
self.btest('clientside_vertex_arrays_es3.c', reference='gl_triangle.png', args=['-s', 'GL_MAX_FEATURE_LEVEL=20', '-s', 'FULL_ES3=1', '-s', 'USE_GLFW=3', '-lglfw', '-lGLESv2'])
self.btest('clientside_vertex_arrays_es3.c', reference='gl_triangle.png', args=['-s', 'MAX_WEBGL_VERSION=2', '-s', 'FULL_ES3=1', '-s', 'USE_GLFW=3', '-lglfw', '-lGLESv2'])

def test_emscripten_api(self):
self.btest('emscripten_api_browser.cpp', '1', args=['-s', '''EXPORTED_FUNCTIONS=['_main', '_third']''', '-lSDL'])
Expand Down Expand Up @@ -2617,46 +2617,46 @@ def test_webgl2(self):
['-s', 'FULL_ES2=1'],
]:
print(opts)
self.btest(path_from_root('tests', 'webgl2.cpp'), args=['-s', 'GL_MAX_FEATURE_LEVEL=20', '-lGL'] + opts, expected='0')
self.btest(path_from_root('tests', 'webgl2.cpp'), args=['-s', 'MAX_WEBGL_VERSION=2', '-lGL'] + opts, expected='0')

@requires_graphics_hardware
@requires_threads
def test_webgl2_pthreads(self):
# test that a program can be compiled with pthreads and render WebGL2 properly on the main thread
# (the testcase doesn't even use threads, but is compiled with thread support).
self.btest(path_from_root('tests', 'webgl2.cpp'), args=['-s', 'GL_MAX_FEATURE_LEVEL=20', '-lGL', '-s', 'USE_PTHREADS=1'], expected='0')
self.btest(path_from_root('tests', 'webgl2.cpp'), args=['-s', 'MAX_WEBGL_VERSION=2', '-lGL', '-s', 'USE_PTHREADS=1'], expected='0')

def test_webgl2_objects(self):
self.btest(path_from_root('tests', 'webgl2_objects.cpp'), args=['-s', 'GL_MAX_FEATURE_LEVEL=20', '-lGL'], expected='0')
self.btest(path_from_root('tests', 'webgl2_objects.cpp'), args=['-s', 'MAX_WEBGL_VERSION=2', '-lGL'], expected='0')

def test_webgl2_ubos(self):
self.btest(path_from_root('tests', 'webgl2_ubos.cpp'), args=['-s', 'GL_MAX_FEATURE_LEVEL=20', '-lGL'], expected='0')
self.btest(path_from_root('tests', 'webgl2_ubos.cpp'), args=['-s', 'MAX_WEBGL_VERSION=2', '-lGL'], expected='0')

@requires_graphics_hardware
def test_webgl2_garbage_free_entrypoints(self):
self.btest(path_from_root('tests', 'webgl2_garbage_free_entrypoints.cpp'), args=['-s', 'GL_MAX_FEATURE_LEVEL=20', '-DTEST_WEBGL2=1'], expected='1')
self.btest(path_from_root('tests', 'webgl2_garbage_free_entrypoints.cpp'), args=['-s', 'MAX_WEBGL_VERSION=2', '-DTEST_WEBGL2=1'], expected='1')
self.btest(path_from_root('tests', 'webgl2_garbage_free_entrypoints.cpp'), expected='1')

@requires_graphics_hardware
def test_webgl2_backwards_compatibility_emulation(self):
self.btest(path_from_root('tests', 'webgl2_backwards_compatibility_emulation.cpp'), args=['-s', 'GL_MAX_FEATURE_LEVEL=20', '-s', 'WEBGL2_BACKWARDS_COMPATIBILITY_EMULATION=1'], expected='0')
self.btest(path_from_root('tests', 'webgl2_backwards_compatibility_emulation.cpp'), args=['-s', 'MAX_WEBGL_VERSION=2', '-s', 'WEBGL2_BACKWARDS_COMPATIBILITY_EMULATION=1'], expected='0')

@requires_graphics_hardware
def test_webgl2_invalid_teximage2d_type(self):
self.btest(path_from_root('tests', 'webgl2_invalid_teximage2d_type.cpp'), args=['-s', 'GL_MAX_FEATURE_LEVEL=20'], expected='0')
self.btest(path_from_root('tests', 'webgl2_invalid_teximage2d_type.cpp'), args=['-s', 'MAX_WEBGL_VERSION=2'], expected='0')

@requires_graphics_hardware
def test_webgl_with_closure(self):
self.btest(path_from_root('tests', 'webgl_with_closure.cpp'), args=['-O2', '-s', 'GL_MAX_FEATURE_LEVEL=20', '--closure', '1', '-lGL'], expected='0')
self.btest(path_from_root('tests', 'webgl_with_closure.cpp'), args=['-O2', '-s', 'MAX_WEBGL_VERSION=2', '--closure', '1', '-lGL'], expected='0')

# Tests that -s GL_ASSERTIONS=1 and glVertexAttribPointer with packed types works
@requires_graphics_hardware
def test_webgl2_packed_types(self):
self.btest(path_from_root('tests', 'webgl2_draw_packed_triangle.c'), args=['-lGL', '-s', 'GL_MAX_FEATURE_LEVEL=20', '-s', 'GL_ASSERTIONS=1'], expected='0')
self.btest(path_from_root('tests', 'webgl2_draw_packed_triangle.c'), args=['-lGL', '-s', 'MAX_WEBGL_VERSION=2', '-s', 'GL_ASSERTIONS=1'], expected='0')

@requires_graphics_hardware
def test_webgl2_pbo(self):
self.btest(path_from_root('tests', 'webgl2_pbo.cpp'), args=['-s', 'GL_MAX_FEATURE_LEVEL=20', '-lGL'], expected='0')
self.btest(path_from_root('tests', 'webgl2_pbo.cpp'), args=['-s', 'MAX_WEBGL_VERSION=2', '-lGL'], expected='0')

def test_sdl_touch(self):
for opts in [[], ['-O2', '-g1', '--closure', '1']]:
Expand Down Expand Up @@ -4293,16 +4293,16 @@ def test_webgl_vao_without_automatic_extensions(self):
def test_webgl_offscreen_framebuffer_state_restoration(self):
for args in [
# full state restoration path on WebGL 1.0
['-s', 'GL_MAX_FEATURE_LEVEL=10', '-s', 'OFFSCREEN_FRAMEBUFFER_FORBID_VAO_PATH=1'],
['-s', 'MAX_WEBGL_VERSION=1', '-s', 'OFFSCREEN_FRAMEBUFFER_FORBID_VAO_PATH=1'],
# VAO path on WebGL 1.0
['-s', 'GL_MAX_FEATURE_LEVEL=10'],
['-s', 'GL_MAX_FEATURE_LEVEL=20', '-DTEST_WEBGL2=0'],
['-s', 'MAX_WEBGL_VERSION=1'],
['-s', 'MAX_WEBGL_VERSION=2', '-DTEST_WEBGL2=0'],
# VAO path on WebGL 2.0
['-s', 'GL_MAX_FEATURE_LEVEL=20', '-DTEST_WEBGL2=1', '-DTEST_ANTIALIAS=1', '-DTEST_REQUIRE_VAO=1'],
['-s', 'MAX_WEBGL_VERSION=2', '-DTEST_WEBGL2=1', '-DTEST_ANTIALIAS=1', '-DTEST_REQUIRE_VAO=1'],
# full state restoration path on WebGL 2.0
['-s', 'GL_MAX_FEATURE_LEVEL=20', '-DTEST_WEBGL2=1', '-DTEST_ANTIALIAS=1', '-s', 'OFFSCREEN_FRAMEBUFFER_FORBID_VAO_PATH=1'],
['-s', 'MAX_WEBGL_VERSION=2', '-DTEST_WEBGL2=1', '-DTEST_ANTIALIAS=1', '-s', 'OFFSCREEN_FRAMEBUFFER_FORBID_VAO_PATH=1'],
# blitFramebuffer path on WebGL 2.0 (falls back to VAO on Firefox < 67)
['-s', 'GL_MAX_FEATURE_LEVEL=20', '-DTEST_WEBGL2=1', '-DTEST_ANTIALIAS=0'],
['-s', 'MAX_WEBGL_VERSION=2', '-DTEST_WEBGL2=1', '-DTEST_ANTIALIAS=0'],
]:
cmd = args + ['-lGL', '-s', 'OFFSCREEN_FRAMEBUFFER=1', '-DEXPLICIT_SWAP=1']
self.btest('webgl_offscreen_framebuffer_swap_with_bad_state.c', '0', args=cmd)
Expand All @@ -4315,7 +4315,7 @@ def test_webgl_workaround_webgl_uniform_upload_bug(self):
# Tests that using an array of structs in GL uniforms works.
@requires_graphics_hardware
def test_webgl_array_of_structs_uniform(self):
self.btest('webgl_array_of_structs_uniform.c', args=['-lGL', '-s', 'GL_MAX_FEATURE_LEVEL=20'], reference='webgl_array_of_structs_uniform.png')
self.btest('webgl_array_of_structs_uniform.c', args=['-lGL', '-s', 'MAX_WEBGL_VERSION=2'], reference='webgl_array_of_structs_uniform.png')

# Tests that if a WebGL context is created in a pthread on a canvas that has not been transferred to that pthread, WebGL calls are then proxied to the main thread
# -DTEST_OFFSCREEN_CANVAS=1: Tests that if a WebGL context is created on a pthread that has the canvas transferred to it via using Emscripten's EMSCRIPTEN_PTHREAD_TRANSFERRED_CANVASES="#canvas", then OffscreenCanvas is used
Expand Down
4 changes: 2 additions & 2 deletions tools/system_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ def get_cflags(self):
if self.is_legacy:
cflags += ['-DLEGACY_GL_EMULATION=1']
if self.is_webgl2:
cflags += ['-DGL_MAX_FEATURE_LEVEL=20', '-s', 'GL_MAX_FEATURE_LEVEL=20']
cflags += ['-DMAX_WEBGL_VERSION=2', '-s', 'MAX_WEBGL_VERSION=2']
if self.is_ofb:
cflags += ['-D__EMSCRIPTEN_OFFSCREEN_FRAMEBUFFER__']
if self.is_full_es3:
Expand All @@ -1042,7 +1042,7 @@ def vary_on(cls):
def get_default_variation(cls, **kwargs):
return super(libgl, cls).get_default_variation(
is_legacy=shared.Settings.LEGACY_GL_EMULATION,
is_webgl2=shared.Settings.GL_MAX_FEATURE_LEVEL >= 20,
is_webgl2=shared.Settings.MAX_WEBGL_VERSION >= 2,
is_ofb=shared.Settings.OFFSCREEN_FRAMEBUFFER,
is_full_es3=shared.Settings.FULL_ES3,
**kwargs
Expand Down

0 comments on commit b54cd4b

Please sign in to comment.