Skip to content

Conversation

@merwaaan
Copy link
Contributor

@merwaaan merwaaan commented Mar 4, 2019

Fix for #15896

  • Uses an OffscreenCanvas only when document is not available (was the default choice before)
  • Flips the texture vertically in this case

@mrdoob
Copy link
Owner

mrdoob commented Mar 5, 2019

@Mugen87 does this look right to you?

@Mugen87
Copy link
Collaborator

Mugen87 commented Mar 5, 2019

I've tested the PR locally with the code from my test fiddle. Looks good now.

//

var useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined';
var useOffscreenCanvas = typeof document === 'undefined';
Copy link
Owner

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?

Copy link
Collaborator

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.

Copy link
Owner

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';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

Copy link
Owner

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?

Copy link
Owner

@mrdoob mrdoob Mar 5, 2019

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.

Copy link
Collaborator

@Mugen87 Mugen87 Mar 5, 2019

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.

Copy link
Owner

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.

Copy link
Contributor Author

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?

//

var useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined';
var useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Extra spaces added.

@mrdoob
Copy link
Owner

mrdoob commented Mar 11, 2019

I did more research on this over the weekend. Also in conversations with the WebGL team at Chrome. It's not clear if ImageBitmap being upside down is correct or not. Maybe it's a big in Chrome.

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 mrdoob added this to the r103 milestone Mar 11, 2019
@merwaaan
Copy link
Contributor Author

@mrdoob Sure, I'll do that.

Is the conversation about ImageBitmap being upside down taking place in a public forum/issue tracker?

@merwaaan
Copy link
Contributor Author

@mrdoob: I just tested @Mugen87 's fiddle again to make sure verything works and it seems like the image is not upside down anymore. Maybe fixed by a Chrome update?

@mrdoob
Copy link
Owner

mrdoob commented Mar 11, 2019

Is the conversation about ImageBitmap being upside down taking place in a public forum/issue tracker?

Not yet.

@mrdoob: I just tested @Mugen87 's fiddle again to make sure verything works and it seems like the image is not upside down anymore. Maybe fixed by a Chrome update?

What browser/os did you try that on? I can still reproduce in Chrome/OSX.


// ImageBitmap is flipped vertically

if ( useOffscreenCanvas ) {
Copy link
Owner

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.

Copy link
Contributor Author

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.

@mrdoob mrdoob merged commit 7d387c3 into mrdoob:dev Mar 11, 2019
@mrdoob
Copy link
Owner

mrdoob commented Mar 11, 2019

Thanks!

@takahirox
Copy link
Collaborator

takahirox commented Mar 11, 2019

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 ImageBitmap.

As I'm adding a note to ImageBitmapLoader document #15945, ImageBitmap flipY and premultiplyAlpha configuration need to be specified on bitmap creation, not on uploading to GPU. This means, texture.flipY/.premultiplyAlpha will be ignored. It may be confusing to users. If non pot regular image is implicitly converted to ImageBitmap inside of renderer, users will be surprised to see that changing texture.flipY/.premultiplyAlpha and then setting texture.needsUpdate=true has no effect.

The upside down problem mentioned above might come from this? I guess OffscreenCanvas.transferToImageBitmap() might generate ImageBitmap with imageOrientation = 'none' (non flipY) so if texture.flipY is true the texture will be upside down?

@mrdoob
Copy link
Owner

mrdoob commented Mar 11, 2019

@takahirox That is indeed the problem. Thanks for confirming and clarifying 🙏

@takahirox
Copy link
Collaborator

takahirox commented Mar 11, 2019

Similarly saying, internally converting ImageBitmap to canvas might be confusing to users because of different texture.flipY/.premultiplyAlpha behaviors.

BTW, how ImageBitmap created with imageOrientation = 'flipY' is rendered to 2D canvas? Upside down? Or not? I need to confirm the specification but encouraging POT ImageBitmap maybe sounds reasonable and less problematic so far...

Update: perhaps it should be rendered upside down because ImageBitmap and its option isn't specific to WebGL. I'll look into more...

@mrdoob
Copy link
Owner

mrdoob commented Mar 11, 2019

@takahirox Just to clarify... The original reason we added OffscreenCanvas was to support Workers. No document in Workers.

@takahirox
Copy link
Collaborator

takahirox commented Mar 12, 2019

Yes, I know. I mean, the issue that non-POT ImageBitmap is implicitly converted to canvas in renderer and can be upside down has been around since before we introduced OffscreenCanvas for resizing in Worker. I'll clarify the problem and open a new issue.

@takahirox
Copy link
Collaborator

Opened an issue #16144

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.

4 participants