From f1762511eeb8d5916200f8ea380adb4e6064cddc Mon Sep 17 00:00:00 2001 From: hchac Date: Thu, 28 May 2026 18:23:54 -0400 Subject: [PATCH 1/2] Adding emscripten as build target for glfw & opengl. Also upping the opengl version from 3.0 to 3.3 when running under WebGL 2.0. --- libraries/glfw.c3l/manifest.json | 5 +++++ libraries/opengl.c3l/gl.c3 | 25 +++++++++++++++++-------- libraries/opengl.c3l/manifest.json | 5 +++++ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/libraries/glfw.c3l/manifest.json b/libraries/glfw.c3l/manifest.json index 6c1dca5..2a79918 100644 --- a/libraries/glfw.c3l/manifest.json +++ b/libraries/glfw.c3l/manifest.json @@ -1,6 +1,11 @@ { "provides": "glfw", "targets" : { + "emscripten" : { + "link-args" : [], + "dependencies" : [], + "linked-libraries" : [] + }, "macos-x64" : { "link-args" : [], "dependencies" : [], diff --git a/libraries/opengl.c3l/gl.c3 b/libraries/opengl.c3l/gl.c3 index a922fa4..d1ef248 100644 --- a/libraries/opengl.c3l/gl.c3 +++ b/libraries/opengl.c3l/gl.c3 @@ -13734,12 +13734,21 @@ fn void load_all_gl(GLLoadFn load, int version) { fn int load_gl_internal(GLLoadFn load) { - getIntegerv = load("glGetIntegerv"); - if (getIntegerv == null) return 0; - int major, minor; - getIntegerv((GLenum)GL_MAJOR_VERSION, &major); - getIntegerv((GLenum)GL_MINOR_VERSION, &minor); - int version = (major * 10) + minor; - load_all_gl(load, version); - return version; + getIntegerv = load("glGetIntegerv"); + if (getIntegerv == null) return 0; + int major, minor; + getIntegerv((GLenum)GL_MAJOR_VERSION, &major); + getIntegerv((GLenum)GL_MINOR_VERSION, &minor); + if (major == 3 && minor == 0) + { + getString = load("glGetString"); + String version_str = ((ZString)getString((GLenum)GL_VERSION)).str_view(); + if (version_str.contains("WebGL 2.0")) + { + minor = 3; + } + } + int version = (major * 10) + minor; + load_all_gl(load, version); + return version; } diff --git a/libraries/opengl.c3l/manifest.json b/libraries/opengl.c3l/manifest.json index c4d28b3..d7fa50c 100644 --- a/libraries/opengl.c3l/manifest.json +++ b/libraries/opengl.c3l/manifest.json @@ -1,6 +1,11 @@ { "provides" : "opengl", "targets" : { + "emscripten" : { + "link-args" : [], + "dependencies" : [], + "linked-libraries" : [] + }, "freebsd-x64" : { "link-args" : [], "dependencies" : [], From 82fb14ba6febdf70578b15de668fea01e9b76ef8 Mon Sep 17 00:00:00 2001 From: hchac Date: Wed, 1 Jul 2026 09:32:41 -0400 Subject: [PATCH 2/2] Adding quick comment to explain reasoning for treating WebGL 2.0 like OpenGL 3.3. --- libraries/opengl.c3l/gl.c3 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/opengl.c3l/gl.c3 b/libraries/opengl.c3l/gl.c3 index d1ef248..1aa4bc9 100644 --- a/libraries/opengl.c3l/gl.c3 +++ b/libraries/opengl.c3l/gl.c3 @@ -13739,6 +13739,9 @@ fn int load_gl_internal(GLLoadFn load) int major, minor; getIntegerv((GLenum)GL_MAJOR_VERSION, &major); getIntegerv((GLenum)GL_MINOR_VERSION, &minor); + // Treating WebGL 2.0 like OpenGL 3.3 in order to load as many of the + // functions defined for WebGL 2.0 as possible. Not all OpenGL 3.1 to 3.3 + // functions are supported in WebGL 2.0, but there is overlap. if (major == 3 && minor == 0) { getString = load("glGetString");