01- acquaintance OpenGL ES

OpenGL ES 3.0

OpenGL ES is a simplified version of OpenGL, it eliminates redundancy, providing both ⼀ easy-to-learn and easier to implement the library in the mobile graphics hardware.

OpenGL ES 3.0 to achieve a graphics pipeline having a programmable shader functions, composed of two specifications: OpenGL ES 3.0 API Specification 3.0 and OpenGL ES shading language specification (OpenGL ES SL). The following figure shows OpenGL ES 3.0 graphics pipeline. FIG yellow background filled with a block representation of programmable pipeline stage in OpenGL ES 3.0.

1276164-e0b96d0cfc3d088c.jpg
OpenGL ES 3.0 graphics pipeline

1. The vertex shader

Vertex shader implements a general purpose programmable vertex method of operation.
Input vertex shader comprises:

  • Shader program - Description vertex shader program code for performing an operation on the source or executable file vertex.
  • Vertex shader input (or attribute) - vertex data of each vertex in the array provided.
  • Unified variable (uniform) - the vertex (or fragment thereof) of the constant data shader.
    Sampler - a variable that represents a specific type of uniform texture vertex shader.

Output variable vertex shader, rasterization stage in FIG COMPUTATIONAL calculating vertex shader output vertex values generated for each segment, and as input to the fragment shader. For each primitive is assigned to the vertex of vertex shader output generating mechanisms each segment value is referred to 插值.

Feedback conversion: making a vertex shader output may be selectively written in one output buffer (except passed to the fragment shader, such delivery may be replaced)

1276164-5ab100b48fae1fbb.jpg
OpenGL ES 3.0 vertex shader .jpg

Vertex shader may be used to change position by a matrix, the lighting calculation formula generating a color per vertex and texture coordinates generated or transformed vertices based on conventional operation. Further, since the vertex shader specified by the application, it may be used to perform vertex-based custom calculation results, the implementation of new transformation, lighting, or the more traditional fixed function pipeline not allowed.

2. The cell assembly of FIG.

After vertex shader, the next stage of the graphics pipeline is OpenGLES 3.0 primitive assembly. Primitives (Primitive) is triangular, linear or other geometric point sprite objects. Each vertex of the primitive is sent to the vertex shader different copies. During assembly of the primitive, the vertices are combined into primitives.

For each primitive, if not completely visual elements within the cone (visible on the screen 3D space region), may need to be cropped. Thereafter, the primitive will be ready to transfer to the next stage of the pipeline - rasterization stage.

3. rasterization

At this stage the corresponding drawing primitives (sprite point, line or triangle). Primitive is rasterized into a set of two-dimensional section of the process, then these fragments are processed by the fragment shader. These fragments represent the two-dimensional pixel can be drawn on the screen.

1276164-80b475e6485dc8f3.jpg
OpenGL ES 3.0 rasterization stage .jpg

4. The fragment shader

To operate on fragment shader fragment implement common programmable method. Shown, each segment of the raster generated execution stage below the shader using the following input:

  • Shader program - the fragment shader program source code or executable file to perform operations on a description fragment.
  • Variable input counter - unit of each rasterized fragment generated by vertex shader output as interpolation.
  • Unity variable - fragment (or vertex) of constant data shader.
  • Sampler - a special type of variable representing fragments unified shader used texture.
1276164-2c066963fa704bdd.jpg
OpenGL ES 3.0 fragment shader .jpg

Fragment shader can be discarded fragments, can also generate one or more color values as output. In general, in addition to multiple render targets outside Guan transfection, only a fragment shader output color value;
in case of multiple render targets, each target output a color rendering value. Rasterization stage generated color, depth, and screen templates coordinate position (x, y) into OpenGL ES 3.0 line 逐片段操作input stage.

The segment-by operation

After the fragment shader, the next stage is the operation by a fragment. Rasterization generated screen coordinates (x, y) of the frame buffer can only be modified fragment position (x, y) of the pixel.

1276164-4dde13ad8ad4fed8.jpg
OpenGL ES 3.0 operating phase by segment .jpg

Segment-by-stage operation, performing the following functions (and test) As shown in FIG on each segment:

  • Pixel Home Test - This test determines the frame buffer position (x, y) of the image search is not currently owned by OpenGL ES all.
    For example, if a window display frame buffer OpenGL ES window obscured by another window, the window system may determine that the pixel does not belong obscured OpenGL ES context, so is not displayed at these pixels. Though 像素归属测试是OpenGL ES的一部分,但是它不由开发人员控制,而是在OpenGL ES内部进行.
  • Test Crop - cutting tests to determine (x, y) is within the range of the cropping rectangle as part of the state of OpenGL ES. If the segment is located outside the clipping region, it was discarded.
  • Templates and depth test - The tests were run on the depth values ​​of the input and the template fragment, to determine whether the segment should be rejected.
  • Mixing - mixing the newly generated fragment value with the color value stored in color frame buffer (x, y) position together.

Cache: The best way to provide data

OpenGL ES is a data exchange memory area defines two cache (buffers) concept. A graphics processor cache means to control and manage continuously RAM. Program to copy the data from memory to the CPU OpenGL ES cache. Data buffers provide seven steps as follows.
(1) 生成(Generate) --- Request OpenGL ES generate a unique identifier for controlling a graphics processor cache.
(2)绑定(Bind)--- tell OpenGL ES uses a cache for the next operation.
(3)缓存数据(Buffer Data)--- let OpenGL ES is currently bound cache allocation and initialization enough contiguous memory (usually memory to copy data from the CPU to control memory allocation).
(4)启用(Enable)或禁止(Disable)--- OpenGL ES tell whether the data cache in the next rendering.
(5)设置指针(Set Pointers)--- Tell memory offset value and all types of data need to access the data as early as OpenGL ES cache.
(6)绘图(Draw)--- tell OpenGL ES uses the data currently bound and enabled cache render part of the scene or a scene.
(7)删除(Delete)--- tell OpenGL ES delete cached previously generated and release the associated resources.

OpenGL ES one type of caching is performed in the course of each step defines the following C language functions, while providing similar functions for other types of cache.

(1) glGenBuffers()--- Request OpenGL ES for the cache control graphics processor generates a unique identifier.
(2) glBindBuffer()--- tell OpenGL ES uses a cache for the next operation.
(3) glBufferData()or glBufferSubData () --- let OpenGL ES is currently bound cache allocation and initialization enough contiguous memory (usually memory to copy data from the CPU to control the allocated memory).
(4) glEnableVertexAttribArray()or glDisableVertexAttribArray()--- OpenGL ES tell whether the data cache in the next rendering.
(5) glVertexAttribPointer()--- tell OpenGL ES type of data early in the cache memory and all the offset values need to access the data.
(6) glDrawArrays()or glDrawElements()data --- tell OpenGL ES bindings and use the current cache enabled to render part of the scene or a scene.
(7) glDeleteBuffers()--- tell OpenGL ES delete cached previously generated and release the associated resources.

Reproduced in: https: //www.jianshu.com/p/d5cffd5d9479

Guess you like

Origin blog.csdn.net/weixin_34133829/article/details/91161643