OpenglES学习3 FBO RBO

1.FrameBuffer

1.1 为什么需要FBO

系统提供的framebuffer不适用于所有场合。比如:
many applications need to render to a texture, and for this using the window system provided framebuffer as your drawing surface is usually not an ideal option. Examples of where render to texture is useful are dynamic reflections and environment-mapping, multipass techniques for depth-of-field, motion blur effects, and post-processing effects.

1.2 什么是FBO

A framebuffer object (often referred to as an FBO) is a collection of color, depth, and stencil buffer attachment points; state that describes properties such as the size and format of the color, depth, and stencil buffers attached to the FBO; and the names of the texture and renderbuffer objects attached to the FBO. Various 2D images can be attached to the color attachment point in the framebuffer object. These include a renderbuffer object that stores color values, a mip-level of a 2D texture or a cubemap face, or even a mip-level of a 2D slice in a 3D texture. Similarly, various 2D images containing depth values can be attached to the depth attachment point of an FBO. These can include a renderbuffer, a mip-level of a 2D texture or a cubemap face that stores depth values. The only 2D image that can be attached to the stencil attachment point of an FBO is a renderbuffer object that stores stencil values.

  • FBO API 支持系列操作

• Creating and using multiple framebuffer objects within a single EGL context; that is, without requiring a rendering context per framebuffer.
• Creating off-screen color, depth, or stencil renderbuffers and textures, and attaching these to a framebuffer object.
• Sharing color, depth or stencil buffers across multiple framebuffers.
• Attaching textures directly to a framebuffer as color or depth and avoiding the need to do a copy operation.

1.3 如何使用FBO

  1. 创建
1
2
3
void glGenFramebuffers(GLsizei n, GLuint *ids)
n:number of framebuffer object names to return
ids:pointer to an array of n entries, where allocated framebuffer objects are returned

ids是大于0的,等于0表示失败。

  1. glBindFramebuffer
1
2
3
void glBindFramebuffer(GLenum target, GLuint framebuffer)
target:must be set to GL_FRAMEBUFFER
framebuffer:framebuffer object name

在使用framebuffer之前,需要把framebuffer 设置为当前 fbo.
The first time a framebuffer object name is bound by calling glBindFrame-buffer, the framebuffer object is allocated with appropriate default state, and if the allocation is successful, this allocated object is bound as the current framebuffer object for the rendering context.

  1. glDeleteFramebuffers
1
2
3
void glDeleteFramebuffers(GLsizei n, GLuint *framebuffers)
n:number of framebuffer object names to delete
framebuffers:pointer to an array of n framebuffer object names to be deleted

Once a framebuffer object is deleted, it has no state associated with it and is marked as unused and can later be reused as a new framebuffer object. When deleting a framebuffer object that is also the currently bound framebuffer object, the framebuffer object is deleted and the current frame-buffer binding is reset to zero. If framebuffer object names specified in framebuffers are invalid or zero, they are ignored and no error will be generated.

2.RenderBuffer

1.1 为什么需要RBO

1.2 什么是RBO

A renderbuffer object is a 2D image buffer allocated by the application. The renderbuffer can be used to allocate and store color, depth, or stencil values and can be used as a color, depth, or stencil attachment in a framebuffer object. A renderbuffer is similar to an off-screen window system provided drawable surface, such as a pbuffer. A renderbuffer, however, cannot be directly used as a GL texture.

1.3 如何使用RBO

文章目录
  1. 1. 1.FrameBuffer
    1. 1.1. 1.1 为什么需要FBO
    2. 1.2. 1.2 什么是FBO
    3. 1.3. 1.3 如何使用FBO
  2. 2. 2.RenderBuffer
    1. 2.1. 1.1 为什么需要RBO
    2. 2.2. 1.2 什么是RBO
    3. 2.3. 1.3 如何使用RBO
|