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

Render upside down using WebGL on Safari #2283

Closed
holymonson opened this issue Jan 12, 2016 · 15 comments
Closed

Render upside down using WebGL on Safari #2283

holymonson opened this issue Jan 12, 2016 · 15 comments

Comments

@holymonson
Copy link

Hi, here is the situation:

const filmObj = _getFilmObj() /* draw obj somewhere else */
const renderer_1 = PIXI.autoDetectRenderer(width, height)
renderer_1.render(filmObj)
const filmTexture = new PIXI.Texture(new PIXI.BaseTexture(renderer_1.view))
renderer_1.destroy()

const artboardObj = new PIXI.Sprite(filmTexture)
const renderer_2 = PIXI.autoDetectRenderer(width, height)
renderer_2.render(artboardObj)
const artboardTexture =new PIXI.Texture(new PIXI.BaseTexture(renderer_2.view))
renderer_2.destroy()

/* render artboardTexture somewhere else */

When test it on Safari (iOS / Mac OS X), renderer_2.view is fliped upside down against filmObj, while renderer_1.view is natural. It seems like renderer_2 rendering incorrect coordinate on renderer_1.view. Would you please check if anything worng?

Addtional Info:

  1. On Chrome (desktop / mobile) everything is fine;
  2. Using CanvasRenderer everything is fine too, even on Safari.
@holymonson
Copy link
Author

Tested in Safari / Firefox / Chrome and got below:
02 01 46

@GoodBoyDigital
Copy link
Member

weird! will make sure to take a look..

@Esshahn
Copy link

Esshahn commented Feb 5, 2016

I seem to have a similar problem with canvas being flipped upside down on Safari whereas Chrome displays it correct.

@holymonson
Copy link
Author

Now I set baseTexture.flipY = true on Safari and use a dirty hack below to get over it.

diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js
index 05258f6..82b1c84 100644
--- a/src/core/renderers/webgl/WebGLRenderer.js
+++ b/src/core/renderers/webgl/WebGLRenderer.js
@@ -396,6 +396,9 @@ WebGLRenderer.prototype.updateTexture = function (texture)

     gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id]);

+    if (texture.flipY) {
+        gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 1);
+    }
     gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultipliedAlpha);
     gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.source);

@vn222ay
Copy link

vn222ay commented Feb 16, 2016

I have a similar problem where I add Sprites to a Sprites and then on the canvas call toDataURL(). The image returned is flipped vertically on newer safari, while older safari (7.1 tested) and other browsers seems to return a non flipped image. Any suggestions how to fix this?

@holymonson maybe worth testing on older safari to see if you have a similar behaviour?

@vn222ay
Copy link

vn222ay commented Feb 26, 2016

Curious if anyone have found the source to this problem?

@Esshahn
Copy link

Esshahn commented Feb 26, 2016

for the sake of not letting this thread die: I haven't found a solution to it and had to fall back to forced canvas rendering.

@jpweeks
Copy link

jpweeks commented Jul 21, 2016

This might be related to WebGL context premultipliedAlpha; in my case, I can only reproduce the issue if premultipliedAlpha is false for the second renderer. Will need to pull out an isolated demo to verify.

@ivanpopelyshev
Copy link
Collaborator

I hate an idea of how could that happen, but i need to reproduce it first.

@jpweeks
Copy link

jpweeks commented Jul 21, 2016

Here is a reproducible case; only affects images generated with toDataURL in Safari.
https://jsbin.com/qivife/14/edit?js,output

@redsend
Copy link

redsend commented Sep 24, 2016

is there a way to export with toDataURL API the image not flipped?

@ivanpopelyshev
Copy link
Collaborator

ivanpopelyshev commented Sep 24, 2016

@redsend

Its not guaranteed that toDataURL and getImageData returns right stuff for WebGL, its not even in the standard. You have to use PIXI extract API:

//if you want canvas
var canvas =renderer.extract.canvas(stage);
//if you want base64
var base64=renderer.extract.base64(stage);

@msrobot0
Copy link

var base64=renderer.extract.base64(stage); and var canvas =renderer.extract.canvas(stage); fix the upside down issue But then the size of the canvas has changed, and background colors do not persist. Any suggestions

@msrobot0
Copy link

I am using PIXI.RenderTexture which fixes the image size issue, but the background color still does not stick

@lock
Copy link

lock bot commented Feb 24, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Feb 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants