Skip to content

fix(Texture): Prevent GL_INVALID_OPERATION when updating texture data #3297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

PaulHax
Copy link
Collaborator

@PaulHax PaulHax commented Jul 25, 2025

TODO

  • I think we need account for datatype changes, among other tings =/

Prevent GL_INVALID_OPERATION when updating texture data in WebGL2

I would think this warning has been disccused before but could not find an issue regarding this...

Context

WebGL2 textures created with texStorage2D are immutable, causing browser console warnings:

GL_INVALID_OPERATION: glTexStorage2D: Texture is immutable.

This occurs when texture.modified() triggers recreation of existing textures, such as when updating video textures or other dynamic content. The warning appears because vtk.js attempts to call texStorage2D again on already-immutable textures.

Console log showing the error pattern:

  • Initial texture creation: texStorage2D + texSubImage2D (works)
  • Texture update: texture.modified() → attempts texStorage2D again (fails)

Want this to update a texture with a video stream.

Results

Before: Browser console shows GL_INVALID_OPERATION warnings on every texture update

After: Clean texture updates without any WebGL errors

The texture data still updates correctly in both cases, but the warnings are eliminated and performance is improved by avoiding unnecessary texture recreation.

Changes

  • Added: update2DFromRaw() method that uses texSubImage2D for data-only updates
  • Modified: render() method to detect when only texture data changes (same dimensions/components)

API additions:

  • publicAPI.update2DFromRaw({ data, dataType, flip }) - Updates existing texture data without recreation

  • Documentation and TypeScript definitions were updated to match those changes

PR and Code Checklist

  • semantic-release commit messages
  • Run npm run reformat to have correctly formatted code

Testing

  • This change adds or fixes unit tests
  • Tested environment:
    • vtk.js: latest master
    • OS: Linux
    • Browser: Chrome WebGL2

Test coverage:

  • Unit test verifies no GL_INVALID_OPERATION errors during texture updates

WebGL2 textures created with texStorage2D are immutable, causing
GL_INVALID_OPERATION: glTexStorage2D: Texture is immutable when
texture.modified() triggers recreation of existing textures.

This commit introduces:
- update2DFromRaw() method that uses texSubImage2D for data-only updates
- Smart detection in render() to avoid recreation when dimensions unchanged
@PaulHax PaulHax marked this pull request as draft July 25, 2025 18:39
@floryst
Copy link
Collaborator

floryst commented Jul 31, 2025

@sankhesh just an FYI (low priority)

@sankhesh sankhesh self-assigned this Aug 12, 2025
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.

3 participants