C# SharpDX - from Control to Fullscreen DXGI_ERROR_INVALID_CALL

0

I have a problem with switching from render to a windows form control to render to fullscreen. so I ripped the problem to a small example project that only includes the swapchain and device initialization and the fullscreen switch.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

using SharpDX;
using SharpDX.DXGI;
using SharpDX.Direct3D;
using SharpDX.Direct3D11;

using Device = SharpDX.Direct3D11.Device;

namespace ControlToFullscreenTest
{
    static class Program
    {
        static Device device;
        static SwapChain swapchain;
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Form1 form = new Form1();

            Control control = form.pictureBox1; //Doesnt work
            //Control control = form;  //works
            control.MouseClick += new MouseEventHandler(click);

            SwapChainDescription sd = new SwapChainDescription()
            {
                BufferCount = 1,
                Flags = SwapChainFlags.AllowModeSwitch,
                IsWindowed = true, //false doesnt work too !
                ModeDescription = new ModeDescription(control.ClientSize.Width, control.ClientSize.Height, Rational.Empty, Format.R8G8B8A8_UNorm),
                OutputHandle = control.Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect = SwapEffect.Discard,
                Usage = Usage.RenderTargetOutput,
            };

            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, sd, out device, out swapchain);

            Factory DxgiFactory;
            SharpDX.DXGI.Device d = device.QueryInterface<SharpDX.DXGI.Device>();
            Adapter a = d.GetParent<Adapter>();
            DxgiFactory = a.GetParent<Factory>();

            DxgiFactory.MakeWindowAssociation(control.Handle, WindowAssociationFlags.None);

            form.Show();

            while(form.Focused)
            {
                swapchain.Present(0, PresentFlags.None);
                Application.DoEvents();
            }
        }

        static void click(object o, EventArgs args)
        {
            swapchain.ResizeBuffers(1, 1920, 1080, Format.Unknown, SwapChainFlags.AllowModeSwitch);
            swapchain.SetFullscreenState(true, null);
        }
    }
}

The switch works fine with a normal windows form but not with a control.

swapchain.SetFullscreenState(true, null);

throws HRESULT: [0x887A0001], Module: [SharpDX.DXGI], ApiCode: [DXGI_ERROR_INVALID_CALL/InvalidCall]

There is nothing about it in the MSDN. Its not even possible to initialize the Swapchain in fullscreen with the control. I know I can fix this by creating a new window and then render in fullscreen mode but I want to know if it is possible without this changing.

Would be really nice if somebody has an idea, information or a link I didnt found.

c#
.net
directx
sharpdx
asked on Stack Overflow Jun 10, 2014 by Bähny • edited Jun 11, 2014 by Bähny

1 Answer

0

Setting a SwapChain to FullScreen requires a non child control, so your picturebox does not satisfy this condition.

Using Debug device creation flag, the following error message will pop in your output window when you try to set to full screen:

DXGI ERROR: IDXGISwapChain::SetFullscreenState: Fullscreen is not allowed for swapchains targetting a child window. Applications are advised to create a second swapchain targeting a non-child window. [ MISCELLANEOUS ERROR #82: ]

answered on Stack Overflow Jun 13, 2014 by catflier

User contributions licensed under CC BY-SA 3.0