I have this strange problem about reading from depth-stencil texture
I tried to add stencil test to my already working deferred rendering engine.
So I create FBO with the following pack depth-stencil attachment.
glGenTextures(1, &depthBufferTexID);
glBindTexture(GL_TEXTURE_2D, depthBufferTexID);
/*1*/glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, width, height, 0, GL_DEPTH_STENCIL,GL_UNSIGNED_INT_24_8, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_NEAREST);
/*2*/glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D,depthBufferTexID, 0);
I attached depth-stencil as a texture instead of render buffer
so that I can directly read from depth texture in lighting pass(to reconstruct vertex position ,etc…)
Actually the only thing I change from my whole source code is the line mark with /1/ and /2/
But after reading from the depth-stencil texture(to reconstruct vertex position in lighting pass),the depth-stencil texture appear to be corrupt.
Any depth-testing enabled rendering perform after the depth-stencil texture reading appered to had some weird hole on them,it is very hard to describe (picture below).
If I comment out the texture reading pass(the deferred lighting pass on background geometry),the subsequence rendering pass appeared correct.
I dont think there are anything in the rendering process that can cause this,If I remove the line /1/ and /2/ and go back to using depth only attachment every thing worked again.
Note that in the whole process I didn’t even doing any stencil-related operation once.
Has anyone ever encouter something like this ?
test on ATI HD4670 with 10.5 driver.
Thank in advance.