diff --git a/src/library_html5_webgl.js b/src/library_html5_webgl.js index 468fe487c642..370e7b8a25b9 100644 --- a/src/library_html5_webgl.js +++ b/src/library_html5_webgl.js @@ -20,31 +20,6 @@ var LibraryHtml5WebGL = { return len; }, - // Execute in calling thread without proxying needed. - emscripten_webgl_init_context_attributes: (attributes) => { -#if ASSERTIONS - assert(attributes); -#endif - var a = attributes >> 2; - for (var i = 0; i < ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.__size__ }}}>>2); ++i) { - HEAP32[a+i] = 0; - } - - HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.alpha }}}>>2)] = - HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.depth }}}>>2)] = - HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.antialias }}}>>2)] = - HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.premultipliedAlpha }}}>>2)] = - HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.majorVersion }}}>>2)] = - HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.enableExtensionsByDefault }}}>>2)] = 1; - -#if PTHREADS - // Default context initialization state (user can override): - // - if main thread is creating the context, default to the context not being shared between threads - enabling sharing has performance overhead, because it forces the context to be OffscreenCanvas or OffscreenFramebuffer. - // - if a web worker is creating the context, default to using OffscreenCanvas if available, or proxying via Offscreen Framebuffer if not - if (ENVIRONMENT_IS_WORKER) {{{ makeSetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.proxyContextToMainThread, 1/*EMSCRIPTEN_WEBGL_CONTEXT_PROXY_FALLBACK*/, 'i32') }}}; -#endif - }, - $emscripten_webgl_power_preferences: "['default', 'low-power', 'high-performance']", #if PTHREADS && OFFSCREEN_FRAMEBUFFER diff --git a/src/library_sigs.js b/src/library_sigs.js index a5ba65f943ad..c4839c260d24 100644 --- a/src/library_sigs.js +++ b/src/library_sigs.js @@ -884,7 +884,6 @@ sigs = { emscripten_webgl_get_vertex_attrib_d__sig: 'dii', emscripten_webgl_get_vertex_attrib_o__sig: 'iii', emscripten_webgl_get_vertex_attrib_v__sig: 'iiipii', - emscripten_webgl_init_context_attributes__sig: 'vp', emscripten_webgl_make_context_current__sig: 'ip', emscripten_webgpu_export_bind_group__sig: 'ip', emscripten_webgpu_export_bind_group_layout__sig: 'ip', diff --git a/system/lib/gl/webgl1.c b/system/lib/gl/webgl1.c index 85e8cc392423..cbe6f4693d94 100644 --- a/system/lib/gl/webgl1.c +++ b/system/lib/gl/webgl1.c @@ -17,6 +17,28 @@ #include "webgl_internal.h" +void emscripten_webgl_init_context_attributes(EmscriptenWebGLContextAttributes *attributes) { + memset(attributes, 0, sizeof(*attributes)); + + attributes->alpha = 1; + attributes->depth = 1; + attributes->antialias = 1; + attributes->premultipliedAlpha = 1; + attributes->majorVersion = 1; + attributes->enableExtensionsByDefault = 1; + + // Default context initialization state (user can override): + // - if main thread is creating the context, default to the context not being + // shared between threads - enabling sharing has performance overhead, + // because it forces the context to be OffscreenCanvas or + // OffscreenFramebuffer. + // - if a web worker is creating the context, default to using OffscreenCanvas + // if available, or proxying via Offscreen Framebuffer if not + if (!emscripten_is_main_runtime_thread()) { + attributes->proxyContextToMainThread = EMSCRIPTEN_WEBGL_CONTEXT_PROXY_FALLBACK; + } +} + #if defined(__EMSCRIPTEN_PTHREADS__) && defined(__EMSCRIPTEN_OFFSCREEN_FRAMEBUFFER__) static pthread_key_t currentActiveWebGLContext; diff --git a/test/code_size/hello_webgl2_wasm.json b/test/code_size/hello_webgl2_wasm.json index 708a528a29e1..35b3a0dc95e9 100644 --- a/test/code_size/hello_webgl2_wasm.json +++ b/test/code_size/hello_webgl2_wasm.json @@ -1,10 +1,10 @@ { "a.html": 569, "a.html.gz": 379, - "a.js": 4681, - "a.js.gz": 2412, - "a.wasm": 10388, - "a.wasm.gz": 6692, - "total": 15638, - "total_gz": 9483 + "a.js": 4593, + "a.js.gz": 2372, + "a.wasm": 10451, + "a.wasm.gz": 6724, + "total": 15613, + "total_gz": 9475 } diff --git a/test/code_size/hello_webgl2_wasm2js.json b/test/code_size/hello_webgl2_wasm2js.json index 823857f3e7a8..b30c2e5a62c2 100644 --- a/test/code_size/hello_webgl2_wasm2js.json +++ b/test/code_size/hello_webgl2_wasm2js.json @@ -1,10 +1,10 @@ { "a.html": 567, "a.html.gz": 379, - "a.js": 17917, - "a.js.gz": 8089, + "a.js": 17937, + "a.js.gz": 8077, "a.mem": 3123, "a.mem.gz": 2693, - "total": 21607, - "total_gz": 11161 + "total": 21627, + "total_gz": 11149 } diff --git a/test/code_size/hello_webgl_wasm.json b/test/code_size/hello_webgl_wasm.json index 1d73a396b738..6509ee225edb 100644 --- a/test/code_size/hello_webgl_wasm.json +++ b/test/code_size/hello_webgl_wasm.json @@ -1,10 +1,10 @@ { "a.html": 569, "a.html.gz": 379, - "a.js": 4167, - "a.js.gz": 2236, - "a.wasm": 10388, - "a.wasm.gz": 6692, - "total": 15124, - "total_gz": 9307 + "a.js": 4080, + "a.js.gz": 2201, + "a.wasm": 10451, + "a.wasm.gz": 6724, + "total": 15100, + "total_gz": 9304 } diff --git a/test/code_size/hello_webgl_wasm2js.json b/test/code_size/hello_webgl_wasm2js.json index cb6d778b2b99..74c11e4b34e3 100644 --- a/test/code_size/hello_webgl_wasm2js.json +++ b/test/code_size/hello_webgl_wasm2js.json @@ -1,10 +1,10 @@ { "a.html": 567, "a.html.gz": 379, - "a.js": 17395, - "a.js.gz": 7900, + "a.js": 17415, + "a.js.gz": 7894, "a.mem": 3123, "a.mem.gz": 2693, - "total": 21085, - "total_gz": 10972 + "total": 21105, + "total_gz": 10966 } diff --git a/test/test_browser.py b/test/test_browser.py index b38a3a85385c..5182b42d66a3 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -4690,9 +4690,9 @@ def test_webgl_timer_query(self, args): 'threads': (['-pthread', '-sPROXY_TO_PTHREAD'],) }) @parameterized({ - 'v1': ([],), - 'v2': (['-sFULL_ES2'],), - 'v3': (['-sFULL_ES3'],), + '': ([],), + 'es2': (['-sFULL_ES2'],), + 'es3': (['-sFULL_ES3'],), }) def test_webgl_offscreen_framebuffer(self, version, threads): # Tests all the different possible versions of libgl diff --git a/test/test_other.py b/test/test_other.py index 3e8c49fecd4d..7191bc1120e8 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -10545,7 +10545,7 @@ def test_minimal_runtime_code_size(self, test_name, js, compare_js_output=False) hello_webgl_sources = [test_file('minimal_webgl/main.c'), test_file('minimal_webgl/webgl.c'), '--js-library', test_file('minimal_webgl/library_js.js'), - '-lwebgl.js', + '-lGL', '-sMODULARIZE'] hello_webgl2_sources = hello_webgl_sources + ['-sMAX_WEBGL_VERSION=2'] hello_wasm_worker_sources = [test_file('wasm_worker/wasm_worker_code_size.c'), '-sWASM_WORKERS', '-sENVIRONMENT=web,worker']