WebGLRenderer: Fix active texture setting in copyTextureToTexture().#33153
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
|
Can you please reproduce the issue with a live example? Use https://jsfiddle.net/3mrkqyea/ as a starter template. We must be able to reproduce the issue so we have a chance to verify if the PR actually fixes it. |
|
Here is the reproduction case: https://jsfiddle.net/xko5s6zf/5/ You should see a green sphere on top and a blue sphere, but actually you see a blue sphere on top of a red one. Try commenting the |
|
While studying the solution I think it's indeed better to fix the issue in
Would you please update the PR and add your proposed fix to three.js/src/renderers/webgl-fallback/utils/WebGLState.js Lines 1248 to 1253 in bf65eaf |
eb09f12 to
61c0af9
Compare
1864769 to
a623478
Compare
|
Done! I also changed the title of the PR to reflect the actual change and not mention copyTextureToTexture directly |
bindTexture().
|
I did a performance review and it turns out this change introduces unnecessary I'm sorry for the back and forth but could you restore the previous version and just modify To further explain the design issue: If a texture is just used for rendering, a simple bind is sufficient. But when mutating the texture (like |
9278d14 to
18a7aee
Compare
18a7aee to
b228a7d
Compare
|
No problem, I force pushed the first version. I'll let you edit the title of the PR however you see fit. |
|
|
||
| textures.setTexture2D( dstTexture, 0 ); | ||
| glTarget = _gl.TEXTURE_2D; | ||
| state.activeTexture( _gl.TEXTURE0 ); |
There was a problem hiding this comment.
Can we move this below the else block so it also works for 3d and array textures?
There was a problem hiding this comment.
Edit: I think WebGPURenderer does not need the change because the WebGL backend does not explicitly set 0 for the texture unit.
There was a problem hiding this comment.
Indeed, WebGPURenderer works fine for both backends: https://jsfiddle.net/wenck4aq/
bindTexture().copyTextureToTexture().
copyTextureToTexture().copyTextureToTexture().
Clean up.
|
I've made a small update and also added a comment to this PR so it's more clear why the line has been added. |
|
Okay, thanks for taking care of this! |
Fixed #25618.
Description
In some cases, calling
gl.copyTextureToTexturecan target a different texture than the one actually passed as parameter. This happens if:In this case, when
copyTextureToTexturecallstextures.setTexture2D,state.bindTextureis called but because this texture was already in slot 0,state.bindTextureis a noop. It means that the active slot is not changed and if it's not 0, then the target ofcopyTextureToTextureis invalid.The fix in this PR solves the problem for
copyTextureToTexturespecifically but maybe we should fixstate.bindTextureinstead. The current behavior ofstate.bindTexturecan create problems because it only set the active slot if the texture was not already bound to this slot.Here's what it currently does:
But instead we could do:
I'm not sure if this will cause some other side-effect. Let me know what you think!