"OpenGL Programming Guide" 1.4 OpenGL rendering pipeline - an interview with a clear explanation of the concept

Original link: https://yq.aliyun.com/articles/117345

https://yq.aliyun.com/articles/117345

 

"OpenGL Programming Guide" 1.4 OpenGL rendering pipeline

Hua Zhang computer  2017-07-03 14:04:00 1896 View

This section excerpt from a chapter Press "OpenGL Programming Guide," a book Chapter 1, Section 1.4, author Bill Licea-Kane, more chapters can be accessed Yunqi community "chapter of the computer," No public view

1.4 OpenGL rendering pipeline

OpenGL, we usually refer to the rendering pipeline (rendering pipeline), which is a series of data processing, and converts the data of the application to the final rendered image. Figure 1-2 is a line OpenGL 4.3 version. Since the birth of OpenGL, its rendering pipeline has been a very big change happened.
OpenGL is first received geometry data (vertex and geometry) provided by the user, and inputs it to the series of processing the shader stages, comprising: a vertex shader, the colored segments (which itself comprises two shaders), and finally the geometry shader, then it will be fed to a raster unit (rasterizer). Rasterizing unit responsible for generating fragment data of FIG shear in all regions (clipping region) element, and then perform a fragment shader generated for each fragment.

image

As you know, for OpenGL applications shaders played a major role. You have complete control of their need to use shaders to achieve their desired function. We do not need to use all the coloring stage, in fact, only vertex shaders and fragment shaders are required. Segments, and the geometry shader is an optional step.
Now, we will be a little deeper into each coloring stage which, for more background information. It is understood that the present stage how many people feel discouraged, but do not worry. By further understanding of the concepts, you will quickly get used OpenGL development process.

1.4.1 ready to transfer data to OpenGL

OpenGL requires all data saved to the cache object (buffer object), which is equivalent to an area of ​​memory maintained by the OpenGL server. We can use a variety of ways to create such a data cache, but the most common method is to use glBufferData example 1.1 () command. We may also need to do some extra cache settings, relevant content, see Chapter 3.

1.4.2 to transfer data to OpenGL

When initialization is complete cache, we can call the OpenGL rendering a drawing command to request geometry, for example, 1.1 to glDrawArrays (commonly used is a drawing command).
OpenGL rendering the vertex data is usually transmitted to the server OpenGL. We can be considered as a vertex requires a unified packet processing. Data in this package can be any data we need (that is to say, we are all responsible for their own definition of what constitutes data vertices), which is usually almost always contain location data. Other data may be used to determine the final color of a pixel.
Chapter 3 describes the content will draw commands in more detail.

1.4.3 vertex shader

For each vertex of the drawing commands, OpenGL vertex shader will call a vertex data related to process. The other active before rasterization shader or not, the vertex shader may be very simple, for example, simply copying data and passed to the next stage of coloring, which is called transfer shader (pass-through shader); it is also possible complex, e.g., a large number of calculations performed to obtain a position of the vertex on the screen (in general, we will use the concept of the transformation matrix (transformation matrix), see Chapter 5), or by calculating the lighting (see section 7 chapter) to determine the color of the vertex, or achieve some other techniques.
Generally speaking, a complex application may contain many vertex shaders, but at the same time, only one vertex shader work.

1.4.4 segments coloring

After the vertex shader processing data associated with each vertex, if activated simultaneously subdivision shader (tessellation shader), it will further process the data. As will be seen in Chapter 9, the shader uses Patch subdivision to describe a shape of the object, and using a relatively simple geometry Patch connected segments to complete the work, the result is to increase the number of geometric elements, and the appearance of the model will become more smooth. Shading stage segments will be used to separately manage two shader Patch data and generating the final shape.

1.4.5 Geometry Shader

Coloring next stage - the geometry shader - are allowed before the rasterization do further processing on each geometric element, such as creating a new entity. This coloring stage is optional, but we will in Chapter 10 where appreciate its powerful place.

1.4.6 primitive assembly

Shading stage described earlier are processed vertex data, in addition to how all of the information between the vertices of the geometry which is also passed to the OpenGL. Primitive assembly stage of tissue together between the element vertices associated with geometry, shear and prepare the next work rasterization.

1.4.7 Cut

Vertices may fall viewport (viewport) outside - that is, we can draw the window area - this time related to the vertices of primitives will make changes to ensure that the relevant pixels not draw outside the viewport. This process is called cutting (clipping), which is done automatically by the OpenGL.

1.4.8 rasterization

Immediately after the cutting work to be performed, after the updating is transmitted to a raster primitives unit, generates the corresponding fragments. We can a tile as a "candidate pixel", i.e. may be placed in the frame buffer pixels, but it may also be eventually removed, corresponding to the pixel position is not updated. Two phases will be executed after the processing of the fragment, i.e., fragment shading operations and by the fragment.

1.4.9 piece of the original coloring

The last stage of the color may be displayed by the control program on the screen, called a fragment shading stage. At this stage, we use the shader calculates a final color film element (may also change color once although the next stage (by operation fragment)) and its depth value. Fragment shader very powerful, here we will use texture mapping, the color values of the vertices of the calculated phase process supplement. If we think we should not continue to draw a fragment in the fragment shader can also terminate the processing of this fragment, this step is called fragment discard (discard).
If we need to better understand the differences between the process vertex shader and fragment shader, this method can be used to remember: vertex shader (including segments and geometry shading) determines what should be an element of the screen in FIG. position, and fragment shaders use this information to determine the color of a fragment of what should be.

1.4.10 fragment by operation

In addition we do in the fragment shader work, the next step is the last independent fragment fragment processing operations. At this stage it will be used to test the depth (depth test, or also commonly referred to z-buffering) and stencil test (stencil test) way to determine whether a fragment is visible.
If a fragment successfully passed all active test, then it can be drawn directly into the frame buffer, the color values (may include depth values) corresponding to the pixels that will be updated, if turned fusion (Blending ) mode, then the fragment will be superimposed with the color of the current color of the pixel, to form a new color values and written to the frame buffer.
1-2 can be seen from the figure, the pixel data is transmitted has a path. In general, the pixel data from the image file, although it could also be a direct OpenGL rendering. Pixel data is typically stored in a texture map which, by way of calls texture mapping. We can find the data value from one or multiple texture maps in the texture stage. We'll learn about texture mapping in Chapter 6.
Now that we understand the basics of OpenGL pipeline, then back to 1.1 cases, to explain the manner in which the operation of pipelines.

Guess you like

Origin blog.csdn.net/u010029439/article/details/102740487