fix(Texture): Prevent GL_INVALID_OPERATION when updating texture data #3297
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TODO
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: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 calltexStorage2D
again on already-immutable textures.Console log showing the error pattern:
texStorage2D
+texSubImage2D
(works)texture.modified()
→ attemptstexStorage2D
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.
Changes
update2DFromRaw()
method that usestexSubImage2D
for data-only updatesrender()
method to detect when only texture data changes (same dimensions/components)API additions:
publicAPI.update2DFromRaw({ data, dataType, flip })
- Updates existing texture data without recreationDocumentation and TypeScript definitions were updated to match those changes
PR and Code Checklist
npm run reformat
to have correctly formatted codeTesting
Test coverage: