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

WebGL auto clear color? #174

Closed
PrincessGod opened this issue Mar 7, 2018 · 2 comments
Closed

WebGL auto clear color? #174

PrincessGod opened this issue Mar 7, 2018 · 2 comments

Comments

@PrincessGod
Copy link
Contributor

PrincessGod commented Mar 7, 2018

Hi, @greggman .

I found in this sample, when comment these lines

72    //webglUtils.resizeCanvasToDisplaySize(gl.canvas);
73
74    // Tell WebGL how to convert from clip space to pixels
75    //gl.viewport(0, 0, gl.canvas.width, gl.canvas.height);
76
77    // Clear the canvas.
78    //gl.clear(gl.COLOR_BUFFER_BIT);

drawScene() still clear history draw, do you know the reason?

Thank you.

@greggman
Copy link
Member

greggman commented Mar 7, 2018

Sorry I guess I never covered that.

Yes, WebGL by default clears the canvas by after the canvas has been compositied.

If you want it not to clear the canvas you need to add preserveDrawingBuffer: true when creating the context as in

const gl = someCanvas.getContext("webgl", {preserveDrawingBuffer: true});

The longer version is:

If you draw to the canvas (gl.drawXXX, gl.clear) then the browser marks that the canvas needs to be recompositied with the page. To do this either either makes a copy of the canvas or swaps the canvas's storage with another storage buffer (double buffered). After the browser has compositied the result it clears the canvas. It does this so that the result is consistent whether or not it copies or it swaps.

@PrincessGod
Copy link
Contributor Author

Really helpful, thank you very mach!

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

No branches or pull requests

2 participants