Skip to content

Best practice for Emscripten / SDL #362

@avitase

Description

@avitase

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions