模板缓冲区在不同显卡上的作用不同

Stencil buffer acts differently on different graphics cards

我正在 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

哎呀。我在创建显示时忘记请求模板缓冲区。

Display.create(new PixelFormat(32, 0, 24, 8, 0),attribs);