sharpdx / SharpDX

SharpDX GitHub Repository
http://sharpdx.org
MIT License
1.69k stars 638 forks source link

Swapchain-Creation fails for DirectComposition in WinForms (not WinRT) #528

Closed TheWhiteAmbit closed 9 years ago

TheWhiteAmbit commented 9 years ago

I have a Windows Forms app that should make use of DirectComposition. Creating a Device with Swapchain like this works fine:

        SharpDX.Direct3D11.Device.CreateWithSwapChain(SharpDX.Direct3D.DriverType.Hardware, DeviceCreationFlags.BgraSupport, swapChainDescription, out device11, out swapChain);

But to use DirectComposition I want to make a call to CreateSwapChainForComposition that hides in a SwapChain1 ctor.

        device11 = new SharpDX.Direct3D11.Device(SharpDX.Direct3D.DriverType.Hardware, DeviceCreationFlags.BgraSupport);
        var dxgiDev = device11.QueryInterface<SharpDX.DXGI.Device>();
        var directComDev = new SharpDX.DirectComposition.Device(dxgiDev);
        SwapChainDescription1 description = new SwapChainDescription1()
        {
            Format = SharpDX.DXGI.Format.B8G8R8A8_UNorm,
            BufferCount = 2,
            SampleDescription = sampleDescription,
            SwapEffect = SwapEffect.FlipSequential,
            Usage = Usage.RenderTargetOutput | Usage.Shared,
            AlphaMode = SharpDX.DXGI.AlphaMode.Premultiplied,
            Flags = SwapChainFlags.None,
            Width = 1920,
            Height = 1080,
            Scaling = Scaling.Stretch,
            Stereo = false,
        };
        var factory = new SharpDX.DXGI.Factory2();
        var chain = new SharpDX.DXGI.SwapChain1(factory, directComDev, ref description);

But the summary quotes it is only available on WinRT (why not use it on in Forms, or at least somewere outside WinRT - doesn't it go all the way down to basic CreateWindowEx?). It throws: [

{"HRESULT: [0x887A0001], Module: [SharpDX.DXGI], ApiCode: [DXGI_ERROR_INVALID_CALL/InvalidCall], Message: The application made a call that is invalid. Either the parameters of the call or the state of some object was incorrect.\r\nEnable the D3D debug layer in order to see details via debug messages.\r\n"}

Is there any trick making it a valid call? Am I using SharpDX correct here? I use normal NuGet 2.6.3. And I am already using projectfile with SharpDXDirectXVersion tag set to DirectX11_2

xoofx commented 9 years ago

As it is suggested in the error message, follow this.

TheWhiteAmbit commented 9 years ago

Thank you. Sorry lost this one a litte bit. Still on the agenda. Had my own CLR-wrapper doing it nicely, but gave up the whole way after seeing it working - not performing ;)