Jason Coley
Jason Coley

Reputation: 125

DirectX10 support in Firemonkey (not 10.1)

Is it possible to drop down to DX10 instead of DX10.1 support. I have a client whose computer supports DX10 only, so they can't take advantage of Direct2D as it seems that FM only supports 10.1

I have tried modifying the sources to use DX10 (FMX.Canvas.D2D and FMX.Context.DX10) and made another switch to drop down to DX10, but one call seems to fail.

I have modified the way the shareddevice is created

if not Assigned(FSharedDevice) then 
begin
SaveClearFPUState;
try
Flags := {$ifdef DXDEBUG}D3D10_CREATE_DEVICE_DEBUG{$else}0{$endif};
Flags := Flags or D3D10_CREATE_DEVICE_BGRA_SUPPORT;
HR := D3D10CreateDevice(nil, FDriverType, 0, Flags, D3D10_SDK_VERSION, FSharedDevice);
if Succeeded(HR) then
begin
HR := FSharedDevice.CreateBuffer(TD3D10_BufferDesc.Create(VBSize, D3D10_BIND_VERTEX_BUFFER, D3D10_USAGE_DYNAMIC, D3D10_CPU_ACCESS_WRITE), nil, @FVB);
HR := FSharedDevice.CreateBuffer(TD3D10_BufferDesc.Create(IBSize, D3D10_BIND_INDEX_BUFFER, D3D10_USAGE_DYNAMIC, D3D10_CPU_ACCESS_WRITE), nil, @FIB);
// Acquire device DXGI factory
HR := FSharedDevice.QueryInterface(IDXGIDevice, DXGIDevice);
if Succeeded(HR) and (DXGIDevice <> nil) then
begin
HR := DXGIDevice.GetParent(IDXGIAdapter, DXGIAdapter);
if Succeeded(HR) and (DXGIAdapter <> nil) then
HR := DXGIAdapter.GetParent(IDXGIFactory, FDXGIFactory);
end;
if not Assigned(FDXGIFactory) then
HR := CreateDXGIFactory(IDXGIFactory, FDXGIFactory);
end;
finally
RestoreFPUState;
end;
end;

and when I am using the device I use code like this below..

SharedDevice: ID3D10Device

if Assigned(TCustomDX10Context.SharedDevice) then
begin
FillChar(Desc, SizeOf(D3D10_TEXTURE2D_DESC), 0);
Desc.Format := DXGI_FORMAT_B8G8R8A8_UNORM;
Desc.Width := 1;
Desc.Height := 1;
Desc.MipLevels := 1;
Desc.ArraySize := 1;
Desc.SampleDesc.Count := 1;
Desc.SampleDesc.Quality := 0;
Desc.Usage := D3D10_USAGE_DEFAULT;
Desc.BindFlags := D3D10_BIND_RENDER_TARGET or D3D10_BIND_SHADER_RESOURCE;
Res := TCustomDX10Context.SharedDevice.CreateTexture2D(Desc, nil, FSharedTexture);
Prop := D2D1RenderTargetProperties(TargetMode, D2D1PixelFormat(DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED));
Res := FFactory.CreateDxgiSurfaceRenderTarget(FSharedTexture as IDXGISurface, Prop, FSharedRenderTarget);
end;

I have created a switch in the source that allows me to switch between the 10.1 and 10 device and have modified all code in FMX.Canvas.D2D and FMX.Context.DX10 to use the alternative device.

BUT...

CreateDxgiSurfaceRenderTarget fails with an error code -2147024809.

So the app loads, but the forms are all blank, because of not being able to create the Target.

Any guru's out there that could help with this?

Upvotes: 2

Views: 824

Answers (1)

Kenny Kerr
Kenny Kerr

Reputation: 3115

Direct2D 1.0 supports interop with Direct3D 10.1 but it can still support Direct3D 10.0 hardware via feature level selection. I don’t know anything about Delphi, but instead of calling D3D10CreateDevice to create the Direct3D device, you need to call the D3D10CreateDevice1 function. You can then simply request the feature level you desire, such as D3D10_FEATURE_LEVEL_10_0.

Upvotes: 2

Related Questions