D3DVERTEXELEMENT9的详细解释

struct D3DVERTEXELEMENT9 {
WORD Stream; //Stream No
WORD Offset; //Start of this element in bytes
BYTE Type; //Element type (float1 ... float4, D3DCOLOR, etc.)
BYTE Method; //Tesselation method
BYTE Usage; //Usage of element (position, normal, color, etc.)
BYTE UsageIndex; //Suffix number used in the vertex shader
};
Stream
The stream number is nothing more than an index to the data stream from which this
element will be interpreted. During rendering it is possible to have several active
streams at the same time. With the concept of multiple streams it becomes possible
to mix and match data from several sources (vertex buffers) to the final vertex shader.
Offset
This is the byte offset in the data input stream to the data you want interpreted to a
specific vertex element. In a vertex buffer, for example, the position data is usually
in the beginning of each element (i.e., at offset zero). The position contains three
float values each containing four bytes. This means that whatever vertex data follows
the position data, it will be located at offset 12.
Type
The type of the vertex element tells the vertex shader how to interpret the data
stream. It also tells the vertex shader how much data to read in from the stream
(since each type also has a corresponding size). The list of different vertex element
types is long—see the DirectX documentation for the entire list. However, some of
the most important types are listed in Table 8.1. Knowing these are enough for you
to understand the examples in this book.
Method
The method member in the vertex element structure deals with tessellation only
and is beyond the scope of this book.
Usage
More important than the type is the usage of the data. The value of this member in
the D3DVERTEXELEMENT9 structure will define how the vertex shader uses the data.
The ones you need to know for this book are listed in Table 8.2 (of course there are
more than these; again, see the DirectX documentation for the entire list).
TABLE 8.1 VERTEX ELEMENT TYPES
Type Description
D3DDECLTYPE_FLOAT1 A single float value
D3DDECLTYPE_FLOAT2 Two float values corresponding to the D3DXVECTOR2 structure
D3DDECLTYPE_FLOAT3 Three float values corresponding to the D3DXVECTOR3 structure
D3DDECLTYPE_FLOAT4 Four float values corresponding to the D3DXVECTOR4 structure
D3DDECLTYPE_D3DCOLOR Four bytes (DWORD) mapped to RGBA in the shader
D3DDECLTYPE_UBYTE4 Four unsigned bytes
TABLE 8.2 VERTEX ELEMENT USAGE
Type Description
D3DDECLUSAGE_POSITION Position of the vertex (X, Y, Z)
D3DDECLUSAGE_COLOR Color of the vertex (R, G, B, A)
D3DDECLUSAGE_NORMAL Vertex normal (X, Y, Z)
D3DDECLUSAGE_TEXCOORD Texture coordinate (U, V)
D3DDECLUSAGE_BLENDWEIGHT Blend weights for hardware skinning
D3DDECLUSAGE_BLENDINDICES Blend indices for hardware skinning
UsageIndex
The usage index tells the vertex shader which index the data belongs to. For example,
in the case of multiple positions being sent to the same vertex shader, the UsageIndex
is used to tell them apart. They are then referred to POSITION0, POSITION1, POSITION2,
etc. according to the usage index.

你可能感兴趣的:(3D游戏菜鸟之路)