copyTextureToTexture pixelStorei fix to prevent upside-down texture uploads #19710
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.
The
WebGLRenderer.copyTextureToTexture
function does not set thepixelStorei
parameters for thedstTexture
, resulting in incorrect data upload if thepixelStorei
parameters have changed after thedstTexture
is created andcopyTextureToTexture
is called. An example would be creating a texture atlas withflipY
set to false and then creating another texture withflipY
set to true. If after this we try to upload new texture data to the atlas theflipY
parameter is be true, and thus our images will appear upside down.Relevant section of WebGL spec: https://www.khronos.org/registry/webgl/specs/latest/1.0/#PIXEL_STORAGE_PARAMETERS
To demonstrate the issue, take a look at the https://threejs.org/examples/?q=partia#webgl_materials_texture_partialupdate example. It needs a slight modification to draw gradients rather than solid squares so that it is clear when the data is upside down (see change below). While the example is running, change the
pixelStorei
parameter on the renderer by setting a breakpoint and then executing:After this all texture uploads will appear upside down. Screenshot demonstrating the output, notice how only some gradients are dark at the bottom.