在运行时检测 GPU 是否支持 Pixel Shader 2.0 (Firemonkey)
Detect if GPU supports Pixel Shader 2.0 at runtime (Firemonkey)
这个问题来自我之前的问题:
Delphi XE7 Abstract Error on StyleLookup with Effect (FireMonkey)
基本上,我有几个应用了效果的样式控件。这些效果在大多数系统上都有效,所以我不想为了 select 少数无法使用的客户而将它们从我的样式中移除。有没有办法检测客户端是否有 DirectX 9 AND 安装的 GPU 是否支持 Pixel Shader 2.0?
AFAIK 没有确定 DirectX 版本的直接方法,但是 Microsoft 提供了一个名为 GetDXVersion 的示例函数,它是 DirectX SDK 的一部分。此函数运行一组检查以确定 DirectX 版本。幸运的是,您可以在 DSPack
项目中找到该函数的 Delphi 翻译。
现在要检测像素着色器版本,您必须使用 IDirect3D9::GetDeviceCaps
method and then check the value of the PixelShaderVersion
field of the D3DCAPS9
记录。
试试这个 FMX 示例
uses
Winapi.Windows,
Winapi.Direct3D9,
FMX.Context.DX9;
procedure TForm1.Button1Click(Sender: TObject);
var
LCaps: TD3DCaps9;
LPixelShaderVersionMajor, LPixelShaderVersionMinor : Cardinal;
begin
ZeroMemory(@LCaps, SizeOf(LCaps));
if TCustomDX9Context.Direct3D9Obj.GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, LCaps) = S_OK then
begin
LPixelShaderVersionMajor:= D3DSHADER_VERSION_MAJOR(LCaps.PixelShaderVersion);
LPixelShaderVersionMinor:= D3DSHADER_VERSION_MINOR(LCaps.PixelShaderVersion);
ShowMessage(Format('PixelShaderVersion %d.%d', [LPixelShaderVersionMajor, LPixelShaderVersionMinor]));
end;
//also you can use the D3DPS_VERSION function to determine if the version returned meets the requirements
if (LCaps.PixelShaderVersion >= D3DPS_VERSION(2, 0)) then
ShowMessage('Hey your PixelShaderVersion is compatible');
end;
这个问题来自我之前的问题:
Delphi XE7 Abstract Error on StyleLookup with Effect (FireMonkey)
基本上,我有几个应用了效果的样式控件。这些效果在大多数系统上都有效,所以我不想为了 select 少数无法使用的客户而将它们从我的样式中移除。有没有办法检测客户端是否有 DirectX 9 AND 安装的 GPU 是否支持 Pixel Shader 2.0?
AFAIK 没有确定 DirectX 版本的直接方法,但是 Microsoft 提供了一个名为 GetDXVersion 的示例函数,它是 DirectX SDK 的一部分。此函数运行一组检查以确定 DirectX 版本。幸运的是,您可以在 DSPack
项目中找到该函数的 Delphi 翻译。
现在要检测像素着色器版本,您必须使用 IDirect3D9::GetDeviceCaps
method and then check the value of the PixelShaderVersion
field of the D3DCAPS9
记录。
试试这个 FMX 示例
uses
Winapi.Windows,
Winapi.Direct3D9,
FMX.Context.DX9;
procedure TForm1.Button1Click(Sender: TObject);
var
LCaps: TD3DCaps9;
LPixelShaderVersionMajor, LPixelShaderVersionMinor : Cardinal;
begin
ZeroMemory(@LCaps, SizeOf(LCaps));
if TCustomDX9Context.Direct3D9Obj.GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, LCaps) = S_OK then
begin
LPixelShaderVersionMajor:= D3DSHADER_VERSION_MAJOR(LCaps.PixelShaderVersion);
LPixelShaderVersionMinor:= D3DSHADER_VERSION_MINOR(LCaps.PixelShaderVersion);
ShowMessage(Format('PixelShaderVersion %d.%d', [LPixelShaderVersionMajor, LPixelShaderVersionMinor]));
end;
//also you can use the D3DPS_VERSION function to determine if the version returned meets the requirements
if (LCaps.PixelShaderVersion >= D3DPS_VERSION(2, 0)) then
ShowMessage('Hey your PixelShaderVersion is compatible');
end;