Skip to content

[rcore][web] Avoid glfwGetProcAddress() to reduce code size - #6220

Open
vdemcak wants to merge 2 commits into
raysan5:masterfrom
vdemcak:master
Open

vdemcak wants to merge 2 commits into
raysan5:masterfrom
vdemcak:master

Conversation

@vdemcak

@vdemcak vdemcak commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

On Emscripten, referencing glfwGetProcAddress() or emscripten_webgl_get_proc_address() links a lookup table of every GL function into both the JS and the wasm, but rlgl only needs 6 extension functions on WebGL. Emscripten links GL functions statically, so a small loader now returns them directly. See #3713.

Applied to both rcore_web.c and the experimental rcore_web_emscripten.c. The loader body is guarded by GRAPHICS_API_OPENGL_ES2, because software rendering builds don't declare the GLES extension functions.

core_basic_window, JS + wasm gzipped: 91.4 -> 83.9 KB (WebGL 1), 94.4 -> 81.3 KB (WebGL 2).

On web, rlGetProcAddress() now only returns those 6 functions.

Tested shaders_mesh_instancing on WebGL 1 & 2: works identically.

@vdemcak

vdemcak commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Also, optional follow-up: -s GL_ENABLE_GET_PROC_ADDRESS=1 from projects/CMake/CMakeLists.txt should no longer be needed and can be removed.

Comment thread src/platforms/rcore_web.c
else if (strcmp(procName, "glDrawElementsInstancedANGLE") == 0) proc = (void *)glDrawElementsInstancedANGLE;
else if (strcmp(procName, "glVertexAttribDivisorANGLE") == 0) proc = (void *)glVertexAttribDivisorANGLE;
#endif

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rlgl uses the loader for the following potential functions:

glGenVertexArraysOES
glBindVertexArrayOES
glDeleteVertexArraysOES

glDrawArraysInstancedANGLE
glDrawElementsInstancedANGLE
glVertexAttribDivisorANGLE

glDrawArraysInstancedEXT
glDrawElementsInstancedEXT
glVertexAttribDivisorEXT
glDrawArraysInstancedNV
glDrawElementsInstancedNV
glVertexAttribDivisorNV

Maybe the additional EXT/NV names should be also checked instead of relying only on ANGLE extension names.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On web, the only instancing extension WebGL defines is ANGLE_instanced_arrays (there's no EXT/NV variant in the WebGL extension registry), so rlgl will only ever request the *ANGLE functions there. The EXT/NV branches can't be hit on this platform.

That said, I'm happy to add the EXT/NV names too if you'd prefer it to be defensive.

@raysan5

raysan5 commented Oct 5, 2026

Copy link
Copy Markdown
Owner

@vdemcak that's a nice improvement! Added some review. Also, please, could you update CMakeLists.txt?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants