Flexible Vertex Formats

Vertex buffers in Direct3D can encapsulate very different information, from vertex coordinates to texture coordinates and colors, and some other exotic data types such as weights for animation matrices. All this is elegantly built into the API using FVF, which is a mechanism to declare the format of a buffer so Direct3D knows how to handle it.

Fundamentally, vertices in Direct3D are defined as arrays of structs. Each struct is one vertex, and we can define the internals of that struct. The FVF informs Direct3D of our chosen format. For example, the following code tells Direct3D we have a vertex format that encapsulates position information (D3DFVF_XYZ), normals, and one set of texture coordinates:

 struct D3DVERTEX    {    D3DXVECTOR3 p;    D3DXVECTOR3 n;    FLOAT tu, tv;    static const DWORD FVF;    }; const DWORD D3DVERTEX::FVF = D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1 

However, the "flexible" in the FVF allows much more than this. Take a look at the next declaration:

 dwFVF = ( D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE |    D3DFVF_SPECULAR | D3DFVF_TEX2 ); 

This FVF incorporates vertices and normals, two sets of texture coordinates, and both a diffuse and specular color. This makes it useful for per-vertex lighting using hardware lights, which will interact with the FVF's diffuse and specular color.

There are many FVF combinations; each suited for specific purposes. The best way to learn about them is to take a look at the DirectX SDK documentation, which lists them and in most cases provides use examples. For completeness, the diagram in Figure C.1 shows all possible FVF combinations.

Figure C.1. The FVF framework with all possible values listed.

graphics/cfig01.gif



Core Techniques and Algorithms in Game Programming2003
Core Techniques and Algorithms in Game Programming2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 261

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net