如何在不支持GL_OES_packed_depth_stencil的设备(以Nexus 7 2012为例)上使用深度和模板初始化帧缓冲区?

这不起作用:

    glGenRenderbuffers(1, &depthStencil);

    glBindRenderbuffer(GL_RENDERBUFFER, depthStencil);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, width, height);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthStencil);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthStencil);

    GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
    //...

最佳答案

您为深度和模具创建单独的渲染缓冲区:

GLuint depthStencil[2];
glGenRenderbuffers(2, depthStencil);

glBindRenderbuffer(GL_RENDERBUFFER, depthStencil[0]);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);

glBindRenderbuffer(GL_RENDERBUFFER, depthStencil[1]);
glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, width, height);

glFramebufferRenderbuffer(GL_FRAMEBUFFER,
    GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthStencil[0]);
glFramebufferRenderbuffer(GL_FRAMEBUFFER,
    GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthStencil[1]);

10-05 18:05