Sign in to follow this  
onnel

Mapping between D3DFVF_* and struct

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 this post


Link to post
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 struct
offset = 0

// 1. Check if there are vertices
if ( 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 normals
if ( dwFVF contains D3DFVF_NORMAL )
- normals are at current offset
- increae offset by 3*sizeof(float)

...

// 28. Check if there are binormals
if ( ... )
- binormals are at current offset
- increase offset by 3*sizeof(float)


Et cetera. Greetz,

Illco

PS: order is for example purposes only

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this