Sign in to follow this  
Shawn1984

Vertex format in the .x file

Recommended Posts

I want to write a shader program to display a model. But I found that I can't know what exactly the vertex format is in a .x file. Althought there is a function GetFVF but I can't know what kind of combination it is.Could anyone share some information? Thanks a lot in advance!

Share this post


Link to post
Share on other sites
You can work out the vertex structure from the FVF. E.g. if the FVF is D3DFVF_XYZ | D3DFVF_TEX1, then you know there's a position (3 floats) and one set of texture coordinates (2 floats). And since you know the order the components have to be in (It's documented in the SDK help somewhere), you can work out the vertex structure.

Share this post


Link to post
Share on other sites
The best thing to do is to clone the mesh into the format your shader expects. That way you can load the various .x files that come with the SDK and render them. For some, you will need to have DX create the normals. Here is how I check the .x file for normals and texture coordinates:

D3DVERTEXELEMENT9 elems[MAX_FVF_DECL_SIZE];
BOOL hasNormals = FALSE;
BOOL hasTexCoords = FALSE;
hr = ObjectMesh->GetDeclaration(elems);
if (SUCCEEDED(hr))
{
for(int i = 0; i < MAX_FVF_DECL_SIZE; ++i)
{
// Did we reach D3DDECL_END() {0xFF,0,D3DDECLTYPE_UNUSED, 0,0,0}?
if(elems[i].Stream == 0xff)
break;

if( elems[i].Type == D3DDECLTYPE_FLOAT3 &&
elems[i].Usage == D3DDECLUSAGE_NORMAL &&
elems[i].UsageIndex == 0 )
{
hasNormals = TRUE;
}
if( elems[i].Type == D3DDECLTYPE_FLOAT2 &&
elems[i].Usage == D3DDECLUSAGE_TEXCOORD &&
elems[i].UsageIndex == 0 )
{
hasTexCoords = TRUE;
}
}
}


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