An Odd FVF Issue

Started by
4 comments, last by sniper1263 18 years, 8 months ago
I would first like to clear up, that I did try looking through DirectX's documentation to double check about this issue, but I couldn't find anything on it. So now I bring it to you guys. I have a FVF as follows:

struct CUSTOMVERTEX
{
	float x, y, z;
	float xNorm, yNorm, zNorm;
	float tX, tY;
};

#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1)

I noticed, however, that if I move 'D3DFVF_TEX1' before 'D3DFVF_NORMAL' and don't update the CUSTOMVERTEX structure, the program still treats the FVF definition as it is now. Also, if I make that same change again, and DO update the structure appropriately, the FVF is again treated as if D3DFVF_TEX is last in the definition. If this issue is in the documentation, I apologive for the waste of time, but I was curious as to why this was happening.
Advertisement
This is because with that the assignment of the D3DFVF_CUSTOMVERTEX you are simply OR'ing togther those three values, D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1.

It doen't matter which order you OR things together.

ace
To elaborate on Ace: with FVF the order of the structure is fixed (as mentioned in the SDK). With FVF positions always come first, followed by normals, followed by etc. for all elements that are set in the FVF flag.

This FVF flag is indeed nothing else then a bit field, which works like:
bit 0: whether the struct has positionsbit 1: whether the struct has normals...

So the order in which you set bits to true/false does not matter; the result is the same flag and the corresponding struct should remain the same.

Illco
Ok, I get it now. Thank you!
It knows so because it is fixed beforehand. So if positions (XYZ) are present as indicated by the FVF flag, then they will be at offset zero. Next, if normals are present in the flag, then they will be after the positions (whether they exist or not determines the final offset).

Perhaps some pseudo code for finding the element in the struct will make this more insightful:
// Start at the beginning of the structvoid* pOffset = 0;// Check for positionsif ( FVF flag contains positions ){  // Store pointer to position info in struct and increase offset  pPosition = pOffset;  pOffset += sizeof( one position );}if ( FVF flag contains normals{  pNormal = pOffset;  pOffset += sizeof( one normal );}


EDIT: oh you already got it. Greayt!
Oh sorry. I had posted the question right after the first reply. Then I saw your post, and just changed my other reply... Thank you though.

This topic is closed to new replies.

Advertisement