[Android][OpenGL] Support GL_TEXTURE_EXTERNAL_OES in ExternalTexture
Maintainers usually reply within 1 day
@bkaradzic-microsoft is already working on this.
Since Aug 25, 2026.
Assessment
This issue has not been assessed yet.
Description
For questions, please use the forum.
Is your feature request related to a problem? Please describe.
Android commonly delivers camera and hardware-decoded video frames through
SurfaceTexture. The underlying OpenGL texture uses the
GL_TEXTURE_EXTERNAL_OES target rather than GL_TEXTURE_2D.
These textures cannot be sampled as ordinary 2D textures:
- They must be bound using
GL_TEXTURE_EXTERNAL_OES. - GLES 3 shaders must enable
GL_OES_EGL_image_external_essl3. - They must use
samplerExternalOES. - They are sampled-only, single-level textures with restricted sampler state.
BabylonNative's current OpenGL ExternalTexture path cannot describe this
texture kind:
Graphics::GL::Texture::Descriptor
has no texture-target/type field. Its target is currently derived from the
layer count as either a 2D texture or a 2D-array texture.ExternalTexture
always creates a bgfx texture throughbgfx::createTexture2D.
As a result, an externally owned OES texture cannot be wrapped and sampled
directly by BabylonNative. The application must currently perform an additional
full-frame GPU pass:
SurfaceTexture / MediaCodec / camera
-> GL_TEXTURE_EXTERNAL_OES
-> samplerExternalOES full-screen draw
-> RGBA GL_TEXTURE_2D
-> BabylonNative ExternalTexture
BabylonNative's own Android
NativeCamera
currently demonstrates this workaround: it samples the OES camera texture into
an RGBA 2D framebuffer texture before making that texture available to bgfx.
Although this avoids CPU readback, it still requires an extra destination
texture and a full-frame render pass for every video frame, adding GPU bandwidth,
synchronization, and latency.
Describe the solution you'd like
Allow the OpenGL ExternalTexture integration to represent and sample an
externally owned GL_TEXTURE_EXTERNAL_OES texture directly.
The exact API shape is open for discussion. One possible approach would be to
extend Graphics::GL::Texture::Descriptor, or an equivalent external-texture
descriptor, with a texture kind/target such as ExternalOES.
The resulting texture should:
- Be bindable as
GL_TEXTURE_EXTERNAL_OES. - Be sampled through
samplerExternalOESon OpenGL ES. - Be usable from JavaScript after
ExternalTexture::CreateForJavaScriptand
engine.wrapNativeTexture, without first copying it into a
GL_TEXTURE_2D. - Support replacing the underlying OES handle through
ExternalTexture::Update, if handle replacement is otherwise supported. - Preserve the existing externally owned lifetime model; BabylonNative must
not delete a texture owned bySurfaceTextureor another producer. - Detect unavailable OES/ESSL3 extension support and report a clear error.
The implementation should also enforce or document the restrictions of an
external OES texture:
- Sampled-only; not a Babylon render target.
- One layer and base mip level zero.
- No mipmap generation or mipmapped filtering.
CLAMP_TO_EDGEwrapping.NEARESTorLINEARminification/magnification filtering.
The producer would remain responsible for its platform lifecycle, including
calling SurfaceTexture.updateTexImage() on the correct GL context and applying
the matrix returned by SurfaceTexture.getTransformMatrix().
Suggested acceptance criteria:
- An Android
SurfaceTexture-backed OES texture containing a known test image
can be wrapped as anExternalTexture. - A Babylon material can sample and display it without an intermediate
OES-to-RGBA texture copy. - Updating the
SurfaceTextureupdates the displayed Babylon texture. - Externally owned texture lifetime and graphics-thread requirements remain
correct. - Existing 2D, 2D-array, D3D, and Metal external-texture paths are unchanged.
- Unsupported sampler states or missing OES extensions fail clearly rather
than rendering a black texture.
Describe alternatives you've considered
-
Render OES into an RGBA
GL_TEXTURE_2D.
This is the current working solution, but it adds one full-frame texture and
GPU render pass per input frame. -
Read the decoded frame back to the CPU and upload it again.
This is substantially more expensive and defeats the purpose of decoding to
aSurface. -
Render the OES texture outside BabylonNative using custom GLES code.
This avoids the copy but prevents the texture from participating normally
in Babylon materials, scene composition, and texture lifecycle management.
Requesting a regular 2D texture from the producer is generally not an option
for Android SurfaceTexture/MediaCodec output, whose texture target is
defined as GL_TEXTURE_EXTERNAL_OES.
Additional context
- Android
SurfaceTexturedocumentation:
https://developer.android.com/reference/android/graphics/SurfaceTexture - Khronos
GL_OES_EGL_image_external:
https://registry.khronos.org/OpenGL/extensions/OES/OES_EGL_image_external.txt - Khronos GLES 3 shader support:
https://registry.khronos.org/OpenGL/extensions/OES/OES_EGL_image_external_essl3.txt - The OpenGL
ExternalTexturebackend was introduced in:
https://github.com/BabylonJS/BabylonNative/pull/1780 - bgfx has historical design context for this capability:
The historical bgfx work used a target-aware overrideInternal operation and an
external-sampler shader abstraction. The currently exposed bgfx API used by
BabylonNative does not appear to retain that target parameter, so implementing
this may require coordinated bgfx and BabylonNative changes.
- Dominant language
- C++
- Stars
- 931
- Forks
- 169
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 66
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from BabylonJS/BabylonNative
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
BabylonJS/BabylonNative#2138 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
BabylonJS/BabylonNative#2042 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
BabylonJS/BabylonNative#2052 ·
Maintainers usually reply within 1 day
-
testing
Difficulty 4/5 3-5 days Newbie friendliness 45/100
BabylonJS/BabylonNative#2136 ·
Maintainers usually reply within 1 day
-
Support useNDCHalfZRange (half-range NDC depth) so Babylon.js half-range depth visual tests can runPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 4/5 3-5 days Newbie friendliness 48/100
BabylonJS/BabylonNative#2134 ·
Maintainers usually reply within 1 day
All issues in BabylonJS/BabylonNative
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
[Bug]: pip install -U cudaq-qec fails with a conflict that names cudaq-qec itselfPossibly taken @fedonman claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
task
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
SparseLinearAlgebra/spla#316 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 3 days