Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/library_html5_webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ var LibraryHtml5WebGL = {
#endif
return 0;
}
canvas = GL.offscreenCanvases[canvas.id];
canvas = GL.offscreenCanvases[canvas.id].canvas;
}
}
#else // !OFFSCREENCANVAS_SUPPORT
Expand Down
27 changes: 27 additions & 0 deletions test/browser/webgl_create_context_swapcontrol.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2024 The Emscripten Authors. All rights reserved.
// Emscripten is available under two separate licenses, the MIT license and the
// University of Illinois/NCSA Open Source License. Both these licenses can be
// found in the LICENSE file.

#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <assert.h>

#include <emscripten/emscripten.h>
#include <emscripten/html5.h>

int main() {
EmscriptenWebGLContextAttributes attrs;
emscripten_webgl_init_context_attributes(&attrs);
attrs.explicitSwapControl = true;
#ifdef USE_OFFSCREEN_FRAMEBUFFER
attrs.renderViaOffscreenBackBuffer = true;
#endif
// Test that creating a context succeeds
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = emscripten_webgl_create_context("#canvas", &attrs);
assert(context > 0); // Must have received a valid context.
EMSCRIPTEN_RESULT res = emscripten_webgl_make_context_current(context);
assert(res == EMSCRIPTEN_RESULT_SUCCESS);
assert(emscripten_webgl_get_current_context() == context);
return 0;
}
9 changes: 9 additions & 0 deletions test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2612,6 +2612,15 @@ def test_html5_webgl_create_context(self, args):
def test_html5_webgl_create_context2(self):
self.btest_exit('webgl_create_context2.cpp')

@requires_graphics_hardware
# Verify bug https://github.com/emscripten-core/emscripten/issues/22943: creating a WebGL context with explicit swap control and offscreenCanvas
@parameterized({
'offscreencanvas': (['-sOFFSCREENCANVAS_SUPPORT'],),
'offscreenframebuffer': (['-sOFFSCREEN_FRAMEBUFFER', '-DUSE_OFFSCREEN_FRAMEBUFFER'],),
})
def test_html5_webgl_create_context_swapcontrol(self, args):
self.btest_exit('browser/webgl_create_context_swapcontrol.c', args=args)

@requires_graphics_hardware
# Verify bug https://github.com/emscripten-core/emscripten/issues/4556: creating a WebGL context to Module.canvas without an ID explicitly assigned to it.
# (this only makes sense in the old deprecated -sDISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=0 mode)
Expand Down
Loading