Chapter 1:opengles 3.0 Introduction (2)--opengl ES 3.0

Source: Internet
Author: User

PipingAs previously, the API version explained in this book is OpenGL ES 3.0. The goal of this book is to provide an in-depth explanation of the technical details of OpenGL ES 3.0, give specific examples of how to use a feature, and discuss various performance optimization techniques. When you finish reading this book, you should be able to have a good grasp of OpenGL ES 3.0API.     You'll be able to easily write the new OpenGL ES 3.0 application, and you don't have to read the specifications of multiple OpenGL ES to understand how a particular feature works. OpenGL ES 3.0 implements a programmable shading graphics pipeline. The OpenGL ES 3.0 specification consists of two parts: the specification of the OpenGL ES 3.0 API and the OpenGL ES 3.0 Coloring Language Specification (OpenGL ES SL). 1-1 describes the graphics pipeline for OpenGL ES 3.0. The shaded modules in the figure represent the stages that can be changed in the OpenGL ES 3.0 graphics pipeline.   Each phase of the OpenGL ES 3.0 graphics pipeline is described below. Vertex shader (Vertex Shader) This section gives a high-level overview of the vertex shader. The vertex shader (Vertex Shader) and the fragment shader (Fragment Shader) are described in more detail in a later section.     The vertex shader implements a common method for manipulating vertices. The input to the vertex shader is as follows:
    • Shader programs (Shader program)--the vertex shader source code or executable program used to manipulate vertices.
    • attribute--the data for each vertex provided by the vertex list.
    • uniform--the vertex shader (or fragment shader) is used as solid.
    • Sampler (Sampler)-a special type of uniform that represents the textures used by each vertex shader.
