1

我有以下顶点声明:

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;
};

我这样声明:

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()
};

我接下来尝试做的是使用新的顶点声明将 ID3DXMesh 复制到另一个中:

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

当我尝试获取 pTempMesh (D3DXGetFVFVertexSize(pTempMesh->GetFVF())) 的 FVF 大小时,我得到“0”,尽管大小应该是 48。

如果我没有最后一个声明 '{ 0, 36, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },' 并且 CloneMesh 函数不返回失败,那么整个事情都很好。我也尝试过使用不同的声明,例如 D3DDECLUSAGE_TEXCOORD,效果很好,返回的大小为 48。我不知道 D3DDECLUSAGE_TANGENT 有什么具体的吗?

我完全不知道为什么这不起作用......

4

2 回答 2

2

TBH AS DeadMG 指出顶点 decl 不兼容 FVF。你问是否有另一种方法来获取顶点缓冲区的大小。您显然知道缓冲区中有多少个顶点,并且您显然知道顶点结构有多大(48 个字节),因为您在顶点声明中如此定义它。

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()
};

失败只是使用D3DXGetDeclLength

于 2010-05-15T21:28:01.943 回答
1

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.

于 2010-05-15T12:49:12.173 回答