-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
Fix non power-of-2 textures being flipped when resized #15904
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
Conversation
|
@Mugen87 does this look right to you? |
|
I've tested the PR locally with the code from my test fiddle. Looks good now. |
src/renderers/webgl/WebGLTextures.js
Outdated
| // | ||
|
|
||
| var useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined'; | ||
| var useOffscreenCanvas = typeof document === 'undefined'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we changing this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OffscreenCanvas is also available in a non worker scenario. So testing for document seems more robust since it's definitely missing in a worker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see... How about changing the name of the variable then?
var isWorker = typeof document === 'undefined';There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
However, my original question still stands. We are no longer going to use OffscreenCanvas for resizing in non-worker scenarios?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, the problem seems to be that ImageBitmap needs flipping, but I do not understand why this PR also reverts to not using OffscreenCanvas in non-worker scenarios.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#15805 should enable texture resizing in workers. I though it's better to ensure the new code path is exclusively used in workers so the previous behavior of resizeImage() is not affected.
Well, maybe I'm too careful in that regard^^. I'm just not 100% sure of side effects if the method always returns resized images of type ImageBitmap when OffscreenCanvas is available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Yeah, lets not give up on OffscreenCanvas just yet. If we find problems with it we can report to browsers. Lets just flip the image for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mrdoob Ok, the latest commit switches back to OffscreenCanvas by default, and flips the texture in this case, which was the initial issue. Is that ok?
src/renderers/webgl/WebGLTextures.js
Outdated
| // | ||
|
|
||
| var useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined'; | ||
| var useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Extra spaces added.
|
I did more research on this over the weekend. Also in conversations with the WebGL team at Chrome. It's not clear if Until that is resolved, I realised we can just pass the OffscreenCanvas to gl directly. Can you change this PR so it just changes this line from this: return useOffscreenCanvas ? canvas.transferToImageBitmap() : canvas;To this? return canvas; |
|
@mrdoob Sure, I'll do that. Is the conversation about |
Not yet.
What browser/os did you try that on? I can still reproduce in Chrome/OSX. |
src/renderers/webgl/WebGLTextures.js
Outdated
|
|
||
| // ImageBitmap is flipped vertically | ||
|
|
||
| if ( useOffscreenCanvas ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block of code is not needed now because we're are now returning the canvas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please ignore what I said about the issue disappearing. I got confused. What fixed it was just returning the canvas instead of the ImageBitmap.
|
Thanks! |
|
I haven't perfectly read through the conversation here and in #15896 but I just want to comment that returning canvas may be safer as this PR finally goes than converting to As I'm adding a note to The upside down problem mentioned above might come from this? I guess |
|
@takahirox That is indeed the problem. Thanks for confirming and clarifying 🙏 |
|
Similarly saying, internally converting BTW, how Update: perhaps it should be rendered upside down because |
|
@takahirox Just to clarify... The original reason we added |
|
Yes, I know. I mean, the issue that non-POT |
|
Opened an issue #16144 |
Fix for #15896