views:

470

answers:

4

I am using SlimDX with WinForms for a while now, but want to make the switch to WPF now. However, I can't figure out how to get DX10/11 working with WPF. The February release of SlimDX provides a WPF example, which only works with DX 9 though. I found the following solution: http://jmorrill.hjtcentral.com/Home/tabid/428/EntryId/437/Direct3D-10-11-Direct2D-in-WPF.aspx but can't get it to work with SlimDX. My main problem is the shared resource handle as I don't know how to retrieve the shared handle from a SlimDX texture. I can't find any information to this topic.

In C++ the code looks like this:

HRESULT D3DImageEx::GetSharedHandle(IUnknown *pUnknown, HANDLE * pHandle)
{
    HRESULT hr = S_OK;

    *pHandle = NULL;
    IDXGIResource* pSurface;

    if (FAILED(hr = pUnknown->QueryInterface(__uuidof(IDXGIResource), (void**)&pSurface)))
        return hr;

    hr = pSurface->GetSharedHandle(pHandle);
    pSurface->Release();

    return hr;
}

Basically, what I want to do (because I think that this is the solution), is to share a texture between a Direct3d9DeviceEx (for rendering the WPF D3DImage) and a Direct3d10Device (a texture render target for my scene).

Any pointers in the right direction are greatly appreciated.

A: 

There is a control called WindowsFormsHost, maybe you could integrate your current WinForm control that way?

LaZe
That works, however it does not integrate nicely with WPF. The WinForms control must be on top, can not be overlayed with other WPF controls etc.However, I managed to get DX10/WPF running nicely. I couldn't figure out if GetSharedHandle was available in SlimDX, so I checked out the source code and added some C++ code to provide me with the needed functionality.If I can find the time, I will post and update and explain my solution in some detail.
slurmomatic
A: 

I would like those details if you find the time, as I am currently playing around with WPF and SlimDX 10 also :-).

  • Peter
Peter
this should be a comment, not an answer
Neil N
A: 

Have a look at D3DImageEx. http://jmorrill.hjtcentral.com/Home/tabid/428/EntryId/437/Direct3D-10-11-Direct2D-in-WPF.aspx You provide a reference to your rendertarget, but it has to be created with the Shared flag. I was not able to use a swapchain in this way though.

let renderTargetDescription = Texture2DDescription(     Width=width,
                                                        Height=height,
                                                        MipLevels=1,
                                                        ArraySize=1,
                                                        Format = Format.B8G8R8A8_UNorm,
                                                        SampleDescription = SampleDescription(Count = 1),
                                                        BindFlags = (BindFlags.RenderTarget ||| BindFlags.ShaderResource),
                                                        OptionFlags = ResourceOptionFlags.Shared)
Johan
I posted the same link in my question above, unfortunately it does provide a solution to my problem.
slurmomatic
+1  A: 

They posted some sample code on how to use slimdx/directx10 with WPF. Here's the link

mdm20