I am writing an application that needs to adapt to various potential vertex formats. The meshes I am loading may or may not have any number of potential vertex attribts (color, normals, texturecoords, weights, and so on).
A simple example of a declaration looks like this:
D3DVERTEXELEMENT9 simple_decl[] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
{0, 20, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
{0, 24, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1},
D3DDECL_END()
};
struct MYVERTS
{
float x,y,z,u,v;
DWORD colr;
float nx,ny,nz;
};
Basically a D3DVERTEXELEMENT9 is an array of offsets. Each offset being the size of the data memebers of "MYVERTS".
If the user exports a model with just XYZ coordinates and color then i want to dynamically generate a struct with 3 floats and 1 dword and then generate a declaration with offsets and D3DDECLUSAGE.
I have no clue how to do this. Does anyone have any advice?