OpenGL framebuffer android without GL_OES_packed_depth_stencil (on Nexus 7 2012)

412 views Asked by At

How do I init the framebuffer with depth and stencil on a device which does not support GL_OES_packed_depth_stencil (In my case a Nexus 7 2012)?

This does not work:

    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);
    //...
1

There are 1 answers

2
Reto Koradi On BEST ANSWER

You create separate renderbuffers for depth and stencil:

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]);