1. [article:] (https://juejin.cn/post/6844903844493656071)
    1. OpenGL first lesson — Name explanation

    2. OpenGL is introduced in lesson 2 – The common fixed storage shader

    3. OpenGL introduction third lesson — matrix transformation and coordinate system

    4. OpenGL entry lesson 4 — Depth

    5. OpenGL entry lesson 5 — front and back elimination

    6. OpenGL entry lesson 6 — Clipping and Blending

    7. OpenGL entry lesson 7 — Texture

    8. OpenGL is in class 8 — a supplementary case

    9. OpenGL ES que

    10. The application of GLKit

    11. GLSL met

    12. How to use custom shaders written in GLSL in iOS

    13. Precision qualifier in GLSL

    14. Use OpenGL to write a rotating stereo album for your girlfriend

Before we talk about the types of storage shaders, let’s take a look at the basic rendering architecture of OpenGL to help us understand the entire rendering process.

OpenGL rendering architecture

In the last description of the name we said that rendering a graph in OpenGL goes through nodes. Such operations can be understood as pipelines. Let’s use a simple architecture diagram to see how OpenGL graphics rendering goes through nodes in this so-called pipeline.

Figure: OpenGL rendering architecture diagram)

From the figure above, we can see that the whole pipeline is divided into two parts, Client and Server.

The client is the program code that we write and the OpenGL API, which runs on the CPU.

The server is written in the underlying hardware of the device to truly complete the rendering operation. It runs on the GPU. As can be seen from the figure, the server mainly includes Vertex Shader and Fragment Shader. The incoming vertex data is first evaluated by the vertex shader. Then the vertex is converted to primitives through primitives assembly. Then rasterization, the pixel vector graphics, into rasterized data. Finally, the rasterized data is fed into a chip shader for operation. The pixel shader operates on each pixel in the rasterized data and determines the pixel’s color and depth values.

Client constantly and command blocks of the data together to buffer, then the buffer will be sent to the server, if the server stop working for the client, or client stop work to wait for the server ready to accept more commands and data, we put this kind of circumstance Chen stagnation of the pipeline

An imaginative client can communicate with a server only through the three Data types: Attributes, textures and Data. Also note that the Attributes attribute can only be passed to the Vertex Shader Shader.

Several common fixed storage shaders

Fixed storage shader is an early Version of OpenGL package to help developers to complete the graphics rendering block, we commonly use the following several:

  • Unit shader:

Usage scenario: Draw graphs in the default OpenGL coordinate system (-1,1). All segments of the graph are filled with one color.

      GLShaderManager::UseStockShader(GLT_SHADER_IDENTITY,GLFloat vColor[4])

Parameter 1: Storage shader type – cell shader; Parameter 2: Color

  • Flat shader

Usage scenario: Transformations (model/projection transformations) can be applied when drawing graphs.

    GLShaderManager::UseStockShader(GLT_SHADER_FLAT,GLFloat mvp[16],GLFloat vColor[4])

Parameter 1: Storage shader type – flat shader; Parameter 2: a 4*4 matrix that allows variation; Parameter 3: Color

  • Coloring shader:

Use scenarios: When drawing graphics, transformations can be applied (model/projection transformations), and colors will be smoothly inserted between vertices called smooth coloring.

    GLShaderManager::UseStockShader(GLT_SHADER_SHADER,mvp[16])

Parameter 1: Storage shader type – coloring shader; Parameter 2: a 4*4 matrix that allows variation

  • Default light shader:

Use scenarios: When drawing graphics, transformations can be applied (model/projection transformations), and this shader will render the graphics with shadows and lighting effects.

     GLShaderManager::UseStockShader(GLT_SHADER_DEFAULT_LIGHT,GLFloat mvMatrix[16], GLFloat pMatrix[16], GLFloat vColor[4]) 

Parameter 1: Storage shader type – default light shader; Parameter 2: Model view 44 matrix; Parameter 3: projection 44 matrix; Parameter 4: color value

  • Point light shader:

Use scenarios: When drawing graphics, transformations can be applied (model/projection transformations), and this shader will render the graphics with shadows and lighting effects. It is very similar to the default light shader, except that the light position may be specific.

     GLShaderManager::UseStockShader(GLT_SHADER_POINT_LIGHT_DIEF,GLFloat mvMatrix[16], GLFloat pMatrix[16],GLFloat vLightPos[3], GLFloat vColor[4]) 

Parameter 1: Storage shader type – point light shader; Parameter 2: Model view 44 matrix; Parameter 3: projection 44 matrix; Parameter 4: point light source position; Parameter 5: color value

  • Texture replacement matrix shader:

Usage scenarios: When drawing graphics, transformations can be applied (model/projection transformations). This shader projects a matrix through a given model view. Use the texture unit for color filling. The color of each pixel is taken from the texture.

      GLShaderManager::UseStockShader(GLT_SHADER_TEXTURE_REPLACE,GLFloat mvMatrix[16],GLint nTextureUnit) 

Parameter 1: Store shader type – Texture replacement matrix shader; Parameter 2: model view 4*4 matrix; Parameter 3: texture unit;

  • Texture adjustment shader:

Usage scenarios: When drawing graphics, transformations (model/projection transformations) can be applied to shaders that pass through a given model view matrix. The shader multiplies a base color by a texture taken from the texture unit nTextureUnit. Blend the color with the texture before filling the fragment.

     GLShaderManager::UserStockShader(GLT_SHADER_TEXTURE_MODULATE,GLfloat mvMatrix[16],GLfloat vColor[4],GLint nTextureUnit); 

Parameter 1: Store shader type – Texture adjustment shader; Parameter 2: model view 4*4 matrix; Parameter 3: color; Parameter 4: texture unit;

  • Texture light shader:

Usage scenario: Transformations (model/projection transformations) can be applied when drawing graphs. This shader projects a matrix through a given model view. The shader adjusts (multiplies) a texture with diffuse lighting calculations.

   GLShaderManager::UserStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIEF,GLfloat mvMatrix[16],GLfloat pMatrix[16],GLfloat vLightPos[3],GLfloat vBaseColor[4],GLint nTextureUnit); 

Parameter 1: Store shader type – Texture light shader; Parameter 2: Model view 44 matrix; Parameter 3: projection 44 matrix; Parameter 4: point light source position; Parameter 5: color value (base color of geometry); Parameter 6: Texturing unit