Skip to content
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

copyTextureToTexture pixelStorei fix to prevent upside-down texture uploads #19710

Merged
merged 3 commits into from
Jun 22, 2020

Conversation

felixpalmer
Copy link
Contributor

The WebGLRenderer.copyTextureToTexture function does not set the pixelStorei parameters for the dstTexture, resulting in incorrect data upload if the pixelStorei parameters have changed after the dstTexture is created and copyTextureToTexture is called. An example would be creating a texture atlas with flipY set to false and then creating another texture with flipY set to true. If after this we try to upload new texture data to the atlas the flipY 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:

renderer.getContext().pixelStorei(37440, false)

After this all texture uploads will appear upside down. Screenshot demonstrating the output, notice how only some gradients are dark at the bottom.

Screen Shot 2020-06-22 at 4 25 01 PM

@felixpalmer
Copy link
Contributor Author

Should resolve #15590

@mrdoob mrdoob requested a review from Mugen87 June 22, 2020 16:08
@mrdoob mrdoob added this to the r118 milestone Jun 22, 2020
@Mugen87
Copy link
Collaborator

Mugen87 commented Jun 22, 2020

Please undo the modifications to the example unless you can demonstrate the issue without use of the debugger.

Apart from that, the code changes to copyTextureToTexture() seem to work. Although the code could be refactored in the future by consolidating some logic in WebGLTextures.

@mrdoob mrdoob merged commit 87bd3ad into mrdoob:dev Jun 22, 2020
@mrdoob
Copy link
Owner

mrdoob commented Jun 22, 2020

Thanks!

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.

None yet

3 participants