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.