Game Development Reference
In-Depth Information
Note:
We can still use an FVF with the programmable pipeline if the
format of our vertex can be described by it. However, this is for conve-
nience only, as the FVF will be converted to a vertex declaration
internally.
17.1.1
Describing a Vertex Declaration
We describe a vertex declaration as an array of
D3DVERTEXELEMENT9
structures. Each element in the
D3DVERTEXELEMENT9
array describes
one component of the vertex. So if your vertex structure has three
components (e.g., position, normal, color), then the corresponding ver-
tex declaration will be described by an array of three
D3DVERTEXELE-
MENT9
structures. The
D3DVERTEXELEMENT9
structure is defined as:
typedef struct _D3DVERTEXELEMENT9 {
BYTE Stream;
BYTE Offset;
BYTE Type;
BYTE Method;
BYTE Usage;
BYTE UsageIndex;
} D3DVERTEXELEMENT9;
Stream
—Specifies the stream with which the vertex component is
associated
Offset
—The offset, in bytes, to the start of the vertex component
relative to the vertex structure of which it is a member. For exam-
ple, if the vertex structure is:
struct Vertex
{
D3DXVECTOR3 pos;
D3DXVECTOR3 normal;
};
. . . The offset of the component
pos
is 0 since it's the first compo-
nent. The offset of the component
normal
is 12 because
sizeof(pos) == 12
. In other words, the component
normal
starts at byte 12 relative to
Vertex
.
Type
—Specifies the data type. This can be any member of the
D3DDECLTYPE
enumerated type; see the documentation for a com-
plete list. Some commonly used types are:
D3DDECLTYPE_FLOAT1
—A floating-point scalar
D3DDECLTYPE_FLOAT2
—A 2D floating-point vector
D3DDECLTYPE_FLOAT3
—A 3D floating-point vector
D3DDECLTYPE_FLOAT4
—A 4D floating-point vector
Search WWH ::
Custom Search