cginternals / cginternals/glbinding

Best practice for Emscripten / SDL

Open
#362 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
877
Forks
95
PR merge metrics
No merged PRs in 30d

Description

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](https://emscripten.org/docs/compiling/Building-Projects.html#emscripten-ports). On [their wiki](https://emscripten.org/docs/optimizing/Optimizing-WebGL.html) 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!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.