Reputation: 9634
I'm trying to learn how to use D3DVERTEXELEMENT9 for my simple DirectX 9 app. I've been looking at tutorials for this, but they don't really explain how to fill in the stream and offset.
I've seen examples like this:
D3DVERTEXELEMENT9 simple_decl[] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
{0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
D3DDECL_END()
};
But how do we know what number to put in for the offset(in this case it's 12 and 24 for the normal and texcoord).
Also, is the stream always set to 0?
Please help.
Thanks
Upvotes: 1
Views: 540
Reputation: 7118
Offset is cumulative size*num where size is sizeof(float) and num is 3 for a Vec3f.
And since it is cumulative you add the previous offset each vertex element. 12, 24, etc.
Stream is 0 unless you are doing multi-streaming. NOTE: When doing multi-streaming, the offset RESETS back to 0 in each successive stream.
Upvotes: 0