Skip to content

Commit dcf6dff

Browse files
authored
Fix WebGL context attribute handling for enableExtensionsByDefault and explicitSwapControl, and work around Chrome behavior that it does not return powerPreference in context attributes. (#7996)
1 parent c45433c commit dcf6dff

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/library_gl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ var LibraryGL = {
767767
registerContext: function(ctx, webGLContextAttributes) {
768768
var handle = _malloc(8); // Make space on the heap to store GL context attributes that need to be accessible as shared between threads.
769769
#if GL_SUPPORT_EXPLICIT_SWAP_CONTROL
770-
{{{ makeSetValue('handle', 0, 'webGLContextAttributes["explicitSwapControl"]', 'i32')}}}; // explicitSwapControl
770+
{{{ makeSetValue('handle', 0, 'webGLContextAttributes.explicitSwapControl', 'i32')}}}; // explicitSwapControl
771771
#endif
772772
#if USE_PTHREADS
773773
{{{ makeSetValue('handle', 4, '_pthread_self()', 'i32')}}}; // the thread pointer of the thread that owns the control of the context

src/library_html5.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2361,16 +2361,16 @@ var LibraryJSEvents = {
23612361
{{{ makeSetValue('a', C_STRUCTS.EmscriptenWebGLContextAttributes.antialias, 't.antialias', 'i32') }}};
23622362
{{{ makeSetValue('a', C_STRUCTS.EmscriptenWebGLContextAttributes.premultipliedAlpha, 't.premultipliedAlpha', 'i32') }}};
23632363
{{{ makeSetValue('a', C_STRUCTS.EmscriptenWebGLContextAttributes.preserveDrawingBuffer, 't.preserveDrawingBuffer', 'i32') }}};
2364-
var power = __emscripten_webgl_power_preferences.indexOf(t['powerPreference']);
2364+
var power = t['powerPreference'] && __emscripten_webgl_power_preferences.indexOf(t['powerPreference']);
23652365
{{{ makeSetValue('a', C_STRUCTS.EmscriptenWebGLContextAttributes.powerPreference, 'power', 'i32') }}};
23662366
{{{ makeSetValue('a', C_STRUCTS.EmscriptenWebGLContextAttributes.failIfMajorPerformanceCaveat, 't.failIfMajorPerformanceCaveat', 'i32') }}};
23672367
{{{ makeSetValue('a', C_STRUCTS.EmscriptenWebGLContextAttributes.majorVersion, 'c.version', 'i32') }}};
23682368
{{{ makeSetValue('a', C_STRUCTS.EmscriptenWebGLContextAttributes.minorVersion, 0, 'i32') }}};
23692369
#if GL_SUPPORT_AUTOMATIC_ENABLE_EXTENSIONS
2370-
{{{ makeSetValue('a', C_STRUCTS.EmscriptenWebGLContextAttributes.enableExtensionsByDefault, 'c.attributes["enableExtensionsByDefault"]', 'i32') }}};
2370+
{{{ makeSetValue('a', C_STRUCTS.EmscriptenWebGLContextAttributes.enableExtensionsByDefault, 'c.attributes.enableExtensionsByDefault', 'i32') }}};
23712371
#endif
23722372
#if GL_SUPPORT_EXPLICIT_SWAP_CONTROL
2373-
{{{ makeSetValue('a', C_STRUCTS.EmscriptenWebGLContextAttributes.explicitSwapControl, 'c.attributes["explicitSwapControl"]', 'i32') }}};
2373+
{{{ makeSetValue('a', C_STRUCTS.EmscriptenWebGLContextAttributes.explicitSwapControl, 'c.attributes.explicitSwapControl', 'i32') }}};
23742374
#endif
23752375
return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
23762376
},

0 commit comments

Comments
 (0)