Skip to content

Fix EGL texture replacement in GPU renderer - #4805

Open
Tianyi20 wants to merge 1 commit into
bulletphysics:masterfrom
Tianyi20:fix/egl-texture-replacement
Open

Tianyi20 wants to merge 1 commit into
bulletphysics:masterfrom
Tianyi20:fix/egl-texture-replacement

Conversation

@Tianyi20

@Tianyi20 Tianyi20 commented Sep 10, 2026 •

Copy link
Copy Markdown

Problem

When using PyBullet in DIRECT mode with the EGL OpenGL renderer, dynamically replacing a visual texture through changeVisualShape(..., textureUniqueId=...) can produce an incorrect texture result.

The EGL visual shape converter was passing the public textureUniqueId directly to the instancing renderer. However, textures registered by the EGL renderer have their own internal renderer texture ID (m_innerTexUid), so the two IDs are not necessarily interchangeable.

I noticed the error was first mentioned on Dec 4, 2020, while it remains unfixed in 2026. Here is the discussion: #3419.

This can make dynamically assigned textures render incorrectly with EGL even though the same texture is rendered correctly by the Tiny Renderer.

Approach

Update EGLRendererVisualShapeConverter::changeShapeTexture() to:

  • resolve textureUniqueId to the corresponding internal m_innerTexUid before calling replaceTexture();
  • preserve -1 as the value used to remove/disable the texture;
  • validate the texture index before accessing m_textures.

The change is intentionally limited to the EGL visual shape converter.

Result

Dynamic texture replacement now uses the renderer's actual internal texture ID, allowing textures changed through PyBullet's visual-shape API to render correctly with the EGL GPU renderer.

This is particularly useful for headless DIRECT rendering where EGL is used for GPU-accelerated camera images.

Validation

I reproduced the issue by comparing dynamic texture replacement using the Tiny Renderer and the EGL hardware OpenGL renderer in DIRECT mode.

After this change, the dynamically replaced texture is correctly used by the EGL renderer.

git diff --check passes.

Thank you for developing and maintaining Bullet and PyBullet. I really enjoy using PyBullet, especially for robotics and GPU-accelerated simulation, and I hope this small fix is useful to the project.

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