The output of the vertex shader in OpenGL ES 2.0 is taken aboard the varying variable, but is renamed in OpenGL ES3.0 to "vertex shader output variable (vertex shader output variables)". At the original rasterization stage, the vertex shader output values for each generated fragment are computed, and the computed values are used as input to the fragment shader. The mechanism used to calculate the output value of vertex shading on each fragment is taken by "difference (interpolation)". In addition, OpenGL provides a new feature called Transform Feedback (transform feedback). The change feedback allows the output value of the vertex shader to be written to the output cache in a selective write. For example, in the 14th chapter, there is a program instance that implements a particle system in a vertex shader. In this program, the transformation feedback is output to a cache object. The input and output of the vertex shader are as shown.        vertex shaders can be used for traditional vertex-based operations, such as the transformation of the position of a matrix, the calculation of Ray equations to produce each vertex color, texture coordinate generation or transformation. In addition, because vertex shaders can be specified by the application, custom mathematical methods can be used in the vertex shader to implement new transformations, lighting, and special effects based on fixed-point processing that cannot be implemented in traditional fixed pipelines.      example 1-1 shows a vertex shader implemented in OpenGL ES coloring language. In the later chapters of this book, we will introduce the vertex shader in very good detail, and here is an example of how the vertex shader might look like. In the vertex shader for example1-1, position (position) and color as input, use a 4*4 matrix to transform the position, and enter the transformed position and color.       The first line of the shader program, which provides the version of the shading language. The version information must appear in the first line of the shader. The "#version es" In this example indicates that the version of the OpenGL ES Shading language is v3.00. The second line, which describes a uniform variable U_mvpmatrix, preserves the model view and the projection matrix. Lines seventh and eighth describe the input of the vertex shader. Where a_position is the position property of the vertex, A_color is the color property of the vertex. Line 12th, declares an output variable v_color. This variable is used as one of the output of the vertex shader, preserving the color of each vertex. Gl_position is a built-in variable that is found to be self-defined in the shader, and that the OpenGL es requires that the vertex shader must assign the vertex position after the transformation to the variable. A vertex shader (or fragment shader) has a unique program entry called the Main method. Lines 13th through 17th describe the main method of the vertex shader. Line 15th, we read a little bit of the color value from the fixed-point input property A_color, and then use it as the color of the vertex shader output, saved in V_color. Line 16th saves the vertex position after the change in the vertex shader output gl_position.       Element Assembly (Primitive Assembly)      OPENGL ES 3.0 Graphics Rendering pipeline, a phase after the fixed-point shader is an element assembly. A primitive is a geometric object, such as a triangle, a line, or a point sprite. Each vertex data of an entity is sent to a different copy of the vertex shader. During the entity assembly phase, the processed vertex data is passed back to the entity.       For each entity, you must determine whether it is inside the perspective cone (the perspective cone is the part that is visible on the screen in 3D space). If an entity is not completely contained within the perspective cone, the element needs to be cut by a perspective cone. If the entity is completely outside the perspective cone, then the element is discarded. After the perspective cone has been cut on an entity, the coordinates of the vertex are converted to screen coordinates. You can also discard parts of an entity that do not need to be rendered, depending on whether the rendering is positive (face forward) or reverse (backward). This operation is called blanking (culling). After the cut and blanking, the elements are passed to the next stage of the rendering pipeline-the rasterization phase.       rasterization (rasterization)       The next stage, as shown in Figure1-3, is the rasterization phase. In this phase the relevant elements (such as point sprites, lines, and triangles) are depicted. Rasterization is the process of transforming an entity into a set of two-dimensional fragments that can be processed on a subsequent fragment shader. These fragments represent pixels that can be spent on the screen.            fragment shader (Fragment Shader)       fragment shader implements a common programming method for a set of operational fragments. As shown in Figure1-4, the fragment shader is used to process each fragment generated during the rasterization phase. The input to the fragment shader is as follows:
    • Shader Programs (Shader program)-The source code or executable program for the fragment shader. It describes how the shader will perform those actions on the fragment. The
    • input variable-The output variable of the vertex shader, which is the input to the fragment shader, is the interpolated element that is obtained by interpolation during the rasterization phase. The
    • uniform--the constants that you want to use in the fragment shader.
    • Sampling (Samples)-a special type of uniform that represents the texture used by the fragment shader.
      Fragment shaders can discard fragments, or generate one or more color values that are output as fragment shaders. Typically, a fragment shader produces only one color value unless it is required to render to multiple render targets (refer to chapter 11th, multi-target rendering related chapters). For multi-target rendering, each color value of the output corresponds to a render target. In the graphics rendering pipeline of OpenGL ES 3.0, the color, depth, template, and screen coordinates generated during the rasterization phase are used as inputs for each fragment operation.      exeample1-2 describes a simple fragment shader. A exeample1-2 shader (gouraud-shaded) triangle can be drawn by combining the fragment shader with the exeample1-1 vertex shader. Again, we'll cover the fragment shader in more detail later in this book. Let's look at an example here that just gives the reader a basic understanding of the fragment shader. Just like the vertex shader described earlier, the first line gives the version of the color-finding language, which must appear in the first line of the shader code (#version 300 indicates that the corresponding OpenGL ES color-Finding language version is v3.00). The second line sets the default precision limiter. The precision limiter is described in detail in the fourth chapter, "Shaders and coloring programs." Line four describes the input of the fragment shader. OpenGL ES requires that the same set of variables must be output in the vertex shader, after which the values of the set of variables are read into the fragment shader. Line six declares the output variable of the fragment shader. The color value of this output is used as input to the next stage. Lines seventh through tenth describe the main method of the fragment shader. Here, the color value of the output is assigned the value of the input color. The input to the fragment shader is the data that is interpolated during rasterization, and the data is then passed to the fragment shader.       Fragment-by-segment processing (per-fragment Operations)       After the fragment shader is a fragment-by-segment processing. Fragments generated in the rasterization process (x, y) can only be modified in the frame cache (framebuffer) where the coordinates are (x, y). Figure1-5 describes the phase-by-fragment operation of OpenGL ES 3.0.        As shown in Figure1-5, the following actions are performed for each fragment at the Fragment processing stage:
    • Pixel Attribution test (Pixel ownership test)-This test process determines whether pixels in the frame cache where the position is (x, y) are currently owned by OpenGL ES. This test allows the window system to determine whether the pixels in the frame cache belong to the current OpenGL ES context. For example, if the window used to display the OpenGL ES frame cache is obscured by another window, the window system can decide that the obscured pixels are not part of the OpenGL ES context. In this way, the masked pixels are not displayed. Although the pixel-owned test is part of OpenGL ES, it is implemented by the OpenGL internal mechanism, not by the developer.
    • Trim Test (Scissor test)--the trim test is used to determine whether a point with coordinates (x, y) falls inside the clipping rectangle that is determined by the part state of OpenGL ES. If the clip is outside the clipping area, the fragment is discarded.
    • Templates and depth tests (stencil and depth tests)-templates and depth-Test Tables Act on the template and depth values of a fragment. With these tests, you can determine whether you want to discard the current fragment.
    • Blending (Blending)-blending is the action of creating a new color based on the color value of the fragment and the color value of the corresponding position in the frame cache.
    • jitter (dithering)--by using jitter, you can minimize artifacts on images caused by the use of finite precision in the frame cache.
The end action of the fragment processing phase is to write the color value, depth value, template value, or discard the fragment at the position determined by the frame buffer fetch (x, y) coordinates. If the fragment is not discarded after a variety of tests, writes to these values are performed regardless of whether the color, depth, and template-related write masks (write mask) are enabled. Write masks have better control over the color, depth, and template values that are written to the associated cache. For example, a write mask for a color cache can be set so that only red values can be written to the color cache.     In addition, OpenGL ES 3.0 provides an interface for reading pixel values from a buffer. Note: Alpha Tests and "logical operations" are not included in the fragment-by-process phase. In OpenGL ES 2.0 and OpenGL ES 1.x, these two operations were once supported. The fragment shader can discard fragments, and the alpha test equivalent can be done in the vertex shader, so there is no need for the alpha test to exist. For logical operations, it is seldom used in application development, and OpenGL ES's workgroup does not receive the need for independent application developers to support logical operations in OpenGL ES 2.0. So, this feature was also discarded in OpenGL.

Chapter 1:opengles 3.0 Introduction (2)--opengl ES 3.0

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.