I’m attempting to implement deferred shading. I’ve got a number of problems with it, but first and foremost, depth testing is not working right.
In my deferred shading, I create a depth buffer, naturally. Depth testing works fine with this. But if I create a depth and stencil buffer, depth testing just doesn’t work. It’s peculiar.
Buffer creation, depth component only, depth testing works:
glBindTexture(GL_TEXTURE_2D, depth_map); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL); glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depth_map, 0);
Buffer creation, depth and stencil components, depth testing doesn’t work:
glBindTexture(GL_TEXTURE_2D, depth_map); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH32F_STENCIL8, width, height, 0, GL_DEPTH_STENCIL, GL_FLOAT, NULL); glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, depth_map, 0);
This is literally the only change to my code, and depth testing works for the first one, and fails for the second one. Stencil test is disabled, depth test enabled for both. Any suggestions to fix this problem? I have read several threads regarding similar issues, suggesting this was an AMD driver problem, and indeed I have an AMD card. Hopefully I’m just doing something wrong.