I wanted to create a depth and stencil buffer for a new frame buffer object. But I got GL_FRAMEBUFFER_UNSUPPORTED error. This is how I was creating the buffers:
GLuint depthBuffer;
glGenRenderbuffers(1, &depthBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, SCR_WIDTH, SCR_HEIGHT);
glBindFramebuffer(GL_FRAMEBUFFER, gBuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBuffer);
GLuint stencilBuffer;
glGenRenderbuffers(1, &stencilBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, stencilBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, SCR_WIDTH, SCR_HEIGHT);
glBindFramebuffer(GL_FRAMEBUFFER, gBuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, stencilBuffer);
I couldn't get this to work so I ended up using a GL_DEPTH24_STENCIL8 texture format instead for both depth and stencil test like this:
GLuint depthStencil;
glGenTextures(1, &depthStencil);
glBindTexture(GL_TEXTURE_2D, depthStencil);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, SCR_WIDTH, SCR_HEIGHT, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, depthStencil, 0);
But there should be a way to use seperate depth and stencil buffers, right? Please tell me how to do it :) OpenGL Core 4.6
The API allows an implementation to support separate depth and stencil images in FBOs. That's (part of) why you can create and attach such images separately. The API does not require that any implementation supports this.
When the API gives you GL_FRAMEBUFFER_UNSUPPORTED
, that means the implementation doesn't support what you asked the framebuffer to do. And if it doesn't support it, there's nothing you can do to make it support it.
OpenGL explicitly requires support for combined depth/stencil images in FBOs. It does not require support for separate depth/stencil images in FBOs.