我有以下顶点解除:
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函数没有返回FAIL,那么整个过程都没问题。我也尝试过使用不同的声明,例如D3DDECLUSAGE_TEXCOORD,并且工作正常,返回48的大小。有什么特别关于D3DDECLUSAGE_TANGENT我不知道吗?
我完全不知道为什么这不起作用......
答案 0 :(得分: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。
答案 1 :(得分:1)
并非每个D3DVERTEXDECL都可以转换为FVF。在尝试获取FVF大小之前,您应该三重检查您是否有与FVF兼容的声明。虽然,为什么你使用FVF超出了我的意义,但是它没有用,因为D3D10甚至不允许使用FVF。