在较旧的iOS设备上,模板缓冲区不可用。剪刀也适用于简单的矩形。对于更一般的剪裁,我们可以使用深度缓冲区吗?为简单起见,我们假设我们只绘制2D。
另外,我的具体要求是能够旋转剪裁矩形。
答案 0 :(得分:5)
是的,绝对的。例如。 (按我输入的方式编码):
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 */
所以,关键功能是: