glbinding icon indicating copy to clipboard operation
glbinding copied to clipboard

Best practice for Emscripten / SDL

Open avitase opened this issue 4 months ago • 1 comments

Hello,

I am successfully using glbinding in a combination of SDL and OpenGL 3.0 ES as an application running locally on my Desktop machine. However, I could (allegedly) easily port this thing to the web via Emscripten, too, since Emscripten does support SDL as an Emscripten Port. On their wiki I found the following warning, though:

Avoid using any of the *glGetProcAddress() API functions. Emscripten provides static linking to all of the GL API functions, even for all WebGL extensions. The *glGetProcAddress() API is only provided for compatibility to ease porting of existing code, but accessing WebGL via calling dynamically obtained function pointers is noticeably slower than direct function calls, due to extra function pointer security validation that dynamic dispatching has to do in asm.js/WebAssembly. Since Emscripten provides all of the GL entry points statically linked in, it is recommended to take advantage of this for best performance.

...which is exactly what I am (not) doing in my code:

::glbinding::initialize(
        reinterpret_cast<::glbinding::ProcAddress (*)(const char *)>(SDL_GL_GetProcAddress),
        /*resolve_functions=*/true);

According to ChatGPT it is totally fine to just change this to ::glbinding::initialize(nullptr, false) in case of an Emscripten build but somehow this seems to be fishy. What do you suggest? How should I deal with situations where symbols are linked statically?

Thanks for your help!

avitase avatar Aug 11 '25 13:08 avitase