【发布时间】:2016-02-07 14:48:33
【问题描述】:
我正在用 lwjgl/opengl 渲染我的世界中的传送门。为了提高性能并使多个门户可以相互渲染,我尝试使用模板缓冲区将绘制的场景剪辑到门户所在的位置。
但这仅适用于 Intel 卡,不适用于 Nvidia/AMD。关于模板缓冲区,卡片的功能有什么区别吗?
glEnable(GL_STENCIL_TEST);
for(Portal portal : portals)
{
//PREPARE STENCIL BUFFER
glColorMask(false, false, false, false);
glDepthMask(false);
glStencilFunc(GL_NEVER, 1, 0xFF);
glStencilOp(GL_REPLACE, GL_KEEP, GL_KEEP);
glClear(GL_STENCIL_BUFFER_BIT);
portalShader.start();
renderPortal(portal, camera);
portalShader.stop();
glColorMask(true, true, true, true);
glDepthMask(true);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
glStencilFunc(GL_LEQUAL, 1, 0xFF);//Fill one or more
//Render scene that is visible through the portal
Camera newCam = portal.getDestinationCamera(camera);
List<Light> combinedLights = portal.getLights(lights);
float near = Vector3f.sub(portal.getDestination().getPosition(), newCam.getPosition(), null).length() - portal.getDestination().getScale().x / 2f;
Matrix4f projectionMatrix = Maths.createProjectionMatrix(Math.max(0.1f, near), 1000f, mainRenderer.FOV);
mainRenderer.entityShader.start();
mainRenderer.entityShader.loadProjectionMatrix(projectionMatrix);
mainRenderer.render(entities, combinedLights, newCam);
glClear(GL_DEPTH_BUFFER_BIT);
}
glDisable(GL_STENCIL_TEST);
//render portals to depth buffer
//render main scene
【问题讨论】:
-
您是否指定了包含模板缓冲区的像素格式?
-
不。非常感谢!!!
标签: opengl stencil-buffer