Question

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...

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top