2

I'd like to be able to share the depth and stencil buffer(s) between the on-screen buffer and an off-screen buffer. (Or, to phrase it a different way, I want to be able to render to a texture using the on-screen depth and stencil buffer.)

I tried to bind a shared depth / stencil renderbuffer to the default framebuffer, only for it to error out with "cannot modify framebuffer 0". Ok, so I cannot modify the onscreen framebuffer.

I then tried to bind the default framebuffer's stencil / depth buffer(s) to the secondary render buffer, but, again, it errored out with "cannot query framebuffer 0".

My current workaround is to create two off-screen framebuffers, and at the end splat the main off-screen buffer to screen via a texture and a fullscreen quad. Not exactly pretty.

Unfortunately, webgl is based on OpenGL ES, and this question suggests that there is no way to do this for OpenGL ES. As such, I suspect, although I hope that I am wrong, that there is no "better" way.

TLW
  • 1,373
  • 9
  • 22
  • You say "not exactly pretty", but to me the principle of having *n* off-screen framebuffers for preprocessing, then blitting the "final" buffer to the screen with a fullscreen quad, sounds pretty standard. – Paul-Jan Dec 19 '15 at 06:46
  • Standard != good. That being said, good/bad to know that it is pretty standard. (Or, I suppose, standard, but not pretty?) – TLW Dec 19 '15 at 18:03
  • Hahaha, very true. I was going to say I'd take *standard* over *pretty* any day, but then I realized that I didn't mean it. :-) – Paul-Jan Dec 20 '15 at 06:35

1 Answers1

3

Not possible.

WebGL 1.0 specification § 5.14.6:

If framebuffer is null, the default framebuffer provided by the context is bound and attempts to modify or query state on target FRAMEBUFFER will generate an INVALID_OPERATION error.

LJᛃ
  • 7,655
  • 2
  • 24
  • 35