views:

39

answers:

2

I have the following vertex declration:

struct MESHVERTInstanced
{
    float x, y, z;      // Position
    float nx, ny, nz;   // Normal
    float tu, tv;       // Texcoord
    float idx;          // index of the vertex!
    float tanx, tany, tanz;   // The tangent

    const static D3DVERTEXELEMENT9 Decl[6];
    static IDirect3DVertexDeclaration9* meshvertinstdecl;
};

And I declare it as such:

const D3DVERTEXELEMENT9 MESHVERTInstanced::Decl[] =
{
    { 0, 0,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
    { 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL,   0 },
    { 0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
    { 0, 32, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 },
    { 0, 36, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },
    D3DDECL_END()
};

What I try to do next is copy an ID3DXMesh into another one with the new vertex declaration as such:

model->CloneMesh( model->GetOptions(), MESHVERTInstanced::Decl,
            gd3dDevice, &pTempMesh );

When I try to get the FVF size of pTempMesh (D3DXGetFVFVertexSize(pTempMesh->GetFVF())) I get '0' though the size should be 48.

The whole thing is fine if I don't have the last declaration, '{ 0, 36, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },' in it and the CloneMesh function does not return a FAIL. I've also tried using different declarations such as D3DDECLUSAGE_TEXCOORD and that has worked fine, returning a size of 48. Is there something specific about D3DDECLUSAGE_TANGENT I don't know?

I'm at a complete loss as to why this isn't working...

+1  A: 

Not every D3DVERTEXDECL can be converted to FVF. You should triple-check that you have an FVF-compatible declaration before trying to get the FVF size. Although, it's beyond me why you're using FVF, it's fairly useless and you won't be gaining future skills, as D3D10 doesn't even allow FVF.

DeadMG
Well is there another way to get the size of a vertex buffer so I can parse it? Also what's the alternative to FVF?
meds
Shaders and the programmable pipeline. I suggest that you get DirectX 9.0c- A Shader Approach by Frank Luna, which is excellent and up-to-date. Also available in a D3D10 flavour, although I believe that D3D11 is not out.Edit: Not sure what you're doing with parsing the vertex buffer.. the size of a vertex buffer is sizeof(the struct you posted in the OP) * the length you input to create it. You shouldn't be dealing with vertex buffers manually at all - that's what ID3DXMesh exists for.
DeadMG
+1  A: 

TBH AS DeadMG points out that vertex decl is NOT FVF compatible. You ask if there is another way to get the size of the vertex buffer. You evidently know how many vertices are in the buffer and you, OBVIOUSLY, know how large the vertex structure is (48 bytes) as you DEFINE it as such in your vertex declaration.

const D3DVERTEXELEMENT9 MESHVERTInstanced::Decl[] =
{
    { 0, 0,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, //Starts at offset 0 and is 3 floats, or 12 bytes in size.  Total = 12 bytes.
    { 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL,   0 }, //Starts at offset 12 and is 3 floats, or 12 bytes in size.  Total = 24 bytes.
    { 0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }, //Starts at offset 24 and is 2 floats, or 8 bytes in size.  Total = 32 bytes.
    { 0, 32, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 }, //Starts at offset 32 and is 1 float, or 4 bytes in size.  Total = 36 bytes.
    { 0, 36, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT,  0 }, //Starts at offset 36 and is 3 floats, or 12 bytes in size.  Total = 48 bytes.
    D3DDECL_END()
};

Failing that just use D3DXGetDeclLength.

Goz
Ah yep that helped, also ID3DXMesh::GetNumBytesPerVertex() seems to work as well. It wasn't so much that I knew how large the vertex declaration was but I wanted to know how I can get the size automatically in cases I did not know the size of the vertex declaration.
meds