OpenGL frame cache

xiaoxiao2021-03-06  43

(Reference is "OpenGL Programming Authority Guide", which is the legendary "Red Book") 1. Classification of cache 1. Color Cache means the cache used by programmer drawing, divided into: left, right lap - use For stereoscopic views (must have left cache); before, then lap - for dual cache (must have a caching); 4 auxiliary cache - optional, not displayed (programmers can define and use themselves they). 2. Depth cache is used to store depth values ​​for each pixel, also known as Z cache. 3. Template cache can be made in some parts of the screen. 4. Cumulative cache contains RGBA color data, usually used to add a series of images to a final synthetic image. Pixels cannot be drawn directly into the cumulative cache, and the accumulation operations are often performed in the rectangular block, and then exchange data with the color cache. Second, the operation of the cache 1. Clear the cache (1). Specify the clear value to write to the cache: GlclearColor () - Set the clear value (Red, Green, Blue, Alpha); GLCLEARINDEX () - for color Index Cache Setting Clear Value (INDEX); GLCLEARDepth () - Sets the value for depth cache (default is 1.0); GLCLEARSTENCIL () - Set the clear value for the template cache (default is 0.0); glcleraCcum () - is accumulated Cache Setting Clear Value (Red, Green, Blue, Alpha); (2). Clear the specified cache: GLCLEAR (GLBITFIELD MASK); MASK's value is GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT and GL_ACCUM_BUFFER_bit and GL_ACCUM_BUFFER_BIT and other constants in position logic or (or) . Multiple caching can be cleared at a time, such as hardware supports simultaneous clearance, then perform simultaneously; otherwise, each cache is cleared in order. 2. Selecting the result of the color cache drawing operation for the read and write operation. The result can be placed in any color cache: before, after, left, left, left, right, right, or any, one, the programmer can choose a single cache as a drawing target or Read the target. For drawing graphics, you can also draw the target simultaneously into several caches, using the GLDRAWBuffer () function to select the cache to be written; use the GLReadbuffer () function to select Cache, as Glreadpixels (), GLCopyPixels (), GlcopyTexImage * () And GLCopyTexSubImage * () application targets. 3. Cache Mask (Mask) OpenGL You need to shield the data to the mask specified by the following functions before writing data to the active color, depth, and template cache. Each mask is to operate with the corresponding data to be written to (AND). Void Glindexmask; Mask defaults to 1. If a mask appears in the mask, the corresponding bit in the color index mode is written; and the bit appears in 0, it is not written. Void Glcolormask (Glboolean Red, Green, Blue, Alpha); Default is GL_TRUE, indicating that the corresponding component is written; if GL_FALSE, no write.

Void GlDepthmask; default is GL_TRUE, indicating that the depth cache is activated for write operation; if GL_FALSE, cancel. Void GlstencilMask (Gluint Mask); default is 1, and color index is similar. Second, the test and operation of the chief, in OpenGL, it is determined that the chill should be generated and the color is still needed to control how the chief is drawn as a pixel into the frame buffer, and determine if it is necessary. do. This section describes a complete test set that must pass before placing a frame cache, and describes the last operation that may be performed at the time of writing. Testing and operations are performed in the following order. If the groups in the previous test are deleted, the following tests or operations are not performed. · Dip Test · Alpha Test · Template Test · Depth Test · Mixed · Jitter · Logic Operation 1. Cut Test Cut Test is just a template test of the template test using the screen rectangular area, but because it is easy to use hardware to be quickly implemented, The template that is performed in software is fast. With the GLSCIissor () function, you can define a rectangular area in the window and limit the mapping. If the film is falling in the rectangular area, then the test is passed, otherwise the group is deleted. Void Glscissor (GLINT X, GLINT Y, GLSIGHT); GLENABLE (GL_SCISSOR_TEST): Activate the cut test; GLDISABLE (GL_SCISSOR_TEST): Cancel the test. By default, the rectangle is identical to the size of the window, and the cut is canceled. 2. Alpha Test In RGBA mode, according to the alpha test in the alpha test, it is determined whether to receive or reject a piece. Glenable / gldisable (GL_Depth_test): Activation / Cancel ALPHA Test GLALPHAFUNC Sets the reference value and comparison function of Alpha test: Void GLALPHAFUNC (Glenum Func, GlcLAMPF Ref); Reference value REF is intercepted between 0 and 1. The possible value of the parameter FUNC is as follows: GL_NEVER: Never accept the chief; GL_ALWAYS: Always accept the chief; GL_SS: If the unit Alpha Refer to Alpha, Accepted; GL_NOTEQUAL: Cell Alpha ≠ Refer to Alpha, Accept; 3. Template test only occurs without template cache. If there is no template cache, the template test is always passed. Template is suitable for this test, which compares the pixel value stored in the template cache to the reference value, according to the result of the comparison, modify the value in the template cache. Void GlstencilFunc (Glenum Func, Glint Ref, Gluint Mask); This function is a template test setup comparison function (FUNC), reference value (REF), and mask (MASK).

