检测GPU是否在运行时支持Pixel Shader 2.0(Firemonkey)

Sme*_*Wiz 4 delphi directx firemonkey delphi-xe7

这个问题来自我之前的问题:

具有效果的StyleLookup上的Delphi XE7抽象错误(FireMonkey)

基本上,我有几个样式控件应用效果.这些效果适用于大多数系统,因此我不想将它们全部用于我的样式,以供那些他们不会使用的少数客户使用.有没有一种方法来检测客户端是否具有支持DirectX 9 和安装在GPU支持的Pixel Shader 2.0吗?

RRU*_*RUZ 6

AFAIK没有直接的方法来确定DirectX版本,但Microsoft提供了一个名为GetDXVersion的示例函数,它是DirectX SDK的一部分.此函数运行一组检查以确定DirectX版本.幸运的是,你可以在DSPack项目中找到该函数的Delphi翻译.

现在要检测像素着色器版本,您必须使用该IDirect3D9::GetDeviceCaps方法,然后检查记录PixelShaderVersion字段的值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;
Run Code Online (Sandbox Code Playgroud)