A BitmapTexture can be used as a rendering target by creating a framebuffer object for it. This framebuffer can have a depth buffer to use depth testing, and a stencil buffer to perform stencil clipping. But using both features at the same time, which requires both a depth buffer and a stencil buffer, is only supported when GLES supports using the same buffer for both (called packed depth stencil). This is supported on GLES3 contexts or in GLES2 contexts that have the GL_OES_packed_depth_stencil extension. We need to modify BitmapTexture to allow using both features at the same time when packed depth stencil is available.
Pull request: https://github.com/WebKit/WebKit/pull/27682
This is going to fix the rendering for the cases where packed depth stencil is supported. For the rest of the cases, like GLES2 without the GL_OES_packed_depth_stencil extension, stencil clipping won't work on BitmapTextures where we're doing depth testing. I'll work on that next. My idea for this would be detecting that the call to initializeStencil() in TextureMapper::beginClip() failed to bind a stencilBuffer, and add an special implementation of the stencil clip for that case using an intermediate texture: - create a new intermediate BitmapTexture with a stencil only buffer and bind it - perform the stencil clip on the intermediate BitmapTexture - let the rendering continue on the intermediate BitmapTexture until the matching endClip - inside endClip, bind back the initial BitmapTexture and render the contents of the intermediate texture into it
(In reply to Miguel Gomez from comment #2) > This is going to fix the rendering for the cases where packed depth stencil > is supported. > > For the rest of the cases, like GLES2 without the > GL_OES_packed_depth_stencil extension, stencil clipping won't work on > BitmapTextures where we're doing depth testing. I'll work on that next. > > My idea for this would be detecting that the call to initializeStencil() in > TextureMapper::beginClip() failed to bind a stencilBuffer, and add an > special implementation of the stencil clip for that case using an > intermediate texture: > > - create a new intermediate BitmapTexture with a stencil only buffer and > bind it > - perform the stencil clip on the intermediate BitmapTexture > - let the rendering continue on the intermediate BitmapTexture until the > matching endClip > - inside endClip, bind back the initial BitmapTexture and render the > contents of the intermediate texture into it mmmmm nope, that's not going to work, as the depth testing won't be applied to the elements rendered into the intermediate BitmapTexture, so the result may be different than doing both depth testing and stencil clipping at the same time.
Committed 278159@main (ed286350cfd5): <https://commits.webkit.org/278159@main> Reviewed commits have been landed. Closing PR #27682 and removing active labels.