4

Brad Larson provides some great code here and here for 'rendering your scene into a texture-backed framebuffer', but it's not clear whether this is the same framebuffer that I use for the rest of the drawing.

If you attach a renderbuffer to a framebuffer, can the framebuffer also render into a texture with the same call?

1 Answer 1

3

Sounds like you might be a bit confused with FBO usage. If you need it, this should get you started: Apple Developer - Drawing offscreen. This could help too.

Renderbuffer is something you can bind to an FBO (framebuffer object). FBO is something you create when you don't want your rendering to be displayed immediately, but want to read the rendering result back or perform additional rendering to it. The way FBOs work in OpenGL ES 2.0, you have only one color attachment point available (GL_COLOR_ATTACHMENT0 - your fragment shader output variable gl_FragColor is connected to this attachment point), and it can only have one texture or renderbuffer attached to it. So to answer that last question, you cannot have an FBO that would simultaneously write color to a renderbuffer and a texture.

As for the first part of your question, it depends whether you are already using an FBO or the default framebuffer. Chances are the behavior you're looking for is something like this:

  1. bind an FBO
  2. render something to a texture attached to the FBO
  3. bind the default framebuffer
  4. use the texture from step 2 to affect rendering in your second renderpass.

Hope this answers your question even a little bit.

4
  • Hmm - maybe I am confused. I have to generate and bind my framebuffer is this what you mean by default framebuffer? I can't render to the texture, and then render the texture onscreen? Commented Aug 28, 2013 at 15:35
  • Default framebuffer is where you render to by default, you don't have to do anything to get that. Framebuffer objects are what you can render to instead, and that's called "off-screen rendering" by some. If you do that, you end up with your image in a texture instead of the default framebuffer (that gets displayed on-screen). You can copy the image from that texture to the default framebuffer (on-screen), that's usually done with blitting (but it's only available in OpenGL ES 3.0). But if you only wanted to show the image on-screen, you probably wouldn't use a FBO in the first place. Commented Aug 28, 2013 at 17:32
  • @ArttuPeltonen I have created a question (stackoverflow.com/questions/19662413/…) based on your last comment. Please could you kindly take a look?
    – MatterGoal
    Commented Oct 29, 2013 at 15:27
  • 3
    A quick note about binding the default framebuffer is that the default framebuffer is not 0, but the buffer you created when setting up the EAGLContext. To get that, you either save the name when creating it. Or call this to get the name at step 0 (before bind a new FBO): (swift code below): var defaultFrameBuffer: GLint = 0 glGetIntegerv(GLenum(GL_FRAMEBUFFER_BINDING), &defaultFrameBuffer) And then at step 3 mentioned above, you bind back the default framebuffer: glBindFramebuffer(GLenum(GL_FRAMEBUFFER), GLuint(defaultFrameBuffer)). The defaultFrameBuffer is not 0 as you will see.
    – Zhao
    Commented Sep 12, 2015 at 1:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.