BabylonJS / BabylonJS/BabylonNative
Reconsider pinning bgfx to OpenGL ES 3.0
- Dominant language
- C++
- Stars
- 919
- Forks
- 162
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 19
Description
[Filed by Copilot on behalf of @bghgary]
`Dependencies/CMakeLists.txt` pins the OpenGL backend to ES 3.0:
```cmake
elseif(GRAPHICS_API STREQUAL "OpenGL")
target_compile_definitions(bgfx PRIVATE BGFX_CONFIG_RENDERER_OPENGLES=30)
```
`BGFX_CONFIG_RENDERER_OPENGL` is never set anywhere in the repo, so this is the version on every
OpenGL platform — Android, Linux, and Windows/ANGLE alike.
## What raising it would buy
ES 3.1 adds compute shaders, `GL_TEXTURE_2D_MULTISAMPLE`, and shader storage buffers; ES 3.2 adds
geometry and tessellation stages. bgfx gates a number of code paths on
`BGFX_CONFIG_RENDERER_OPENGLES >= 31` / `>= 32`.
## What it would cost
Not the build: bgfx vendors `GLES3/gl31.h` and `gl32.h`, and `minSdk = 25` already clears the API
levels that introduced ES 3.1 (21) and ES 3.2 (24).
The risk is runtime, because **bgfx requests an exact version with no fallback**:
```cpp
const uint32_t glVersion = !!BGFX_CONFIG_RENDERER_OPENGL
? BGFX_CONFIG_RENDERER_OPENGL
: BGFX_CONFIG_RENDERER_OPENGLES
;
...
bx::write(&writer, EGLint(EGL_CONTEXT_MAJOR_VERSION_KHR), ...);
bx::write(&writer, EGLint(glVersion / 10), ...);
bx::write(&writer, EGLint(EGL_CONTEXT_MINOR_VERSION_KHR), ...);
bx::write(&writer, EGLint(glVersion % 10), ...);
```
`EGL_KHR_create_context` is universal on ES 3.x, so this is the branch that runs. The retry loop
below it only drops the debug `EGL_CONTEXT_FLAGS_KHR` — it never lowers the version — and failure
is fatal:
```cpp
BGFX_FATAL(m_context != EGL_NO_CONTEXT, Fatal::UnableToInitialize, "Failed to create context.");
```
On any device that tops out at ES 3.0, raising this turns "runs" into "fails to start".
## Questions
- What is the real ES 3.1 coverage across the Android devices we target? That is the deciding
number.
- Should the version be a runtime capability check with fallback rather than a compile-time pin?
That would require a change in bgfx.
Contributor guide
Assessment
This issue has not been assessed yet.