29

what is the Difference between Frame buffer object, Render buffer object and texture? In what context they will be used?

Megharaj
  • 1,483
  • 2
  • 20
  • 31
  • See a question.http://stackoverflow.com/questions/2213030/whats-the-concept-of-and-differences-between-framebuffer-and-renderbuffer-in – Shree Apr 12 '12 at 04:42
  • @shree "It allows to render a scene directly to a renderbuffer object, instead of rendering to a texture object." Why do we need to render to render buffer or Texture we need to render to frame buffer object right? – Megharaj Apr 12 '12 at 05:43

2 Answers2

31

Framebuffer

A framebuffer is not actually a buffer. It's an abstraction for an object that defines parameters for a draw operation. It's a small object that holds one or more attachments, which are themselves the actual buffers. Understand the framebuffer as a C struct with many fields. Each field (each attachment in OpenGL terms) can be a pointer to a render buffer, texture, depth buffer, etc.

Texture

An array of standard pixels. This is an actual buffer and can be attached to a framebuffer as the destination of pixels being drawn. Each pixel in a texture typically contains color components and an alpha value (a pixel in the texture can be translated from and into an RGBA quad with 4 floats).

After drawing to the framebuffer that contains a texture attached, it's possible to read pixels from the texture to use in another draw operation. This allows, for instance, multi-pass drawing or drawing a scene inside another scene.

Textures can be attached to a shader program and used as samplers.

Renderbuffer

An array of native pixels. The renderbuffer is just like a texture, but stores pixels using an internal format. It's optimized for pixel transfer operations. It can be attached to a framebuffer as the destination of pixels being drawn, then quickly copied to the viewport or another framebuffer. This allows implementing of double buffer algorithms, where the next scene is drawn while the previous scene is exhibited.

A renderbuffer can also be used to store depth and stencil information that is used just for a single draw procedure. This is possible because only the implementation itself needs to read renderbuffer data, and tends to be faster than textures, because uses a native format.

Because this uses a native format, a renderbuffer cannot be attached to a shader program and used as a sampler.

fernacolo
  • 5,982
  • 4
  • 35
  • 57
  • 1
    The most clearest explain about these buffers I've ever heard, and point out the different use cases of each objects. Great! – Jim Tang Nov 13 '18 at 14:02
22

A framebuffer object is more or less just a managing construct. It manages a complete framebuffer at a whole with all its sub-buffers, like the color buffers, the depth buffer and the stencil buffer.

The textures or renderbuffers comprise the actual storage for the individual sub-buffers. This way you can have multiple color buffers, a depth buffer and a stencil buffer, all stored in different textures/renderbuffers. But they all together make up a single logical framebuffer into which you render.

So a final fragment (you may call it pixel, but actually isn't one yet) written to the framebuffer has one or more color values, a depth value and a stencil value and they all end up in different sub-buffers of the framebuffer.

Christian Rau
  • 43,206
  • 10
  • 106
  • 177
  • 1
    thanks for the replay. GOt an Idea of frame buffers so they are final rendering buffers. But how about these render buffer ? i know textures but why and when must we use render buffers? – Megharaj Apr 12 '12 at 07:21
  • 1
    @Megharaj Renderbuffers were needed at the time framebuffer objects were introduced since textures couldn't be used as depth or stencil attachments, I think, let aside multisample framebuffers. But with the advent of multisample textures renderbuffers are not really needed anymore. They basically just provide the storage for a buffer of memory to be rendered into, but cannot be used for much else. – Christian Rau Apr 12 '12 at 07:54
  • @ChristianRau Could one then safely use textures instead of renderbuffers in *every* offscreen rendering conditions (in ES 2.X)? – Bartek Banachewicz Jan 11 '13 at 14:55
  • @BartekBanachewicz I'm not so certain about OpenGL ES. I'm pretty sure ES doesn't support multisample textures. So if you need a multisampled FBO, you will need a renderbuffer. Likewise if ES doesn't support depth or stencil textures (not sure about that). So no, definitely not *every* condition. – Christian Rau Jan 11 '13 at 15:15