Skip to content

Commit b3edd4c

Browse files
authored
[OffscreenCanvas] Extract the canvas from the offscreenCanvases entry (#22958)
Fixes a type error in #22943 when creating a context with explicit swap control.
1 parent 8435293 commit b3edd4c

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/library_html5_webgl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ var LibraryHtml5WebGL = {
171171
#endif
172172
return 0;
173173
}
174-
canvas = GL.offscreenCanvases[canvas.id];
174+
canvas = GL.offscreenCanvases[canvas.id].canvas;
175175
}
176176
}
177177
#else // !OFFSCREENCANVAS_SUPPORT
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2024 The Emscripten Authors. All rights reserved.
2+
// Emscripten is available under two separate licenses, the MIT license and the
3+
// University of Illinois/NCSA Open Source License. Both these licenses can be
4+
// found in the LICENSE file.
5+
6+
#include <GLES2/gl2.h>
7+
#include <GLES2/gl2ext.h>
8+
#include <assert.h>
9+
10+
#include <emscripten/emscripten.h>
11+
#include <emscripten/html5.h>
12+
13+
int main() {
14+
EmscriptenWebGLContextAttributes attrs;
15+
emscripten_webgl_init_context_attributes(&attrs);
16+
attrs.explicitSwapControl = true;
17+
#ifdef USE_OFFSCREEN_FRAMEBUFFER
18+
attrs.renderViaOffscreenBackBuffer = true;
19+
#endif
20+
// Test that creating a context succeeds
21+
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = emscripten_webgl_create_context("#canvas", &attrs);
22+
assert(context > 0); // Must have received a valid context.
23+
EMSCRIPTEN_RESULT res = emscripten_webgl_make_context_current(context);
24+
assert(res == EMSCRIPTEN_RESULT_SUCCESS);
25+
assert(emscripten_webgl_get_current_context() == context);
26+
return 0;
27+
}

test/test_browser.py

+9
Original file line numberDiff line numberDiff line change
@@ -2612,6 +2612,15 @@ def test_html5_webgl_create_context(self, args):
26122612
def test_html5_webgl_create_context2(self):
26132613
self.btest_exit('webgl_create_context2.cpp')
26142614

2615+
@requires_graphics_hardware
2616+
# Verify bug https://github.com/emscripten-core/emscripten/issues/22943: creating a WebGL context with explicit swap control and offscreenCanvas
2617+
@parameterized({
2618+
'offscreencanvas': (['-sOFFSCREENCANVAS_SUPPORT'],),
2619+
'offscreenframebuffer': (['-sOFFSCREEN_FRAMEBUFFER', '-DUSE_OFFSCREEN_FRAMEBUFFER'],),
2620+
})
2621+
def test_html5_webgl_create_context_swapcontrol(self, args):
2622+
self.btest_exit('browser/webgl_create_context_swapcontrol.c', args=args)
2623+
26152624
@requires_graphics_hardware
26162625
# Verify bug https://github.com/emscripten-core/emscripten/issues/4556: creating a WebGL context to Module.canvas without an ID explicitly assigned to it.
26172626
# (this only makes sense in the old deprecated -sDISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=0 mode)

0 commit comments

Comments
 (0)