# Mapping between D3DFVF_* and struct

This topic is 4904 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I define my vertix type as: #define D3DFVF_VERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1 | D3DFVF_TEX2) But how does D3D know how to map the variables to those in my struct:
struct D3DVERTEX
{
D3DXVECTOR3 p;
D3DXVECTOR3 n;
FLOAT       tu;
FLOAT		tv;

FLOAT       tu1;
FLOAT		tv1;

D3DVERTEX() {};
D3DVERTEX(D3DXVECTOR3& v1,D3DXVECTOR3& v2 ,FLOAT f1, FLOAT f2, FLOAT f21, FLOAT f22) {
p = v1;
n = v2;
tu = f1;
tv = f2;
tu1 = f21;
tv1 = f22;
};
};


For example that n = normals and p = x,y,z? Sorry for the dumb question! Onnel

##### Share on other sites
The order of the various elements of a vertex is fixed for FVF. The size of each type is also known so one can simply calculate. For example:
DWORD dwFVF = D3DFVF_POSITION | D3DFVF_NORMAL;// Begin at beginning of structoffset = 0// 1. Check if there are verticesif ( dwFVF contains D3DFVF_POSITION )  - positions are at offset from the start of the struct  - increase offset by 3*sizeof(float)// 2. Check if there are normalsif ( dwFVF contains D3DFVF_NORMAL )  - normals are at current offset  - increae offset by 3*sizeof(float)...// 28. Check if there are binormalsif ( ... )  - binormals are at current offset  - increase offset by 3*sizeof(float)

Et cetera. Greetz,

Illco

PS: order is for example purposes only

##### Share on other sites
Thanks! Is the order based on the DWORD?

So:

DWORD dwFVF = D3DFVF_POSITION | D3DFVF_NORMAL;

Would need a struct:

struct D3DVERTEX{    D3DXVECTOR3 p;    D3DXVECTOR3 n;};

Would it mix up the values if it were defined:

struct D3DVERTEX{    D3DXVECTOR3 n;    D3DXVECTOR3 p;};

Thanks. this is probably all really dumb, but I'd like to make sure I understand the relationship correctly.

Onnel

##### Share on other sites
Yes that would mix up:
struct D3DVERTEX{    D3DXVECTOR3 n;    D3DXVECTOR3 p;};

Because the deal is that positions come before normals. See the SDK documentation for the precise order.

Greetz,

Illco

##### Share on other sites
Grand, thanks for the help!

Onnel

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633662
• Total Posts
3013231
×