Direct3D 11 Graphics pipeline
PCs typically have two processors: CPUs and GPU, and you need to write code for each processor. These two parts have completely different schemas and instruction sets. In graphics programming, you need to write software for all two processors, use common languages for CPU applications, such as C + +, and HLSL for GPU. DirectX is the bridge between systems. Most of the articles on graphic programming focus on the CPU or the GPU, but these two parts are very difficult to understand. This book will be explained in two parts. In DirectX we mainly study Direct3D. In simple terms, Direct3D is a system for drawing 3D graphics, defining a series of steps for displaying graphics to the display. These steps are referred to as Direct3D graphics pipelines (Figure 1.1). As shown in the figure, these arrows indicate that the data flows from one phase to the next. The large rectangle on the right side of the graph specifies the resources inside the video memory, and the two-headed arrows indicate that a phase and resource can read and write. The programmable (use HLSL) phase is represented with rounded rectangles. Each phase of the pipeline is described in detail below.
Figure 1.1 The Direct3D graphics pipeline.
The Input-assembler Stage (IA)
The Input-assembler phase is the entry point for the graphics pipeline, providing the vertex and index data of the objects you want to render at some stage. The IA phase assembles the data into primitives (such as dots, lines, triangles) and sends the output of the phase to the vertex shader phase. What the hell is vertex?
Vertex buffers
A vertex is at least one point in a three-dimensional space. For example, in a line segment, a single vertex is an endpoint of a segment: a triangle is one of three points (Figure 1.2). But I say a vertex is at least a bit, because vertex is not just a coordinate point. A vertex may contain color,normal (useful for lighting calculations), texture coordinates, or more. All these data are applied to the input-assembler phase via vertex buffer. In addition to the coordinate position, Direct3D allows the programmer to define a vertex entirely by itself. You can define the data contained in your own vertices and tell Direct3D the vertex format through input layout. The third part, "Rendering with DirectX", describes how to invoke the API settings vertex buffers and input layout; Now you just need to know these terms.
Figure 1.2 3D Primitives:point (left), Line (center), triangle (right).
Index buffers
The Index buffers is the second (optional) data type to be transported to the IA phase. The indices identifies some specific vertices in the vertex buffer and is used to reduce the duplication of reusable vertices. As the following illustration shows, you think of rendering a rectangle (more generally, a quadrilateral). A quadrilateral can be defined with a minimum of four vertices. However, Direct3D does not support the use of quadrilateral as a primitive (and it is not necessary because all polygons can be decomposed into triangles). To render a quadrilateral, it can be divided into two triangles, each of which has three vertices (figure 1.3). Now the vertices has changed from 4 to 6, including two repetitive vertices. Using index buffer, you can specify 4 unique vertices (instead of 6 vertices) and 6 indices in vertex buffer.
Figure 1.3 Vertices and indices for a 3D quadrilateral