gpt4 book ai didi

delphi - Delphi中的CreateVertexDeclaration错误

转载 作者:行者123 更新时间:2023-12-03 15:54:46 25 4
gpt4 key购买 nike

我有简单的声明:

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 错误 0:E_FAIL,发生了未确定的错误,位于

  CheckDxError(m_pd3dDevice.CreateVertexDeclaration(@decl, g_pVertexDeclaration));

DirectX 9、设备等在调用之前初始化(并且代码在没有着色器的情况下工作,我试图研究着色器),此代码中没有错误,decl 数组只有第一个位置和 D3DDECL_END。但我的顶点着色器包含 4 个输入值,并且使用 DirectX SDK 中的 fxc.exe 进行编译时没有错误。

struct VSInput
{
float3 Pos : POSITION;
float3 Normal : NORMAL;
float2 TexcoordUV : TEXCOORD0;
float2 TexcoordST : TEXCOORD1;
};

为什么会出现此错误以及如何避免?

最佳答案

您的第二个 TEXCOORD 需要将 UsageIndex 设置为 1

D3DDECLUSAGE 的文档确实涵盖了这一点:

D3DDECLUSAGE_TEXCOORD

Texture coordinate data. Use D3DDECLUSAGE_TEXCOORD, n to specify texture coordinates in fixed function vertex processing and in pixel shaders prior to ps_3_0. These can be used to pass user defined data.

n 的值是使用索引,如果您希望多个顶点元素具有相同的使用情况,则需要为它们提供不同的使用索引。

关于delphi - Delphi中的CreateVertexDeclaration错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18719849/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com