Finally, I have finished talking about the basic concept of space ry in the first three articles. Now I can say something practical.
For a long time, I have always hoped to record some of my 3D knowledge in the most easy-to-understand language as a series of popular science articles for everyone to take a look.
About a decade ago, I had my first computer and soon saw the charm of 3D games. After hearing about OpenGL, I heard about Microsoft's DirectX 3D (d3d for short ). Early game comparisons show that OpenGL-based game screen effects seem to be slightly better than d3d, but after Microsoft put on OpenGL on the Windows platform, OpenGL gradually surpassed d3d. By now, the effect of d3d seems to be slightly better than that of OpenGL.
So What Are OpenGL and d3d?
This is from the perspectives of business, technology, and computer development history.
When I invented the concept of the game engine, the ID Soft Card mark, people began to use the engine to develop a large number of games. When the picture of the game became more and more realistic, graphics and image processing by CPU alone cannot meet the needs of the game. As a result, people began to try to use hardware acceleration cards to assist the CPU in 3D image processing, which was both technically and commercially successful. Voodoo was famous in the early days.
As a result, a large number of Speed-up card and GPU (Graphic Processing Unit) design companies began to quickly launch their own designs, such as Ati (just acquired by AMD), NVIDIA, powervr (shrinking the market, turn to the 3D acceleration unit of the embedded system. See powervr mbx and OpenGL ES.
The problem arises: Every company may have its own design scheme, so it is difficult to run the software designed and developed by game and 3D application developers on the accelerator card between different vendors, it is difficult to use the acceleration functions of these acceleration cards. That is to say, the portability of such applications will be reduced.
To solve the portability problem, you can abstract the accelerator card function and define the interface form in a unified manner. As a result, people adopt a typical layered model (see design patterns) and divide a set of applications into three layers:
Application Layer-> Hardware Abstraction Layer-> hardware layer
The application layer is the development subject of game and application software developers. They call the unified accelerator card API for upper-layer development without considering portability;
The Hardware Abstraction Layer abstracts hardware acceleration functions, encapsulates application-layer development-friendly applications, and opens APIs to the application layer;
The hardware layer provides the hardware driver to the abstraction layer to enable the acceleration function of the abstraction layer.
This structure effectively isolates games and applications from the hardware accelerator card, which improves the program porting capability. In addition, the Knowledge Reuse Rate of developers is improved, which lowers the development threshold of such software.
As a result, many accelerator card manufacturers joined together to form an organization and jointly developed the interface standards for the hardware abstraction layer. This is OpenGL.
For the same purpose, Microsoft also defined a set of parallel interfaces similar to OpenGL, called Direct 3D.
This is the origin of OpenGL and d3d.
The difference is that OpenGL only contains the 3D acceleration interface, while DirectX also contains the Sound Interface direct sound in addition to d3d, and then the input and output device interfaces, collectively referred to as DirectX.
No matter OpenGL or d3d, their workflows are similar.
We will discuss d3d in the future.
The main function of the 3D accelerator card is to assist the CPU in performing conversion, illumination calculation, cropping, and other operations on the vector image data (vertex set) in the memory. Finally, the image is displayed to the human eye through grating. This process is called rendering. d3d divides the entire rendering into nine steps. The combination of nine steps is called pipeline or pipeline (see pipeline mode in design mode ).
D3d rendering pipeline (rendering pipeline ):
Local Coordinate Transformation-> world coordinate transformation-> observation coordinate transformation-> back elimination-> illumination-> cropping-> projection-> corner calculation-> Rasterization
(These nine links will be introduced one by one in subsequent articles)
Both fixed and programmable pipelines follow these nine steps.
First, introduce the programmable pipeline. As the name implies, some links in the pipeline can be controlled. You can control and manage the rendering effect of the accelerator card by programming the pasters In the GPU. The paintors are divided into vertex paintors and pixel paintors. The Vertex coloring tool is used for Coordinate Transformation and illumination calculation, while the pixel coloring tool is used for grating. This pipeline is called a programmable pipeline when people customize the coloring tool.
At the same time, d3d also provides the default coloring program. When the game or application uses the default coloring program completely, this pipeline is called a fixed pipeline.
In the subsequent sections, we will first introduce the fixed assembly line and its various links, and then introduce the coloring program.