With the comparison function, the reference value and the value in the template cache can be compared, and the bit is only 1 bit having only 1 position 1 only for the mask. The possible value of the comparison function is the same as the possible value of the comparison function in GLALPHAFUNC (), but the meaning is the opposite. Void GltenciloP (Glenum Zpass); How this function describes how to fix data in the template cache when the chief pass or not pass the template test. Three parameters fail, zfail, zpass can be: GL_keep: Keep the current value GL_ZERO: replace GL_REPLACE with 0 Replacement GL_INCR: Increase this value (between 0 ~ Maximum No symbol integer value) GL_DECR: reduce this value (Between 0 ~ Maximum No Symbol Integer) GL_INVERT: Pressing the value by bit by bit to test the template test, then apply the FAIL function; if the unit is tested by the template, the depth test failed, applied ZFAIL functions If the group is tested through the template, the Zpass function is applied by depth testing or without depth test. By default, three template operations are GL_KEEP. The most typical application of the template test is to block the irregular area of ​​the screen to avoid being mapped in this area. 4. Depth Test For each pixel on the screen, the depth cache time tracks the distance between the viewpoints and the object of the pixel. If the depth test is passed, the input depth value will replace the corresponding value in the depth cache. Depth caching is usually used to eliminate operation of hidden surfaces. Initially, the depth cache is usually filled with the value as far as possible, so the depth of any object is closer than the initial state. Glenalbe (GL_DEPTH_TEST); // Activates depth test GLCLEARDEPTH (1.0); // Clear depth cache can be used to select different comparison functions for depth tests with the GLDEPTHUNC () function. Void GlDepthfunc (Glenum Func); This function is a comparison function for depth test settings. The value of FUNC must be GL_NEVER, GL_ALWAYS, GL_Ess, GL_LEQUAL, GL_EQUAL, GL_GEQUAL, GL_GREATER, or GL_NOTEQUAL. If the z value meets the value in the depth cache satisfies the determined relationship, the input card element is tested by depth. 5. Mixing, Jitter, and Logic Operation Once entered the entered film passes all the tests, it can be combined with the current content in the color cache. The simplest method is also the default operation, that is, override the current value. In RGBA mode, if you want the chill to be translucent or eliminate the sawtooth phenomenon, the programmer can make the value in the cache as average, ie mixed. For systems having fewer colors, the number of available colors can be increased by a sacrificial resolution. The jitter operation is related to the hardware, and OpenGL allows the programmer to operate only if the jitter operation is turned on or off. In fact, if the resolution of the machine is quite high, there is no meaning at all of the activation jitter operation. To activate or cancel the jitter, you can use Glenable (GL_DITHER) and GLDISABLE (GL_DITHER) functions. By default, jitter is activated. In the color index mode, an arbitrary bitwise logic can be utilized to synthesize the input tablets with the written pixels. Note: Please refer to "The Office Guide to Learning OpenGL" (Red Book)

转载请注明原文地址:https://www.9cbs.com/read-68678.html

New Post(0)