简体   繁体   English

使用深度缓冲区而不是模板缓冲区进行剪辑

[英]Using the depth buffer instead of stencil buffer for clipping

On older iOS devices the stencil buffer isn't available.在较旧的 iOS 设备上,模板缓冲区不可用。 Also scissor only works for simple rectangles.剪刀也只适用于简单的矩形。 For more general clipping can we use the depth buffer?对于更一般的剪辑,我们可以使用深度缓冲区吗? To make things simple, lets assume that we are only drawing in 2D.为简单起见,让我们假设我们只在 2D 中绘图。

Also, my specific requirement is to be able to rotate the clipping rectangle.此外,我的具体要求是能够旋转剪切矩形。

Yes, absolutely.是的,一点没错。 Eg (coded as I type):例如(在我输入时编码):

glEnable(GL_DEPTH_TEST); // to enable writing to the depth buffer
glDepthFunc(GL_ALWAYS);  // to ensure everything you draw passes
glDepthMask(GL_TRUE);    // to allow writes to the depth buffer
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
                         // so that whatever we draw isn't actually visible

glClear(GL_DEPTH_BUFFER_BIT); // for a fresh start

/* here: draw geometry to clip to the inside of, e.g. at z = -2 */

glDepthFunc(GL_GREATER); // so that the z test will actually be applied
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
                         // so that pixels are painted again...
glDepthMask(GL_FALSE);  // ... but don't change the clip area

/* here: draw the geometry to clip inside the old shape at a z further than -2 */

So, key features are:因此,主要特点是:

  • the depth test can be set always to pass深度测试可以设置为始终通过
  • colour plotting can be disabled even while other buffer values are set即使设置了其他缓冲区值,也可以禁用彩色绘图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM