OpenGL Shader Program Analysis--Shader Basics

Partially from https://yq.aliyun.com/articles/212816?spm=5176.100239.blogcont212814.16.7FHthK
Modern OpenGL rendering pipelines rely heavily on shaders to process incoming data. If you don't use shaders, the only thing you can do with OpenGL is to clear the window content, which shows the importance of shaders to OpenGL. Prior to and including OpenGL version 3.0, or if you used a compatibility profile environment, OpenGL also included a fixed-function pipeline (f?ixed-function pipeline) that could be used without shaders. Handle geometric and pixel data without exception. As of version 3.1, the fixed-function pipeline was removed from core mode, so we had to use shaders to get the job done.
Shaders are like a function call - data is passed in, processed, and then passed out. For example, in the C language, this process can be done through global variables, or function parameters. GLSL is slightly different from it. Each shader looks like a complete C program whose input point is a function called main(). But unlike C, GLSL's main() function does not have any parameters, and all data input and output in a certain shading stage is passed through special global variables in the shader (please do not use them with the application global variables in - shader variables are completely irrelevant to variables you declare in your application code).
OpenGL defines six types of storage qualifiers (const/in/out/uniform/buffer/shared).
OpenGL defines in variables to copy data into the shader, and out variables to copy out the content of the shader. The values ​​of these variables are updated each time OpenGL executes the shader. Another type of variable that receives data directly from an OpenGL application is called a uniform variable. The uniform variable does not change with the change of vertices or fragments, it is the same value for all geometry primitives, unless the application updates it. Buffer is a large buffer shared with shaders in the application. Unlike uniform, buffer allows shaders to modify it.
GLSL is annotated with // or / and / as in C. Unlike C, all variables must be initialized at the same time they are declared. GLSL supports arrays of arbitrary types, such as

float coeff[3]=float[3](2.38,3.14,42.0);

Here is a brief explanation here, we will all start from the code for analysis later

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325525808&siteId=291194637