Codebase list emscripten / f263265
[GLFW] Respect GLFW_NO_API flag (#12907) In order to support the combined use of GLFW and WebGPU, GLFW should not assign anything to the Emscripten modules context variable. GLFW supports not creating any OpenGL context using the windows attribute GLFW_CLIENT_API. Basil Fierz authored 3 years ago GitHub committed 3 years ago
4 changed file(s) with 27 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
526526 * Alexey Sokolov <sokolov@google.com> (copyright owned by Google, LLC)
527527 * Ivan Romanovski <ivan.romanovski@gmail.com>
528528 * Max Brunsfeld <maxbrunsfeld@gmail.com>
529 * Basil Fierz <basil.fierz@hotmail.com>
999999 for (i = 0; i < GLFW.windows.length && GLFW.windows[i] == null; i++) {
10001000 // no-op
10011001 }
1002 var useWebGL = GLFW.hints[0x00022001] > 0; // Use WebGL when we are told to based on GLFW_CLIENT_API
10021003 if (i == GLFW.windows.length) {
1003 var contextAttributes = {
1004 antialias: (GLFW.hints[0x0002100D] > 1), // GLFW_SAMPLES
1005 depth: (GLFW.hints[0x00021005] > 0), // GLFW_DEPTH_BITS
1006 stencil: (GLFW.hints[0x00021006] > 0), // GLFW_STENCIL_BITS
1007 alpha: (GLFW.hints[0x00021004] > 0) // GLFW_ALPHA_BITS
1004 if (useWebGL) {
1005 var contextAttributes = {
1006 antialias: (GLFW.hints[0x0002100D] > 1), // GLFW_SAMPLES
1007 depth: (GLFW.hints[0x00021005] > 0), // GLFW_DEPTH_BITS
1008 stencil: (GLFW.hints[0x00021006] > 0), // GLFW_STENCIL_BITS
1009 alpha: (GLFW.hints[0x00021004] > 0) // GLFW_ALPHA_BITS
1010 }
1011 #if OFFSCREEN_FRAMEBUFFER
1012 // TODO: Make GLFW explicitly aware of whether it is being proxied or not, and set these to true only when proxying is being performed.
1013 GL.enableOffscreenFramebufferAttributes(contextAttributes);
1014 #endif
1015 Module.ctx = Browser.createContext(Module['canvas'], true, true, contextAttributes);
1016 } else {
1017 Browser.init();
10081018 }
1009 #if OFFSCREEN_FRAMEBUFFER
1010 // TODO: Make GLFW explicitly aware of whether it is being proxied or not, and set these to true only when proxying is being performed.
1011 GL.enableOffscreenFramebufferAttributes(contextAttributes);
1012 #endif
1013 Module.ctx = Browser.createContext(Module['canvas'], true, true, contextAttributes);
10141019 }
10151020
10161021 // If context creation failed, do not return a valid window
1017 if (!Module.ctx) return 0;
1022 if (!Module.ctx && useWebGL) return 0;
10181023
10191024 // Get non alive id
10201025 var win = new GLFW_Window(id, width, height, title, monitor, share);
8383 {
8484 int x, y, w, h;
8585 glfwDefaultWindowHints();
86 glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
86 glfwWindowHint(GLFW_CLIENT_API, CLIENT_API);
8787
8888 window = glfwCreateWindow(640, 480, "glfw3.c", NULL, NULL);
8989 assert(window != NULL);
141141 window = glfwCreateWindow(640, 480, "glfw3.c", NULL, NULL);
142142 assert(window != NULL);
143143
144 assert(glfwGetWindowAttrib(window, GLFW_CLIENT_API) == GLFW_OPENGL_ES_API);
144 assert(glfwGetWindowAttrib(window, GLFW_CLIENT_API) == CLIENT_API);
145145
146146 assert(glfwGetWindowUserPointer(window) == NULL);
147147 glfwSetWindowUserPointer(window, userptr);
194194 glfwSetTime(0);
195195 }
196196
197 #if CLIENT_API == GLFW_OPENGL_ES_API
197198 {
198199 glfwMakeContextCurrent(window); // stub
199200 assert(glfwGetCurrentContext() == window);
205206 assert(glfwExtensionSupported("nonexistant") == 0);
206207 assert(glfwGetProcAddress("nonexistant") == NULL);
207208 }
209 #endif
208210
209211 glfwTerminate();
210212
27822782 in_html('200')
27832783
27842784 @requires_graphics_hardware
2785 def test_glfw3(self):
2785 @parameterized({
2786 'no_gl': (['-DCLIENT_API=GLFW_NO_API'],),
2787 'gl_es': (['-DCLIENT_API=GLFW_OPENGL_ES_API'],)
2788 })
2789 def test_glfw3(self, args):
27862790 for opts in [[], ['-s', 'LEGACY_GL_EMULATION=1'], ['-Os', '--closure', '1']]:
27872791 print(opts)
2788 self.btest(path_from_root('tests', 'glfw3.c'), args=['-s', 'USE_GLFW=3', '-lglfw', '-lGL'] + opts, expected='1')
2792 self.btest(path_from_root('tests', 'glfw3.c'), args=['-s', 'USE_GLFW=3', '-lglfw', '-lGL'] + args + opts, expected='1')
27892793
27902794 @requires_graphics_hardware
27912795 def test_glfw_events(self):