Game Development Reference
In-Depth Information
Buffers
Now we need to take these vertices and indices and get them into arrays that the
GPU can understand. This is done through the use of buffers, which refer to blocks of
memory that the GPU can use for a variety of different tasks.
Direct3D provides a couple of different types of buffers, each with their own purpose
in the pipeline. The most commonly used buffers include the following:
• Vertex buffers
• Index buffers
• Constant buffers
As you may have gathered, we use vertex and index buffers to store the data we need
for rendering.
Building the vertex and index buffers
To create these buffers, we need to build up an array of the data, being careful to con-
trol the layout of each vertex. Later on we'll tell the GPU how to read the data, so we
can make sure that we know how it will be laid out in memory. To do this, we need
to create a structure definition that outlines the layout of each vertex. A simple vertex
structure could look like the following:
typedef struct PositionNormalVertex
{
XMFLOAT3 Position;
XMFLOAT3 Normal;
} PositionNormalVertex;
This structure defines a position and a normal for each vertex. At a minimum each
vertex requires a position; however, most lighting techniques also require a normal for
the lighting equation. If the model has been created in a 3D editing package, you may
need to check what vertex parameters your importer gives you, and ensure that you
remove the parameters you won't be using (alternatively, you can provide a vertex
structure that matches what you have imported).
Search WWH ::




Custom Search