Jump to content
  • Advertisement
Sign in to follow this  
Ender1618

Having trouble using glGetTexImage with a depth texture of an FBO

This topic is 924 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement

Make sure m_TextureID is valid at the time you call getTexImage. You could try creating a 2D texture right before and calling getTexImage on that instead. Are you sure that the texture is filled with data, try glTexImage2D() before getTexImage. See if TexImage2D fails as well.

Share this post


Link to post
Share on other sites

to even start with depth with FBO you need to create valid renderbuffer.

 

//not sure if thats supported.

m_DepthTexture.SetFilterMode(GL_NEAREST,GL_NEAREST); 
m_DepthTexture.SetWrapMode(GL_CLAMP_TO_BORDER,GL_CLAMP_TO_BORDER);

 

//not sure if thats even deprecated
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);

void init()
{
glGenTextures(1, &SHADOW_DEPTH_TEX);
glBindTexture(GL_TEXTURE_2D, SHADOW_DEPTH_TEX);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, RENDER_BUFF_W, RENDER_BUFF_H, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);



glGenFramebuffers(1, &SHADOW_FBO1);
glGenRenderbuffers(1, &SHADOW_RBO1);
glBindRenderbuffer(GL_RENDERBUFFER, SHADOW_RBO1);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, RENDER_BUFF_W, RENDER_BUFF_H);
glBindFramebuffer(GL_FRAMEBUFFER, SHADOW_FBO1);
glBindTexture(GL_TEXTURE_2D, SHADOW_DEPTH_TEX);
glFramebufferRenderbuffer(GL_FRAMEBUFFER,
                          GL_DEPTH_ATTACHMENT,
                          GL_RENDERBUFFER,
						  SHADOW_RBO1);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, SHADOW_DEPTH_TEX, 0);
}


where
unsigned int SHADOW_FBO1;
unsigned int SHADOW_RBO1;
unsigned int SHADOW_DEPTH_TEX;

thus

 

GL_INVALID_OPERATION is generated by glGetTextureImage if texture is not the name of an existing texture object.

GL_INVALID_OPERATION is generated if type is one of GL_UNSIGNED_BYTE_3_3_2GL_UNSIGNED_BYTE_2_3_3_REVGL_UNSIGNED_SHORT_5_6_5,GL_UNSIGNED_SHORT_5_6_5_REV, or GL_UNSIGNED_INT_10F_11F_11F_REV and format is not GL_RGB.

GL_INVALID_OPERATION is generated if type is one of GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1,GL_UNSIGNED_SHORT_1_5_5_5_REV, GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV, GL_UNSIGNED_INT_10_10_10_2,GL_UNSIGNED_INT_2_10_10_10_REV, or GL_UNSIGNED_INT_5_9_9_9_REV and format is neither GL_RGBA or GL_BGRA.

GL_INVALID_OPERATION is generated if format is GL_STENCIL_INDEX and the base internal format is not GL_STENCIL_INDEX or GL_DEPTH_STENCIL.

GL_INVALID_OPERATION is generated if a non-zero buffer object name is bound to the GL_PIXEL_PACK_BUFFER target and the buffer object's data store is currently mapped.

GL_INVALID_OPERATION is generated if a non-zero buffer object name is bound to the GL_PIXEL_PACK_BUFFER target and the data would be packed to the buffer object such that the memory writes required would exceed the data store size.

GL_INVALID_OPERATION is generated if a non-zero buffer object name is bound to the GL_PIXEL_PACK_BUFFER target and pixels is not evenly divisible into the number of bytes needed to store in memory a datum indicated by type.

GL_INVALID_OPERATION is generated by glGetTextureImage and glGetnTexImage if the buffer size required to store the requested data is greater thanbufSize.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!