Jump to content
  • Advertisement
Sign in to follow this  

An Odd FVF Issue

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 positions
bit 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

Share this post


Link to post
Share on other sites
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 struct
void* pOffset = 0;

// Check for positions
if ( 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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!