Chapter 10 of OpenGL programming guide: Frame Buffer

Source: Internet
Author: User

After rasterazation, OpenGL obtains fragment. fragment is not the final pixel data, but corresponds to pixels. Fragment must be processed by a write, blend, texture, lighting ..., to get the final pixel. The buffer used to cache fragment data is frame buffer.

Fragment-related data includes color, stencel, depth, etc. Therefore, frame buffer can be said to contain several buffers, such as color buffer, stencel buffer, and depth buffer. Only color buffer is used for the final pixel display, and others are used to assist fragment processing.

1. Various Buffers and their usage the specific OpenGL implementation determines which buffer is available and the bit depth of each buffer. You can call glgetintegerv () to query the number of bits. ColorbuffersOpenGL that supports stereoscopic vision includes left color buffer and right color buffer. Otherwise, only left color buffer is supported. When double-buffer is supported, the first two buffers are split into front buffer and back buffer; otherwise, front buffer is available. OpenGL also has some color buffer that is not used for display, called auxiliary color buffer. The effect of these buffer is not specified by OpenGL, but determined by the user. For example, OpenGL can be used to store a pair of images that are used repeatedly. Depth bufferDepth buffer stores the depth of fragment, that is, the distance from the viewpoint. Depth buffer is also called Z buffer. Stencel BufferThe stencel buffer can limit the drawing to the specified part of the screen, for example, the scenario of passing through a window. Accumulation BufferThe accumulation buffer also stores the color value. This buffer accumulates some column images and obtains a final image, which can be used for super sampling antialiasing. 2. Buffer operations Clear BufferYou can use the following API to set the clearing values for each Buffer: void glclearcolor, void glcleardepth (glclampd depth), void glclearstencel (glint S), void glclearaccum (glfloat red, glfloat green, glfloat blue, glfloat alpha); you can use glclear to clear one or more buffers at a time. Select the target color buffer for read/writeFrom the preceding section, color buffer includes several buffers. You can select the target buffer through gldrawbuffer () and glreadbuffer, Buffer maskYou can set a mask for the buffer. Before the data is written to the buffer, bit-wise and computation is performed with the mask. Glcolormask (), gldepthmask (), glstencilmask (), glstencilmaskseparate (). 3. Fragment testing and Calculation

After OpenGL performs various transformations and rasterizes an element to obtain fragment, it also requires Calculation of some columns to determine whether fragment is required and how to enter the frame buffer.

First, we need to test some columns: Scissor TestScissor defines a rectangular area in the window, and the drawing is restricted within this rectangular area. Glscissor (glint X, glint y, glsizei width, glsizei height ). Scissor can be said to be a simplified version of stensor, and the speed is faster. Alpha testThe Alpha test is based on the fragment Alpha value to determine whether to discard fragment. This test is to compare it with a specific value. The comparison operation and reference value are determined by the API glalphafunc (glenum func, glclampf ref. Stencel TestCompare the value in stencel buffer with a reference value and determine whether to accept fragment based on the comparison result. It also determines whether to modify the value of stencel buffer. Depth TestCompare the fragment depth with the value in the current depth buffer. If the value is greater than the value, fragment is discarded; otherwise, the value in the depth buffer is replaced. You can use gldepthfunc (glenum func) to set the comparison function. Blending, dithering, and logical operationsThe blending operation is performed based on the alhpa value of the input fragment and the Alpha of the corresponding fragment in the frame buffer. Logical meta-calculation combines the values in framgment and frame buffer with logical elements. gllogicop () can specify the operation type. 4. In addition to frame buffer inherent in the window system, frame buffer objects can be created for off-screen rendering. Frame Buffer object is similar to a special buffer object. Use glgenframebuffers to generate the object name. glbindframebuffer is bound to FBO and initialized. gldeleteframebuffers deletes FBO. Glbindframebuffer (glenum target, gluint framebuffer); target = gl_draw_framebuffer specifies the write purpose FBO, gl_read_framebuffer specifies the read purpose FBO, and gl_framebuffer specifies both. After FBO is created, the image cannot be drawn. Therefore, the target buffer, that is, the render buffer object, must be provided to FBO. Renderbuffer contains specific image data. glgenrenderbuffers generates the object name. glbindrenderbuffer binds the name to renderbuffer, and glrenderbufferstorage allocates storage space for Rander buffer. Now let's talk about the renderbuffer attach to FBO, glframebufferrenderbuffer (glenum target, glenum attachment, glenum renderbuffertarget, gluint renderbuffer); target is consistent with glbindframebuffer, attachment = Accept, accept, accept, or reply _
Attachment, renderbuffertarget = gl_renderbuffer, renderbuffer = renderbuffer name. You can use FBO to create a dynamic texture, and glframebuffertexture * D can be bound to FBO. After FBO configuration is complete, it may be unavailable. glcheckframebufferstatus checks FBO and provides error suggestions.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.