4

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?

Community
  • 1
  • 1
SmeTheWiz
  • 210
  • 1
  • 8

1 Answers1

6

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;
RRUZ
  • 134,889
  • 20
  • 356
  • 483
  • Really appreciate it! – SmeTheWiz Mar 10 '15 at 23:31
  • 1
    To expand on this answer, there is the `TCustomDX9Context.HardwareSupported` boolean function, but it only checks if it can initialize DirectX9, Embarcadero should include the shader version check in this function... – whosrdaddy Mar 11 '15 at 07:45