Document directory
- 10.2.3 template Test
- 10.2.4 deep Test
- 10.3.3 depth of field
In the OpenGL window, the pixels in the lower left corner are (0, 0 ). in general, the lower left corner of the rectangle occupied by pixels (X, Y) is (x, y), and the upper right corner is (x + 1, Y + 1 ).
10.1 cache and Its Usage
1) color cache, left front, right front, left back, right back, and any number of secondary color caches;
2) Deep Cache
3) template Cache
4) cumulative Cache
Note: In the X Window System, the rgba mode must have at least one color buffer, template buffer, depth buffer, and accumulative buffer.
The color index mode ensures at least one eye color buffer, depth buffer, and template buffer.
You can use the glxgetconfig {} function to query.
Use glgetintegerv () to query the cache space occupied by each pixel
Gl_red_bits, gl_green_bits, gl_blue_bits, gl_alpha_bits --- number of digits of the R, G, B, And a components in the color Cache
Gl_index_bits --- the number of digits of each color index in the color Cache
Gl_depth_bits --- the number of bits in each pixel in the deep Cache
Gl_stencil_bits --- number of digits in each pixel in the template Cache
Gl_accum_red_bits, gl_accum_green_bits, gl_accum_blue_bits, gl_accum_alpha_bits --- the bits of R, G, B, And a in the cumulative cache.
10.1.1 color Cache
1) color cache stores color indexes or RGB color data, and may also store Alpha values.
2) supports the left color cache and right color cache for OpenGL Implementation of stereoscopic viewing, which are used for Left and Right stereo images respectively.
3) If three-dimensional observation is not supported, only the left color cache is used.
4) The dual-color cache includes the front cache and the back cache, and the single cache system only has the front cache.
5) support secondary color caching that cannot be displayed
6) The glgetbooleanv () function queries whether stereoscopic observation and dual cache are supported: gl_stereo and gl_double_buffer.
The glgetintegerv () function queries how many secondary caches are available: gl_aux_bufferes.
10.1.2 deep Cache
Deep cache stores the depth values of each pixel, usually the distance from the viewpoint. Therefore, pixels with a large depth value will be overwritten by pixels with a small depth value.
10.1.3 template Cache
Purpose 1: The drawing scope is limited to a specific area of the screen.
10.1.4 cumulative Cache
The cumulative cache also stores rgba color data to synthesize a series of images.
You can oversample the image, then average the sample, and write the result into the color cache, so as to implement reverse sampling. data cannot be directly written to the cumulative cache.
The Accumulate operation always targets a rectangle block. It usually moves data into or out of the color cache.
10.1.5 clear Cache
Void glclearcolor (glclampf red, glclampf green, glclampf blue, glclampf alpha );
Void glclearindex (glfloat index );
Void glcleardepth (glclampd depth );
Void glclearstenpencil (glint S );
Void glclearaccum (glfloat red, glfloat green, glfloat blue, glfloat alpha );
Function: Specify the values used to clear the color cache (rgba mode or color index mode), deep cache, template cache, and cumulative cache.
Parameters of the type glclampf and glclampd are intercepted to [0.0, 1.0]. The default clear value of the Depth cache is 1.0, and the value of other caches is 0.0.
After setting the clear value, you can call the glclear () function to clear the cache.
Void glclear (glbitfield mask );
Function: clears the specified cache.
Mask: gl_color_buffer_bit, gl_depth_buffer_bit, gl_stencil_buffer_bit, gl_accum_buffer_bit logic or (OR ).
When the color cache is cleared, if the pixel ownership test, cropping test, and jitter operations are enabled, they are all executed in the clear operation.
The blocking operation (glcolormask () and glindexmask () will also take effect. Alpha test, template test, and deep test will not affect the operation of the glclear () function.
10.1.6 specify the color cache for read/write
Specify the cache gldrawbuffer () to be written ();
Specify the cache glreadbuffer () to be read ();
The dual cache is used. It is usually cached only after being drawn, and cached after being drawn. you may want to regard the Double Cache window as a single cache window: by calling the gldrawbuffer () function, you can draw both the pre-Cache and post-cache.
Void gldrawbuffer (glenum mode );
Function: Specify the color cache to be written or removed, and disable the previously enabled color cache. Multiple caches can be enabled at one time.
Gl_front: default value of a single cache
Gl_front_right:
Gl_none:
Gl_front_left:
Gl_front_and_back:
Gl_right:
Gl_auxi: I indicates the number of secondary caches.
Gl_left:
Gl_back_right:
Gl_back: Default Value of Double Cache
Gl_back_left:
Note: When multiple caches are enabled for write operations, no error will occur if one of the caches exists. If none of the specified caches exist, an error will occur.
Void glreadbuffer (glenum mode );
Function: select the following function to call glreadpixels (), glcopypixels (), glcopyteximage * (), glcopytexsubimage * (), and glcopyconvolutionfilter * () to cache the read data.
And enable the cache previously enabled by the function glreadbuffer.
Value of the mode parameter:
Gl_front: Default single cache
Gl_front_right:
Gl_back_right:
Gl_front_left:
Gl_left:
Gl_aux:
Gl_back_left:
Gl_back: Double Cache default
Gl_right:
Note: When cache is enabled for read operations, the specified cache must exist; otherwise, an error will occur.
10.1.7 shielding Cache
Void glindexmask (gluint mask );
Void glcolormask (glboolean red, glboolean green, glboolean blue, glboolean alpha );
Void gldepthmask (glboolean flag );
Void glstencilmask (gluint mask );
Function: sets a mask to control data written to the specified cache,
Glindexmask: used only in color index mode. The data bit of mask 1 is written to the color index cache. The bit of mask 0 is not written.
Glcolormask: only writes in rgba mode are affected. Red, green, blue, and Alpha determine whether to write the corresponding components. When gl_true is used, writes are made.
Gldepthmask (): If the flag value is gl_true, enable deep cache for writing. Otherwise, disable deep cache.
Glstencilmask (): the meaning of the parameter mask is the same as that in the glindexmask () function.
The default value of all glboolean parameters is gl_true, and the default values of both gluint parameters are 1.
Disable deep cache: if the background is complex, disable the deep cache after the background is drawn. draw new objects as long as they do not overlap .. for the next frame, you only need to restore the tree image without restoring the value in the depth cache.
This method is very effective.
The blocking operation of template cache allows you to use one multi-bit template cache to store multiple templates (one for each template)
The mask specified by the function glstencilmask () is used to control which template bit planes can be written and is irrelevant to the mask specified by the third parameter of the function glstencilefunc (). The latter specifies which bit planes the template function will consider.
10.2 fragment testing and operations
Test sequence:
1. Cropping Test
2. Alpha Testing
3. template Test
4. Deep Test
5. Hybrid
6. Jitter
7. logical operations
10.2.1 cropping Test
Void glscissor (glint X, glint y, glsizei width, glsizei height );
Set the position and size of the cropped rectangle. You must enable gl_scissor_test.
10.2.2 Alpha test
You need to enable gl_alpha_test
Void glalphafunc (glenum func, glclampf ref );
Set Reference Values and comparison functions for Alpha testing.
Alpha testing can be used for transparent algorithms and decals.
10.2.3 template Test
Void glstencilfunc (glenum func, glint ref, gluint mask );
Void glstencilfuncseparate (glenum face, glenum func, glint ref, gluint mask );
Set the comparison function (func), reference value (REF), and mask (mask) used for template testing)
Void glstencilop (glenum fail, glenum zfail, glenum zpass );
Void glstencilosponparate (glenum face, glenum fail, glenum zfail, glenum zpass );
Specifies how to modify the data in the template buffer when a clip passes or fails the template test.
Set the template to the middle square
Parameters available for template query glgetinteger:
Gl_stencil_func
Gl_stencil_ref
Gl_stencil_value_mask
Gl_stencil_fail
Gl_stencil_pass_depth_fail
Gl_stencil_pass_depth_pass
10.2.4 deep Test
Void gldepthfunc (glenum func );
Set the comparison function for the deep test.
10.2.5 occlusion test
The occlusion test allows us to determine whether a group of geometric figures are visible after a deep test.
Steps:
1. Generate a query ID for each required occlusion Query
2. Call glbeginquery () to start a blocked query.
3. rendering of geometric images that require occlusion Query
4. Call glendquery () to indicate that the occlusion query has been completed.
5. Extract the number of samples queried by occlusion.
Generate query object
Void glgenqueries (glsizei N, gluint * IDs );
Initializes the occlusion query object.
Void glbeginquery (glenum target, gluint ID );
Void glendquery (glenum target );
Target must be gl_samples_passed.
Determine the result of occlusion Query
Void glgetqueryobjectiv (glenum ID, glenum pname, glint * Params );
Void glgetqueryobjectuiv (glenum ID, glenum pname, gluint * Params );
Clear blocked query objects
Void gldeletequeries (glsizei N, const gluint * IDs );
10.2.6 hybrid, jitter and logical operations
Void gllogicop (glenum opcode );
Select the logical operation to be executed.
10.3 cumulative Buffer
Void glaccum (glenum op, glfloat value );
Control the cumulative buffer zone
OP parameters:
Gl_accum -- read each pixel from the current buffer read by glreadbuffer (). Multiply the R, G, B, And a values by the value. Then the result is accumulated to the cumulative buffer.
Gl_load -- same as above. It only replaces the value in the cumulative buffer with the result.
Gl_return -- multiply the value in the cumulative buffer by value and place the result in the color buffer.
Gl_add and al_mult -- values in the cumulative buffer are added or multiplied, and the result is written back to the cumulative buffer. The results of gl_mult are truncated [-1.0. 1.0]. gl_add is not truncated.
10.3.1 anti-aliasing
First, clear the cumulative buffer and enable the pre-buffer for reading and writing.
Then execute the code several times (for example, n times) cyclically to perform image micro-migration and rendering.
How to accumulate data:
Glaccum (gl_accum, 1.0/n); // draw to a color buffer that is not displayed to avoid displaying intermediate images.
And finally call
Glaccum (gl_return, 1.0); // draw to the displayed color buffer (or the buffer to be switched ).
A user interface can be provided to show the improvements made after each image accumulation. If the image is satisfied enough, the accumulation can be terminated at any time.
In this example, the color components are gradually accumulated in the window.
A total of eight times are accumulated, and each time the data in the J8 array is used for micro-migration scenarios, the use of the glfrustum function can be our scenario without symmetry.
The offset of orthogonal projection only needs to use gltranslatef () to move the offset in one pixel.
Indicates that no image is retained
For images that have accumulated cache anti-aliasing
Show the cumulative cache in steps to see the effect
10.3.2 motion blur
Set the cumulative buffer in the same way, but not the image space migration, but the time migration.
Glaccum (gl_mult, decayfactor );
In this way, as the scenario is drawn to the cumulative buffer, the entire scenario becomes more and more blurred. The decayfactor is a number between 0.0 and 1.0. The smaller the value, the faster the motion.
Then use
Glaccum (gl_return, 1.0 );
Transfer to the eye color buffer.
10.3.3 depth of field
The farther away from the focus plane, the blurrier the object.
Accperspective Function
The fifth and sixth parameters indicate micro-migration in the X and Y directions to achieve anti-aliasing in scenarios.
The ninth parameter sets the focus plane.
The degree of blurring is determined by the product of the seventh and eighth parameters.
10.3.4 soft shadow
Soft Shadows produced by multiple light sources-you can render the scene multiple times, open only one light source at a time, and then accumulate the rendering results.
10.3.5 micro-migration
Sample Micro-shift value