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

时间:2016-02-07 14:48:33

标签: opengl stencil-buffer

我在lwjgl / opengl中渲染我的世界中的门户。为了提高性能并使许多门户可以互相渲染,我尝试使用模板缓冲区将绘制的场景剪切到门户所在的位置。

但这仅适用于英特尔卡,而不适用于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

1 个答案:

答案 0 :(得分:2)

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

subsequences