Possible bug in WebGL with preserveDrawingBuffer:true

801 views
Skip to first unread message

Duncan Murdoch

unread,
Feb 20, 2016, 12:01:01 PM2/20/16
to WebGL Dev List
I'm seeing some problems in a WebGL scene rendered in several different browsers. 

The symptoms are that when the WebGL canvas is created with preserveDrawingBuffer:true, and the drawing of the scene results in gl.depthMask(false) being in effect at the end of rendering, a call to gl.clear(gl.DEPTH_BUFFER_BIT) at the start of the next render doesn't actually do anything.  If I precede it with gl.depthMask(true), things look fine, but that shouldn't be required, should it?

For a simple demo of the problem, see the WebGL demo <https://github.com/MarkusSprunck/webgl-hello-world>, with the following changes to webgl-demo.js:

Line 71:      gl = canvas.getContext("experimental-webgl", {preserveDrawingBuffer:true});

After the gl.clear on line 319:

gl.depthMask(true);

Just before the end of the drawScene() function, i.e. near line 388, add

gl.depthMask(false);


Run the demo with these changes, and the cube gets all messed up because the depth buffer is never cleared.

Duncan Murdoch



Duncan Murdoch

unread,
Feb 20, 2016, 12:07:51 PM2/20/16
to WebGL Dev List
I've just put the demo online at

http://www.stats.uwo.ca/faculty/murdoch/temp/webgl-demo.htm

I don't guarantee it will remain there forever.  Here's a web page showing the demo as it should be:

http://www.sw-engineering-candies.com/snippets/webgl/hello-world

Duncan Murdoch

Mark Callow

unread,
Feb 20, 2016, 7:06:44 PM2/20/16
to webgl-d...@googlegroups.com

On Feb 21, 2016, at 2:01 AM, Duncan Murdoch <murdoch...@gmail.com> wrote:

I'm seeing some problems in a WebGL scene rendered in several different browsers. 

The symptoms are that when the WebGL canvas is created with preserveDrawingBuffer:true, and the drawing of the scene results in gl.depthMask(false) being in effect at the end of rendering, a call to gl.clear(gl.DEPTH_BUFFER_BIT) at the start of the next render doesn't actually do anything.  If I precede it with gl.depthMask(true), things look fine, but that shouldn't be required, should it?


Yes it is required. Your application is in full control of GL state. If you leave depthMask FALSE at the end of rendering a frame, it will still be FALSE at the start of rendering the next frame. The error in your program is being masked with preserveDrawingBuffer:false because WebGL implementations clear the buffers in this case to prevent information leaks from other apps through newly allocated buffer memory. As an optimization, most implementations only perform this clear when the application itself fails to clear the buffers.

Regards

    -Mark

signature.asc

Duncan Murdoch

unread,
Feb 20, 2016, 7:32:37 PM2/20/16
to webgl-d...@googlegroups.com
Thanks. I didn't see that in the documentation I was using for WebGL,
but now I see this in the OpenGL docs:

"The pixel ownership test, the scissor test, dithering, and the buffer
writemasks affect the operation of glClear. The scissor box bounds the
cleared region. Alpha function, blend function, logical operation,
stenciling, texture mapping, and depth-buffering are ignored by glClear."

This seems contradictory to me: it says the writemasks affect the
operation, but depth-buffering is ignored. What does it mean that
depth-buffering is ignored?

Duncan Murdoch

Mark Callow

unread,
Feb 20, 2016, 7:43:17 PM2/20/16
to webgl-d...@googlegroups.com

> On Feb 21, 2016, at 9:32 AM, Duncan Murdoch <murdoch...@gmail.com> wrote:
>
>
>
> This seems contradictory to me: it says the writemasks affect the operation, but depth-buffering is ignored. What does it mean that depth-buffering is ignored?
>

That the current setting of the depth test function is ignored so no depth testing is performed. I.e. the depth value specified to gl.clear() is written to every fragment in the depth buffer regardless of its current value.

Regards

-Mark

signature.asc

Catalin

unread,
Feb 23, 2016, 5:49:21 PM2/23/16
to webgl-d...@googlegroups.com
@Duncan Murdoch
Your http://www.stats.uwo.ca/faculty/murdoch/temp/webgl-demo.htm not working well with my browser ( firefox ).
 Imagini inline 1
This http://www.sw-engineering-candies.com/snippets/webgl/hello-world working well.
I don't know why.


--
You received this message because you are subscribed to the Google Groups "WebGL Dev List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webgl-dev-lis...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Duncan Murdoch

unread,
Feb 23, 2016, 6:14:16 PM2/23/16
to WebGL Dev List
That was the point.  The one on my web site had the depthMask(false) in effect when it cleared the depth buffer.  That doesn't work, as Mark explained.

Duncan Murdoch
Reply all
Reply to author
Forward
0 new messages