OpenGL for beginners is not very friendly, the first is to understand its professional noun meaning, the following list of some key professional noun parsing.
1. Context
- Concept: A context is a large state machine that holds all the states in OpenGL and is the basis for OpenGL execution.
- OpenGL functions operate on a state in the current object’s OpenGL context, a huge state machine.
- Problem: Since context is a large state machine, switching between contexts can be expensive, but different modules may need to use completely separate state management.
- Solution: You can create multiple different contexts in your application, use different contexts in different threads, share textures, buffers, etc. Such a solution would be more efficient than repeatedly switching the context or changing the render state a lot.
Personally, I think the principle of the solution is to use multiple threads to process the context concurrently, and use sharing to improve the utilization rate and reduce consumption.Copy the code
2. The OpenGL state machine
- Concept: A state machine is theoretically a machine. A state machine describes the various states an object goes through during its life cycle, the causes, conditions, and activities performed during the transition. In other words, a state machine is a behavior that describes the response of a sequence of states that an object experiences in response time during its life cycle.
- Features: 1. Have memory function, can remember its current state; 2. Can accept input, according to the income content and their original state, modify the current state, and corresponding output 3. When entering a special state (shutdown state), it becomes no longer receiving input and stops working.
A state machine can save behavior, control changes, and record stateCopy the code
It can be understood from the above
OpenGL can record its state (the current color, whether the blending function is enabled, etc.). OpenGL can receive input (when the OpenGL function is called). OpenGL can enter the stop state and no longer receive input. OpenGL always stops working before the program exits
3. The Rendering Rendering
The operation of converting graphic/image data into 2D spatial images is called rendering.
Rendering is the process of converting data into imagesCopy the code
4. VertexArray and vertex Buffers (VerteButter)
- The vertex data is the skeleton of the image to be drawn, and unlike in real life, images in OpenGL are made up of primitives. In OpenGL ES, there are three types of primitives: points, lines, and trigons.
- The vertex data is eventually stored in memory, called a vertex array.
- To improve performance, a chunk of memory is allocated in advance, and the vertex data is preloaded into video memory, which is called the vertex buffer.
- Vertices are vertex position data, stored in an array or cached in the CPU.
Vertices are a very important concept in OpenGL, and a lot of transformations are done by manipulating vertices arrays.Copy the code
5. Shader program
- This is the complete transformation of a fixed render pipeline architecture into a programmable render pipeline. Only vertex shaders and fragment shaders are supported
- OpenGL handles shaders just like any other compiler. Through compiling, linking and other steps, a color color program (glProgram) was generated. The color color program contains the operation logic of vertex color color and slice color color. In The process of row drawing in OpenGL, the row calculation of the incoming vertex data is performed by the vertex colored filter first. Then the vertex is converted to primitives through primitives assembly. Then row rasterization is carried out to transform the vector quantity graphics of the graph element into rasterized data. Finally, the rasterized data is fed into the chromatic filter for row arithmetic. The fragment color filter evaluates each pixel in the rasterized data line by line and determines the color of the pixel
Vertex shaders are responsible for converting to graph metadata, and fragment shaders are responsible for pixel calculationsCopy the code
6. The line
- When you render a graph in OpenGL, you go node by node. Pipeline is an abstract concept, so called pipeline because the graphics card processing data in a fixed order, and strictly in accordance with this order.
7. Fixed pipeline/storage shaders
In the early version of OpenGL, it encapsulated many kinds of colored program block, including a fixed shader program which included lighting, coordinate transformation, clipping and many other functions, to help developers to complete the rendering of graphics. Developers only need to pass in the corresponding parameters, can quickly complete the graphics rendering. But because OpenGL has so many different usage scenarios, a fixed pipeline or storage shader cannot do every job. At this point, the relevant parts are exposed as programmable
Vertex shaders
- Function: Generally used to deal with the vertex changes of each graph (rotation/translation/projection, etc.)
- Vertex shaders are programs used in OpenGL to calculate vertex properties. Vertex shaders are vertex-by-vertex programs, that is, each vertex data is executed once, in parallel and without access to other vertex data
Vertex shader, dealing with vertex-related operationsCopy the code
9. Slice shader
- Function: Generally handles the calculation and filling of the color of each pixel. Fragment shader is a program used in OpenGL to calculate the color of slice fragments (pixels)
- The fragment shader is a program that operates pixel by pixel
Fragment shaders work with pixelsCopy the code
10.GLSL(OpenGL Shading Languange)
OpenGL Shading Language is the Language used for Shading programming in OpenGL, that is, short custom programs written by developers that are executed on the GRAPHICS Processor GPU (GRAPHICS Processor Unit), Instead of a fixed part of the render pipeline, the different layers in the render pipeline are programmable. For example: view conversion, projection conversion and so on. GLSL(GL Shading Language) Shader code is divided into 2 parts: Vertex Shader and Fragment
GLSL mainly programs vertex shaders and chip shadersCopy the code
11. Rasterization
It is the process of converting vertex data into slices, and has the function of converting a graph into an image composed of a grid, characterized by each element corresponding to a frame buffer pixel. Rasterization is the process of converting vertex data into patch elements. Each element in the tile corresponds to a pixel in the frame buffer. Rasterization is actually a process of transforming geometric elements into two-dimensional images. There are two parts to this process. The first part of the work: determine which integral grid areas in window coordinates are occupied by basic primitives; Two parts of the job: assign a color value and a depth value to each area. The rasterization process is generated by converting the mathematical description of the object as well as the color and color information related to the object into pixels for corresponding positions on the screen and colors for filling pixels. This process is called rasterization, which is a process of converting analog signals into discrete signals.
Rasterization is pixel-level operations that may affect some performanceCopy the code
12. The texture
Texture theory can be understood as a picture. When rendering graphics, we need to encode and fill the picture in order to make the scene more realistic. And the picture used in the interior is often referred to as texture theory. But in OpenGL, we’re more used to calling textures, not images.
Texture is a big picture.Copy the code
Mixed 13.
After the test phase, if the pixel is still not removed, the color of the pixel will be mixed with the color attached to the color in the frame buffer. The blending algorithm can be specified by the OpenGL function. However, the mixing algorithm provided by OpenGL is limited. If a more complex mixing algorithm is needed, it can be achieved through the pixel shader. Of course, the performance will be worse than the original mixing algorithm.
The intersection of two translucent views is the centerCopy the code
14 Transformation Matrix
For example, the graph wants to be translated, scaled, rotated. You have to use the transformation matrix
Projection matrix Projection
Used to convert 3D coordinates to 2d screen coordinates where the actual lines will also be drawn