Skip to content

renderer_gl: support external textures (BGFX_CAPS_TEXTURE_EXTERNAL)#69

Open
cdschmidt wants to merge 1 commit into
BabylonJS:masterfrom
cdschmidt:users/caschmidt/gl-external-texture
Open

renderer_gl: support external textures (BGFX_CAPS_TEXTURE_EXTERNAL)#69
cdschmidt wants to merge 1 commit into
BabylonJS:masterfrom
cdschmidt:users/caschmidt/gl-external-texture

Conversation

@cdschmidt

Copy link
Copy Markdown

What

Add OpenGL/OpenGL ES support for bgfx external textures (importing an existing, caller-owned GL texture id instead of allocating a new one).

Two changes in src/renderer_gl.cpp:

  1. Advertise BGFX_CAPS_TEXTURE_EXTERNAL. The GL renderer never set this capability, so createTexture2D(..., _external) tripped the "External texture is not supported!" assertion in bgfx.cpp. The D3D11, D3D12, Metal, and Vulkan renderers already advertise it.
  2. Honor the _external handle in createTexture. The override previously did BX_UNUSED(_external) and always allocated a fresh texture. It now adopts the supplied id via the existing TextureGL::overrideInternal, which sets BGFX_SAMPLER_INTERNAL_SHARED so TextureGL::destroy will not delete the externally owned texture.

Why

This is the renderer-side counterpart required by BabylonNative's ExternalTexture OpenGL backend (BabylonJS/BabylonNative#1780). Without it, the OpenGL/OpenGL ES path fatals at runtime with External texture is not supported! because the GL renderer neither advertises the capability nor wraps the provided texture id.

Importing an existing GL texture id is valid on any GL/GLES context, so the capability is advertised unconditionally, matching the other backends.

The OpenGL renderer never advertised BGFX_CAPS_TEXTURE_EXTERNAL and ignored
the external native handle passed to createTexture, so createTexture2D(...,
_external) tripped the "External texture is not supported!" assertion. The
D3D11, D3D12, Metal and Vulkan renderers already support this path.

Advertise the capability (importing an existing GL texture id via
TextureGL::overrideInternal is valid on any GL/GLES context) and adopt the
supplied id in createTexture. overrideInternal sets BGFX_SAMPLER_INTERNAL_SHARED
so TextureGL::destroy will not delete the externally owned texture.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 266f2ffa-1a30-41c7-96de-0ec7782df1bd
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.

1 participant