VERTEX ELEMENTS

Vertex elements are just the parts that make up the vertex data we're interested in rendering. This is typically going to be the position, normal, specular and diffuse color, one or more sets of texture coordinates, etc. Though this seems all rather mundane, the point to note is that you can specify your own data as a vertex element as well. It doesn't have to be one of the traditional position, normal, color items at all, but could be a set of alternative data that you'd frequently use—perhaps the object dynamically changes colors every frame and you need additional per vertex colors. Although this gives you a great deal of flexibility, remember that you don't want to be sending a bunch of additional data per object that you infrequently use—this will eat up memory bandwidth. If only some of the information changes (like the colors) while some of the information remains static (like the positions), it's better to separate the data into two streams. (You'll need to check the CAPS bit first. That said, be aware that some of the older videocards have a real problem with trying to use data from more than one stream simultaneously.)

There are two pieces of information that you'll need to create when deciding how to assemble vertex elements: the actual data structure and a vertex format flag that describes how the data is laid out. The first is just a regular C/C++ structure. This example shows a structure that holds vertex position, normal, and color data. You can also use the D3DTYPES nested in your own structure if you like.

 // Define the vertex data structure struct MYCUSTOMVERTEX {    // The untransformed position for the vertex.    float x, y, z;    // The vertex normals    float nx, ny, nz;    // The vertex colors.    DWORD diffuse_color;    DWORD specular_color; }; 

The next step is to define a bit field that holds the Direct3D flags that describe the format we just created.

 // Then define the format constant const unsigned int D3DFVF_MYCUSTOMVERTEX =       ( D3DFVF_XYZ | D3DFVF_NORMAL |         D3DFVF_DIFFUSE | D3DFVF_SPECULAR ) 

Once you have the data element layout, you can create a data buffer.



Real-Time Shader Programming(c) Covering Directx 9. 0
Real-Time Shader Programming (The Morgan Kaufmann Series in Computer Graphics)
ISBN: 1558608532
EAN: 2147483647
Year: 2005
Pages: 104
Authors: Ron Fosner

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