4
votes

This question comes from my previous question here:

Delphi XE7 Abstract Error on StyleLookup with Effect (FireMonkey)

Basically, I have several styled controls with effects applied. The effects work on most systems so I don't want to take them out of my styles all together for the select few customers they won't work on. Is there a way to detect whether or not the client has DirectX 9 AND the GPU installed supports Pixel Shader 2.0?

1

1 Answers

6
votes

AFAIK there is not a direct way to determine the DirectX version, however Microsoft provides a sample function called GetDXVersion which is part of the DirectX SDK. This function runs a set of checks to determine the DirectX version. Luckily you can found a Delphi translation of that function in the DSPack project.

Now to detect the pixel shader version you must use the IDirect3D9::GetDeviceCaps method and then check the value of the PixelShaderVersion field of the D3DCAPS9 record.

Try this FMX sample

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;