0
votes

i am implementing render to texture concept and have doubt regarding scope of a FBOs. After i am done with glDrawArrays call on default FBO with render to texture, i am deleting texture and non default FBO. Then i am calling glReadPixels to read contents on default FBO. So, my question is am i doing it right i mean should i call readpixel before deleting FBO and texture?

What i was assuming that after drawing it on default FBO we dont need non default FBO and texture but later some developer of OpenGL told me i am doing some strange things in my application referring to above. Please help me to understand this.

Here are the steps i am following:

  1. create a framebuffer object and attach a suitable texture as color attachment
  2. bind and clear the FBO
  3. render some primitives
  4. unbind the FBO thus switiching back to the system FBO
  5. bind the texture used as color attachment
  6. Render on system FBO with texture created above.
  7. delete texture and FBO created.
  8. glReadpixel from system FBO.

Now, as i have rendered on system FBO and it. why do we still need that texture and other FBO which were used as textures?

Note: I am using terms system FBO to just differentiate between two FBOs its my terminology.

1
You mean deleting the FBO inputs, or the attached FBO output texture? Once you've rendered to the output texture, you're done with the FBO. Won't make any difference if you delete it. As long as you keep the target (attached output) texture around and don't delete that of course.Robinson
I think the strange thing was, that you recreate and delete the intermediary FBO and texture for each and every drawing iteration. That's slow and inefficient. Normally you create them only once and then recycle them. You only delete and recreate them, when a change of the dimensions require it.datenwolf
@datenwolf: I don't have a loop, it is only 1 frame.debonair
@Robinson: I mean FBO created by glGenBuffer call and texture which is color attachment to it.debonair

1 Answers

0
votes

I suggest reading this: http://www.songho.ca/opengl/gl_fbo.html

but all in all here is a bit of pseudo code for Render To Texture in OpenGL

init() {
    // setup FBO, attachments, etc...
}

render() {
    glBindFramebuffer(your_fbo);
    glClearBuffer(...);
    renderScene();

    glBindFramebuffer(0);  // setup default, system FBO
    glBindTexture(texture_id_that_was_attached_to_FBO);
    renderSecondScene();
}

there is no need to delete textures or fbo after you render your scene, delete them at the end of application in some cleanup proc.