I am having trouble using glGetTexImage with a depth texture of an FBO.
My FBO is set up like so:
GLfloat border[] ={ 1.0f, 0.0f, 0.0f, 0.0f};
// depth texture setup
m_DepthTexture.Create(dbFormat,m_Width,m_Height);
m_TextureID = m_DepthTexture.GetTextureID();
m_DepthTexture.SetFilterMode(GL_NEAREST,GL_NEAREST);
m_DepthTexture.SetWrapMode(GL_CLAMP_TO_BORDER,GL_CLAMP_TO_BORDER);
glBindTexture(GL_TEXTURE_2D, m_TextureID);
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, border);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE,
GL_COMPARE_REF_TO_TEXTURE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LESS);
// Assign the depth map to texture unit 0
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_TextureID);
// Create and set up the FBO
glGenFramebuffers(1,&m_FBOID);
glBindFramebuffer(GL_FRAMEBUFFER, m_FBOID);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
GL_TEXTURE_2D, m_TextureID, 0);
GLenum drawBuffers[] = {GL_NONE};
glDrawBuffers(1, drawBuffers);
GLenum status = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glBindTexture(GL_TEXTURE_2D,0);
if(status != GL_FRAMEBUFFER_COMPLETE)
{ return false; }
I draw to it like so:
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_FBOID);
// draw some things
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
And I attempt to copy the depth texture to system memory like so:
glBindTexture(GL_TEXTURE_2D, m_TextureID);
glGetTexImage(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
m_DepthImage.data);
glCheckErrorRetB();
glBindTexture(GL_TEXTURE_2D, 0);
The function glGetTexImage throws an error invalid operation;
This same code works in another project i have, but not in this project, so I am sure it has to do with some internal state that is being incorrectly set.
Any ideas?