Newbie questions: Pixel versus Frame buffer?

Started by dime, April 25, 2011, 03:57:43

Previous topic - Next topic

dime

I'm not sure if I understand the differences between Pixel Buffer and Frame Buffer.

What I'm looking to do is:

A load a texture (into pixel buffer?)
Modify it (with a fragment shader)
Display it.

On a high level is that I want I want to do?  What I mean, is should the "buffer/texture" that I'm modifying be a separate one from the one I'm display?

That is:
Load a texture (into pixel buffer?)
Loop start()
Modify the pixel buffer (with a fragment shader)
copy it to a frame buffer [?]
Display the frame buffer [?]
Loop end;




spasi

Pixel buffer in OpenGL usually means a buffer object that holds pixel data, a.k.a. PBO (a PIXEL_UNPACK_BUFFER or PIXEL_PACK_BUFFER). See Pixel Storage Modes and Pixel Buffer Objects in the OpenGL spec (chapter 3.7).

Framebuffer is one of two things: The framebuffer that contains the display's fragment data or a framebuffer object, a.k.a. FBO (chapter 4.4 in the OpenGL spec).

To do what you describe you basically do the following:

- Load a texture. This can be any normal texture, no need to use a PBO.
- Create an FBO and attach a texture to it. The attached texture will be used as the render-target.
- Loop start
    - Bind the FBO and the fragment shader, render the original texture.
    - Unbind the FBO and fragment shader and render to the display using the render-target texture.
    - SwapBuffers.
- Loop end

You can also ping-pong between the original and render-target textures, so each frame the source texture becomes the previous-frame's target texture. You can do this with either changing the FBOs attachement each frame, or simply using two FBOs (one for each texture) and swapping between them.

Chapter 4.4 describes all you need to know to render using FBOs. You can also check the ARB_framebuffer_object spec for some example code.

dime

thanks for the post.  Chapter 4.4 of what?

I don't understand this part, why two renders?

-  Bind the FBO and the fragment shader, render the original texture.
- Unbind the FBO and fragment shader and render to the display using the render-target texture.