我有简单的声明:
uses ...
Winapi.Direct3D9, Winapi.DXTypes, Winapi.D3DX9,
var
g_pVertexDeclaration: IDirect3DVertexDeclaration9 = nil;
const
decl: array [0 .. 4] of TD3DVertexElement9 = (
(Stream: 0; Offset: 0; _Type: D3DDECLTYPE_FLOAT3; Method: D3DDECLMETHOD_DEFAULT;
Usage: D3DDECLUSAGE_POSITION; UsageIndex: 0),
(Stream: 0; Offset: 3 * sizeof(single); _Type: D3DDECLTYPE_FLOAT3; Method: D3DDECLMETHOD_DEFAULT;
Usage: D3DDECLUSAGE_NORMAL; UsageIndex: 0),
(Stream: 0; Offset: 6 * sizeof(single); _Type: D3DDECLTYPE_FLOAT2; Method: D3DDECLMETHOD_DEFAULT;
Usage: D3DDECLUSAGE_TEXCOORD; UsageIndex: 0),
(Stream: 0; Offset: 8 * sizeof(single); _Type: D3DDECLTYPE_FLOAT2; Method: D3DDECLMETHOD_DEFAULT;
Usage: D3DDECLUSAGE_TEXCOORD; UsageIndex: 0),
(Stream: $FF; Offset: 0; _Type: D3DDECLTYPE_UNUSED; Method: TD3DDeclMethod(0);
Usage: TD3DDeclUsage(0); UsageIndex: 0) //({D3DDECL_END})
);
记录错误的功能
function CheckDxError(e: dword): boolean;
begin
if Failed(e) then begin
raise Exception.Create(format('dx error %d: %s, %s', [(e shr 16) and $7FFF, DXGetErrorString9(e),
DXGetErrorDescription9(e)]));
exit(false);
end;
result := true;
end;
我dx error 0: E_FAIL, An Undetermined error occured
有
CheckDxError(m_pd3dDevice.CreateVertexDeclaration(@decl, g_pVertexDeclaration));
DirectX 9,设备等在调用之前初始化(并且代码在没有着色器的情况下工作,我试图研究着色器),这个代码中没有错误,只有第一个位置和 D3DDECL_END 的 decl 数组。但是我的顶点着色器包含 4 个输入值,并且使用 DirectX SDK 中的 fxc.exe 编译没有错误。
struct VSInput
{
float3 Pos : POSITION;
float3 Normal : NORMAL;
float2 TexcoordUV : TEXCOORD0;
float2 TexcoordST : TEXCOORD1;
};
为什么会发生此错误以及如何避免?