Sign in to follow this  
B_old

glGetTexImage/glGetTextureImageEXT with render to texture and FBO

Recommended Posts

B_old    689

I render to the individual faces of  a cubemap by setting different views on the cubemap texture on the bound FBO.

After rendering is done I want to download the texture data using glGetTextureImageEXT.

I read somewhere that I should unbind the FBO before calling glGetTextureImageEXT. If I do that the first call to glGetTextureImageEXT works as expected, but the second call gives all zeros.

However, if I bind the FBO, set with the different texture views, before glGetTextureImageEXT, I get exactly the data I expect. The most confusing thing is, that it works a single time when no FBO is bound. 

(I tried it with glGetTexImage and it behaves exactly the same.)

Any idea how this is supposed to behave?

Share this post


Link to post
Share on other sites
richardurich    1352

You can use glFramebufferTexture2DEXT to attach a texture and render to it instead of getting the data after. Make sure you don't have it auto-generating mipmaps.

 

You can use a PBO, glReadBuffer(GL_COLOR_ATTACHMENT_0), glReadPixels to get data after you render.

 

I'm not familiar with the process you're describing, but you should definitely provide minimized code that demonstrates the problem when asking for help with this stuff. Rendering to texture is always a multi-step process with a lot of setup and such that you can get wrong, so it's hard to just guess where you went wrong. If you can't provide sample code and need to stick with this approach, what result do you get if you replace glGetTexImage with glCopyTexImage? At least that would help narrow down the cause.

Share this post


Link to post
Share on other sites
B_old    689

Ok, it seems like I provided a bad description.

 

What I am doing is rendering to texture and then I want to download the data to the CPU. As far as I know PBOs are only a means of meaking the downloading stuff asynchronous, which can be a performance win if handled smartly.

 

Anyway, glGetTextureImageEXT should download the texture data to system memory, but it only works the "first" time for me. Unless I bind the FBO which I used to render to the texture in the first place. And this is contradictory to some information I found on this topic. 

Share this post


Link to post
Share on other sites
richardurich    1352

I think the FBO restriction is just that it's not supposed to be an active render target when reading data from it, and unbinding it ensures it's not active. When you read from an active target framebuffer, I think the results are undefined. So you might see results that make sense right now, but you might see different results on a different video card or different results when you change what you are rendering.

 

Without more detailed code or more information, I can't narrow down why you're seeing the results you're seeing. Are you following a certain tutorial about rendering a cubemap? Is there any other information you can share?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this