Пример #1
0
        static void TryChangeToFullscreen()
        {
            if (m_changeToFullscreen.HasValue)
            {
                var md = m_changeToFullscreen.Value;

                try
                {
                    var adapterDevId = m_adapterInfoList[m_settings.AdapterOrdinal].AdapterDeviceId;
                    var outputId     = m_adapterInfoList[m_settings.AdapterOrdinal].OutputId;

                    m_swapchain.ResizeTarget(ref md);
                    m_swapchain.SetFullscreenState(true, GetFactory().Adapters[adapterDevId].Outputs.Length > outputId ? GetFactory().Adapters[adapterDevId].Outputs[outputId] : null);

                    md.RefreshRate.Numerator   = 0;
                    md.RefreshRate.Denominator = 0;
                    m_swapchain.ResizeTarget(ref md);

                    m_changeToFullscreen = null;

                    Log.WriteLine("DXGI SetFullscreenState succeded");
                }
                catch (SharpDX.SharpDXException e)
                {
                    if (e.ResultCode == SharpDX.DXGI.ResultCode.Unsupported)
                    {
                        m_changeToFullscreen = null;
                    }

                    Log.WriteLine("TryChangeToFullscreen failed with " + e.ResultCode);
                }
            }
        }
Пример #2
0
        static void TryChangeToFullscreen()
        {
            if (m_changeToFullscreen.HasValue)
            {
                var md = m_changeToFullscreen.Value;

                try
                {
                    var adapterDevId = m_adapterInfoList[m_settings.AdapterOrdinal].AdapterDeviceId;
                    var outputId     = m_adapterInfoList[m_settings.AdapterOrdinal].OutputId;

                    m_swapchain.ResizeTarget(ref md);
                    m_swapchain.SetFullscreenState(true, GetFactory().Adapters[adapterDevId].Outputs[outputId]);

                    md.RefreshRate.Numerator   = 0;
                    md.RefreshRate.Denominator = 0;
                    m_swapchain.ResizeTarget(ref md);

                    m_changeToFullscreen = null;

                    MyRender11.Log.WriteLine("DXGI SetFullscreenState succeded");
                }
                catch (SharpDX.SharpDXException e)
                {
                    // there might be some fatal exception, or minor exception saying that windows is overlapped/has no mouse focus and going to fullscreen should be done later
                }
            }
        }
Пример #3
0
        private SwapChain CreateSwapChainForDesktop(IntPtr handle)
        {
            bufferCount = 1;
            var description = new SwapChainDescription
            {
                ModeDescription   = new ModeDescription(Description.BackBufferWidth, Description.BackBufferHeight, Description.RefreshRate.ToSharpDX(), (SharpDX.DXGI.Format)Description.BackBufferFormat),
                BufferCount       = bufferCount, // TODO: Do we really need this to be configurable by the user?
                OutputHandle      = handle,
                SampleDescription = new SampleDescription((int)Description.MultiSampleCount, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = SharpDX.DXGI.Usage.BackBuffer | SharpDX.DXGI.Usage.RenderTargetOutput,
                IsWindowed        = true,
                Flags             = Description.IsFullScreen ? SwapChainFlags.AllowModeSwitch : SwapChainFlags.None,
            };

            var newSwapChain = new SwapChain(GraphicsAdapterFactory.NativeFactory, GraphicsDevice.NativeDevice, description);

            if (Description.IsFullScreen)
            {
                // Before fullscreen switch
                newSwapChain.ResizeTarget(ref description.ModeDescription);

                // Switch to full screen
                newSwapChain.IsFullScreen = true;

                // This is really important to call ResizeBuffers AFTER switching to IsFullScreen
                newSwapChain.ResizeBuffers(bufferCount, Description.BackBufferWidth, Description.BackBufferHeight, (SharpDX.DXGI.Format)Description.BackBufferFormat, SwapChainFlags.AllowModeSwitch);
            }

            return(newSwapChain);
        }
Пример #4
0
        protected override SwapChain CreateSwapChainResources()
        {
            IntPtr?handle  = null;
            var    control = Description.DeviceWindowHandle as Control;

            if (control != null)
            {
                handle = control.Handle;
            }
            else if (Description.DeviceWindowHandle is IntPtr)
            {
                handle = (IntPtr)Description.DeviceWindowHandle;
            }

            if (!handle.HasValue)
            {
                throw new NotSupportedException(
                          string.Format("DeviceWindowHandle of type [{0}] is not supported. Only System.Windows.Control or IntPtr are supported",
                                        Description.DeviceWindowHandle != null ? Description.DeviceWindowHandle.GetType().Name : "null"));
            }

            int requestedMultiSampleCount = (int)Description.MultiSampleCount;
            int multiSampleCount          = Math.Min((int)DirectXDevice.Features[Description.BackBufferFormat].MSAALevelMax, requestedMultiSampleCount);

            if (multiSampleCount < (int)Description.MultiSampleCount)
            {
                LogEvent.Engine.Warning(string.Format("Requested MultiSampleCount of {0} not supported, using {1} instead", requestedMultiSampleCount, multiSampleCount));
            }

            BufferCount = 1;
            var description = new SwapChainDescription
            {
                ModeDescription = new ModeDescription(Description.BackBufferWidth, Description.BackBufferHeight, Description.RefreshRate,
                                                      Description.BackBufferFormat),
                BufferCount       = BufferCount, // TODO: Do we really need this to be configurable by the user?
                OutputHandle      = handle.Value,
                SampleDescription = new SampleDescription(multiSampleCount, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Description.RenderTargetUsage,
                IsWindowed        = true,
                Flags             = Description.Flags,
            };

            var newSwapChain = new SwapChain(GraphicsAdapter.Factory, (Device)DirectXDevice, description);

            if (Description.IsFullScreen)
            {
                // Before fullscreen switch
                newSwapChain.ResizeTarget(ref description.ModeDescription);

                // Switch to full screen
                newSwapChain.IsFullScreen = true;

                // This is really important to call ResizeBuffers AFTER switching to IsFullScreen
                newSwapChain.ResizeBuffers(BufferCount, Description.BackBufferWidth, Description.BackBufferHeight,
                                           Description.BackBufferFormat, SwapChainFlags.AllowModeSwitch);
            }

            return(newSwapChain);
        }
Пример #5
0
        /// <summary>
        /// Hooked to allow resizing a texture/surface that is reused. Currently not in use as we create the texture for each request
        /// to support different sizes each time (as we use DirectX to copy only the region we are after rather than the entire backbuffer)
        /// </summary>
        /// <param name="swapChainPtr"></param>
        /// <param name="newTargetParameters"></param>
        /// <returns></returns>
        int ResizeTargetHook(IntPtr swapChainPtr, ref DXGI.DXGI_MODE_DESC newTargetParameters)
        {
            if (swapChainPtr != _swapChainPointer)
            {
                _swapChain = SlimDX.DXGI.SwapChain.FromPointer(swapChainPtr);
            }
            SwapChain swapChain = _swapChain;
            //using (SlimDX.DXGI.SwapChain swapChain = SlimDX.DXGI.SwapChain.FromPointer(swapChainPtr))
            {
                // This version creates a new texture for each request so there is nothing to resize.
                // IF the size of the texture is known each time, we could create it once, and then possibly need to resize it here

                return(swapChain.ResizeTarget(
                           new SlimDX.DXGI.ModeDescription()
                {
                    Format = newTargetParameters.Format,
                    Height = newTargetParameters.Height,
                    RefreshRate = newTargetParameters.RefreshRate,
                    Scaling = newTargetParameters.Scaling,
                    ScanlineOrdering = newTargetParameters.ScanlineOrdering,
                    Width = newTargetParameters.Width
                }
                           ).Code);
            }
        }
Пример #6
0
        /// <summary>
        /// Hooked to allow resizing a texture/surface that is reused. Currently not in use as we create the texture for each request
        /// to support different sizes each time (as we use DirectX to copy only the region we are after rather than the entire backbuffer)
        /// </summary>
        /// <param name="swapChainPtr"></param>
        /// <param name="newTargetParameters"></param>
        /// <returns></returns>
        int ResizeTargetHook(IntPtr swapChainPtr, ref DXGI.DXGI_MODE_DESC newTargetParameters)
        {
            DebugMessage("ResizeTarget");
            try
            {
                if (_swapChain == null)
                {
                    _swapChain = SlimDX.DXGI.SwapChain.FromPointer(swapChainPtr);
                }
                SwapChain swapChain = _swapChain;
                //using (SlimDX.DXGI.SwapChain swapChain = SlimDX.DXGI.SwapChain.FromPointer(swapChainPtr))
                {
                    // This version creates a new texture for each request so there is nothing to resize.
                    // IF the size of the texture is known each time, we could create it once, and then possibly need to resize it here

                    return(swapChain.ResizeTarget(
                               new SlimDX.DXGI.ModeDescription()
                    {
                        Format = newTargetParameters.Format,
                        Height = newTargetParameters.Height,
                        RefreshRate = newTargetParameters.RefreshRate,
                        Scaling = newTargetParameters.Scaling,
                        ScanlineOrdering = newTargetParameters.ScanlineOrdering,
                        Width = newTargetParameters.Width
                    }
                               ).Code);
                }
            }
            catch (Exception ex)
            {
                DebugMessage(ex.ToString());
                return(System.Runtime.InteropServices.Marshal.GetHRForException(ex));
            }
        }
Пример #7
0
        /// <summary>
        /// Hooked to allow resizing a texture/surface that is reused. Currently not in use as we create the texture for each request
        /// to support different sizes each time (as we use DirectX to copy only the region we are after rather than the entire backbuffer)
        /// </summary>
        /// <param name="swapChainPtr"></param>
        /// <param name="newTargetParameters"></param>
        /// <returns></returns>
        int ResizeTargetHook(IntPtr swapChainPtr, ref ModeDescription newTargetParameters)
        {
            SwapChain swapChain = (SwapChain)swapChainPtr;

            // This version creates a new texture for each request so there is nothing to resize.
            // IF the size of the texture is known each time, we could create it once, and then possibly need to resize it here

            swapChain.ResizeTarget(ref newTargetParameters);
            return(SharpDX.Result.Ok.Code);
        }
Пример #8
0
        /// <summary>
        /// Hooked to allow resizing a texture/surface that is reused. Currently not in use as we create the texture for each request
        /// to support different sizes each time (as we use DirectX to copy only the region we are after rather than the entire backbuffer)
        /// </summary>
        /// <param name="swapChainPtr"></param>
        /// <param name="newTargetParameters"></param>
        /// <returns></returns>
        int ResizeTargetHook(IntPtr swapChainPtr, ref ModeDescription newTargetParameters)
        {
            if (swapChainPtr != _swapChainPointer)
            {
                _swapChain = SlimDX.DXGI.SwapChain.FromPointer(swapChainPtr);
            }
            SwapChain swapChain = _swapChain;
            {
                // This version creates a new texture for each request so there is nothing to resize.
                // IF the size of the texture is known each time, we could create it once, and then possibly need to resize it here

                return(swapChain.ResizeTarget(newTargetParameters).Code);
            }
        }
Пример #9
0
        private SwapChain CreateSwapChainForDesktop(IntPtr handle)
        {
            bufferCount = 1;
            var backbufferFormat = Description.BackBufferFormat;

#if XENKO_GRAPHICS_API_DIRECT3D12
            // TODO D3D12 (check if this setting make sense on D3D11 too?)
            backbufferFormat = backbufferFormat.ToNonSRgb();
            // TODO D3D12 Can we make it work with something else after?
            bufferCount = 2;
#endif
            var description = new SwapChainDescription
            {
                ModeDescription   = new ModeDescription(Description.BackBufferWidth, Description.BackBufferHeight, Description.RefreshRate.ToSharpDX(), (SharpDX.DXGI.Format)backbufferFormat),
                BufferCount       = bufferCount, // TODO: Do we really need this to be configurable by the user?
                OutputHandle      = handle,
                SampleDescription = new SampleDescription((int)Description.MultisampleCount, 0),
#if XENKO_GRAPHICS_API_DIRECT3D11
                SwapEffect = SwapEffect.Discard,
#elif XENKO_GRAPHICS_API_DIRECT3D12
                SwapEffect = SwapEffect.FlipDiscard,
#endif
                Usage      = SharpDX.DXGI.Usage.BackBuffer | SharpDX.DXGI.Usage.RenderTargetOutput,
                IsWindowed = true,
                Flags      = Description.IsFullScreen ? SwapChainFlags.AllowModeSwitch : SwapChainFlags.None,
            };

#if XENKO_GRAPHICS_API_DIRECT3D11
            var newSwapChain = new SwapChain(GraphicsAdapterFactory.NativeFactory, GraphicsDevice.NativeDevice, description);
#elif XENKO_GRAPHICS_API_DIRECT3D12
            var newSwapChain = new SwapChain(GraphicsAdapterFactory.NativeFactory, GraphicsDevice.NativeCommandQueue, description);
#endif

            //prevent normal alt-tab
            GraphicsAdapterFactory.NativeFactory.MakeWindowAssociation(handle, WindowAssociationFlags.IgnoreAltEnter);

            if (Description.IsFullScreen)
            {
                // Before fullscreen switch
                newSwapChain.ResizeTarget(ref description.ModeDescription);

                // Switch to full screen
                newSwapChain.IsFullScreen = true;

                // This is really important to call ResizeBuffers AFTER switching to IsFullScreen
                newSwapChain.ResizeBuffers(bufferCount, Description.BackBufferWidth, Description.BackBufferHeight, (SharpDX.DXGI.Format)Description.BackBufferFormat, SwapChainFlags.AllowModeSwitch);
            }

            return(newSwapChain);
        }
Пример #10
0
        private SwapChain CreateSwapChainForDesktop()
        {
            IntPtr?handle  = null;
            var    control = Description.DeviceWindowHandle as Control;

            if (control != null)
            {
                handle = control.Handle;
            }
            else if (Description.DeviceWindowHandle is IntPtr)
            {
                handle = (IntPtr)Description.DeviceWindowHandle;
            }

            if (!handle.HasValue)
            {
                throw new NotSupportedException(string.Format("DeviceWindowHandle of type [{0}] is not supported. Only System.Windows.Control or IntPtr are supported", Description.DeviceWindowHandle != null ? Description.DeviceWindowHandle.GetType().Name : "null"));
            }

            bufferCount = 1;
            var description = new SwapChainDescription
            {
                ModeDescription   = new ModeDescription(Description.BackBufferWidth, Description.BackBufferHeight, Description.RefreshRate, Description.BackBufferFormat),
                BufferCount       = bufferCount, // TODO: Do we really need this to be configurable by the user?
                OutputHandle      = handle.Value,
                SampleDescription = new SampleDescription((int)Description.MultiSampleCount, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Description.RenderTargetUsage,
                IsWindowed        = true,
                Flags             = Description.Flags,
            };

            var newSwapChain = new SwapChain(GraphicsAdapter.Factory, (Direct3D11.Device)GraphicsDevice, description);

            if (Description.IsFullScreen)
            {
                // Before fullscreen switch
                newSwapChain.ResizeTarget(ref description.ModeDescription);

                // Switch to full screen
                newSwapChain.IsFullScreen = true;

                // This is really important to call ResizeBuffers AFTER switching to IsFullScreen
                newSwapChain.ResizeBuffers(bufferCount, Description.BackBufferWidth, Description.BackBufferHeight, Description.BackBufferFormat, SwapChainFlags.AllowModeSwitch);
            }

            return(newSwapChain);
        }
        public void SetSize(Size size)
        {
            DestroyD3D11Resources();

            mSwapChain.ResizeBuffers(1,
                                     (int)size.Width,
                                     (int)size.Height,
                                     Format.R8G8B8A8_UNorm,
                                     SwapChainFlags.None);

            mSwapChain.ResizeTarget(new ModeDescription((int)size.Width,
                                                        (int)size.Height,
                                                        new Rational(60, 1),
                                                        Format.R8G8B8A8_UNorm));

            CreateD3D11Resources((int)size.Width, (int)size.Height);
            Render();
        }
Пример #12
0
        /// <summary>
        /// Hooked to allow resizing a texture/surface that is reused. Currently not in use as we create the texture for each request
        /// to support different sizes each time (as we use DirectX to copy only the region we are after rather than the entire backbuffer)
        /// </summary>
        /// <param name="swapChainPtr"></param>
        /// <param name="newTargetParameters"></param>
        /// <returns></returns>
        int ResizeTargetHook(IntPtr swapChainPtr, ref ModeDescription newTargetParameters)
        {
            SwapChain swapChain = (SharpDX.DXGI.SwapChain)swapChainPtr;
            //using (SharpDX.DXGI.SwapChain swapChain = SharpDX.DXGI.SwapChain.FromPointer(swapChainPtr))
            {
                // This version creates a new texture for each request so there is nothing to resize.
                // IF the size of the texture is known each time, we could create it once, and then possibly need to resize it here

                // Dispose of overlay engine (so it will be recreated)
                if (_overlayEngine != null)
                {
                    _overlayEngine.Dispose();
                    _overlayEngine = null;
                }

                swapChain.ResizeTarget(ref newTargetParameters);
                return(SharpDX.Result.Ok.Code);
            }
        }
        private SwapChain CreateSwapChainForDesktop()
        {
            var control = Description.DeviceWindowHandle.NativeHandle as Control;

            if (control == null)
            {
                throw new NotSupportedException(string.Format("Form of type [{0}] is not supported. Only System.Windows.Control are supported", Description.DeviceWindowHandle != null ? Description.DeviceWindowHandle.GetType().Name : "null"));
            }

            bufferCount = 1;
            var description = new SwapChainDescription
            {
                ModeDescription   = new ModeDescription(Description.BackBufferWidth, Description.BackBufferHeight, Description.RefreshRate.ToSharpDX(), (SharpDX.DXGI.Format)Description.BackBufferFormat),
                BufferCount       = bufferCount, // TODO: Do we really need this to be configurable by the user?
                OutputHandle      = control.Handle,
                SampleDescription = new SampleDescription((int)Description.MultiSampleCount, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = SharpDX.DXGI.Usage.BackBuffer | SharpDX.DXGI.Usage.RenderTargetOutput,
                IsWindowed        = true,
                Flags             = Description.IsFullScreen ? SwapChainFlags.AllowModeSwitch : SwapChainFlags.None,
            };

            var newSwapChain = new SwapChain(GraphicsAdapterFactory.NativeFactory, GraphicsDevice.NativeDevice, description);

            if (Description.IsFullScreen)
            {
                // Before fullscreen switch
                newSwapChain.ResizeTarget(ref description.ModeDescription);

                // Switch to full screen
                newSwapChain.IsFullScreen = true;

                // This is really important to call ResizeBuffers AFTER switching to IsFullScreen
                newSwapChain.ResizeBuffers(bufferCount, Description.BackBufferWidth, Description.BackBufferHeight, (SharpDX.DXGI.Format)Description.BackBufferFormat, SwapChainFlags.AllowModeSwitch);
            }

            return(newSwapChain);
        }
Пример #14
0
        private void ControlViewport_Resize(object sender, EventArgs e)
        {
            if (depthStencilView != null)
            {
                depthStencilTexture.Dispose();
                depthStencilTexture = null;
                backBufferTexture.Dispose();
                backBufferTexture = null;

                depthStencilView.Dispose();
                depthStencilView = null;
                backBufferView.Dispose();
                backBufferView = null;
            }

            if (ClientSize.Width <= 0 || ClientSize.Height <= 0)
            {
                return;
            }

            Renderer.Current.Context.ClearState();

            swapChain.ResizeBuffers(1, ClientSize.Width, ClientSize.Height, Format.R8G8B8A8_UNorm, SwapChainFlags.None);

            var md = new ModeDescription();

            md.Width       = ClientSize.Width;
            md.Height      = ClientSize.Height;
            md.Format      = Format.R8G8B8A8_UNorm;
            md.RefreshRate = new Rational(60, 1);
            swapChain.ResizeTarget(ref md);

            backBufferTexture = swapChain.GetBackBuffer <Texture2D>(0);
            backBufferView    = new RenderTargetView(Renderer.Current.Device, backBufferTexture);

            RecreateDepthStencilView(swapChain.Description);
        }
Пример #15
0
        private SwapChain CreateSwapChainForDesktop()
        {
            IntPtr? handle = null;
            var control = Description.DeviceWindowHandle as Control;
            if (control != null) handle = control.Handle;
            else if (Description.DeviceWindowHandle is IntPtr) handle = (IntPtr)Description.DeviceWindowHandle;

            if (!handle.HasValue)
            {
                throw new NotSupportedException(string.Format("DeviceWindowHandle of type [{0}] is not supported. Only System.Windows.Control or IntPtr are supported", Description.DeviceWindowHandle != null ? Description.DeviceWindowHandle.GetType().Name : "null"));
            }

            bufferCount = 1;
            var description = new SwapChainDescription
                {
                    ModeDescription = new ModeDescription(Description.BackBufferWidth, Description.BackBufferHeight, Description.RefreshRate, Description.BackBufferFormat),
                    BufferCount = bufferCount, // TODO: Do we really need this to be configurable by the user?
                    OutputHandle = handle.Value,
                    SampleDescription = new SampleDescription((int)Description.MultiSampleCount, 0),
                    SwapEffect = SwapEffect.Discard,
                    Usage = Description.RenderTargetUsage,
                    IsWindowed = true,
                    Flags = Description.Flags,
                };

            var newSwapChain = new SwapChain(GraphicsAdapter.Factory, (Direct3D11.Device)GraphicsDevice, description);
            if (Description.IsFullScreen)
            {
                // Before fullscreen switch
                newSwapChain.ResizeTarget(ref description.ModeDescription);

                // Switch to full screen
                newSwapChain.IsFullScreen = true;

                // This is really important to call ResizeBuffers AFTER switching to IsFullScreen 
                newSwapChain.ResizeBuffers(bufferCount, Description.BackBufferWidth, Description.BackBufferHeight, Description.BackBufferFormat, SwapChainFlags.AllowModeSwitch);
            }

            return newSwapChain;
        }
        private SwapChain CreateSwapChainForDesktop(IntPtr handle)
        {
            bufferCount = 1;
            var description = new SwapChainDescription
                {
                    ModeDescription = new ModeDescription(Description.BackBufferWidth, Description.BackBufferHeight, Description.RefreshRate.ToSharpDX(), (SharpDX.DXGI.Format)Description.BackBufferFormat), 
                    BufferCount = bufferCount, // TODO: Do we really need this to be configurable by the user?
                    OutputHandle = handle,
                    SampleDescription = new SampleDescription((int)Description.MultiSampleCount, 0), 
                    SwapEffect = SwapEffect.Discard,
                    Usage = SharpDX.DXGI.Usage.BackBuffer | SharpDX.DXGI.Usage.RenderTargetOutput,
                    IsWindowed = true,
                    Flags = Description.IsFullScreen ? SwapChainFlags.AllowModeSwitch : SwapChainFlags.None, 
                };

            var newSwapChain = new SwapChain(GraphicsAdapterFactory.NativeFactory, GraphicsDevice.NativeDevice, description);
            if (Description.IsFullScreen)
            {
                // Before fullscreen switch
                newSwapChain.ResizeTarget(ref description.ModeDescription);

                // Switch to full screen
                newSwapChain.IsFullScreen = true;

                // This is really important to call ResizeBuffers AFTER switching to IsFullScreen 
                newSwapChain.ResizeBuffers(bufferCount, Description.BackBufferWidth, Description.BackBufferHeight, (SharpDX.DXGI.Format)Description.BackBufferFormat, SwapChainFlags.AllowModeSwitch);
            }

            return newSwapChain;
        }
Пример #17
0
 private void ResizeBuffers()
 {
     SwapChain.ResizeTarget(ref Resolution);
     SwapChain.ResizeBuffers(2, Resolution.Width, Resolution.Height, Resolution.Format, SwapChainFlags.AllowModeSwitch);
 }
        private SwapChain CreateSwapChainForDesktop(IntPtr handle)
        {
            bufferCount = 1;
            var backbufferFormat = Description.BackBufferFormat;
#if SILICONSTUDIO_XENKO_GRAPHICS_API_DIRECT3D12
            // TODO D3D12 (check if this setting make sense on D3D11 too?)
            backbufferFormat = backbufferFormat.ToNonSRgb();
            // TODO D3D12 Can we make it work with something else after?
            bufferCount = 2;
#endif
            var description = new SwapChainDescription
                {
                    ModeDescription = new ModeDescription(Description.BackBufferWidth, Description.BackBufferHeight, Description.RefreshRate.ToSharpDX(), (SharpDX.DXGI.Format)backbufferFormat), 
                    BufferCount = bufferCount, // TODO: Do we really need this to be configurable by the user?
                    OutputHandle = handle,
                    SampleDescription = new SampleDescription((int)Description.MultiSampleLevel, 0),
#if SILICONSTUDIO_XENKO_GRAPHICS_API_DIRECT3D11
                    SwapEffect = SwapEffect.Discard,
#elif SILICONSTUDIO_XENKO_GRAPHICS_API_DIRECT3D12
                    SwapEffect = SwapEffect.FlipDiscard,
#endif
                    Usage = SharpDX.DXGI.Usage.BackBuffer | SharpDX.DXGI.Usage.RenderTargetOutput,
                    IsWindowed = true,
                    Flags = Description.IsFullScreen ? SwapChainFlags.AllowModeSwitch : SwapChainFlags.None, 
                };

#if SILICONSTUDIO_XENKO_GRAPHICS_API_DIRECT3D11
            var newSwapChain = new SwapChain(GraphicsAdapterFactory.NativeFactory, GraphicsDevice.NativeDevice, description);
#elif SILICONSTUDIO_XENKO_GRAPHICS_API_DIRECT3D12
            var newSwapChain = new SwapChain(GraphicsAdapterFactory.NativeFactory, GraphicsDevice.NativeCommandQueue, description);
#endif

            //prevent normal alt-tab
            GraphicsAdapterFactory.NativeFactory.MakeWindowAssociation(handle, WindowAssociationFlags.IgnoreAltEnter);

            if (Description.IsFullScreen)
            {
                // Before fullscreen switch
                newSwapChain.ResizeTarget(ref description.ModeDescription);

                // Switch to full screen
                newSwapChain.IsFullScreen = true;

                // This is really important to call ResizeBuffers AFTER switching to IsFullScreen 
                newSwapChain.ResizeBuffers(bufferCount, Description.BackBufferWidth, Description.BackBufferHeight, (SharpDX.DXGI.Format)Description.BackBufferFormat, SwapChainFlags.AllowModeSwitch);
            }

            return newSwapChain;
        }
        private SwapChain CreateSwapChainForDesktop()
        {
            var control = Description.DeviceWindowHandle.NativeHandle as Control;
            if (control == null)
            {
                throw new NotSupportedException(string.Format("Form of type [{0}] is not supported. Only System.Windows.Control are supported", Description.DeviceWindowHandle != null ? Description.DeviceWindowHandle.GetType().Name : "null"));
            }

            bufferCount = 1;
            var description = new SwapChainDescription
                {
                    ModeDescription = new ModeDescription(Description.BackBufferWidth, Description.BackBufferHeight, Description.RefreshRate.ToSharpDX(), (SharpDX.DXGI.Format)Description.BackBufferFormat), 
                    BufferCount = bufferCount, // TODO: Do we really need this to be configurable by the user?
                    OutputHandle = control.Handle, 
                    SampleDescription = new SampleDescription((int)Description.MultiSampleCount, 0), 
                    SwapEffect = SwapEffect.Discard,
                    Usage = SharpDX.DXGI.Usage.BackBuffer | SharpDX.DXGI.Usage.RenderTargetOutput,
                    IsWindowed = true,
                    Flags = Description.IsFullScreen ? SwapChainFlags.AllowModeSwitch : SwapChainFlags.None, 
                };

            var newSwapChain = new SwapChain(GraphicsAdapterFactory.NativeFactory, GraphicsDevice.NativeDevice, description);
            if (Description.IsFullScreen)
            {
                // Before fullscreen switch
                newSwapChain.ResizeTarget(ref description.ModeDescription);

                // Switch to full screen
                newSwapChain.IsFullScreen = true;

                // This is really important to call ResizeBuffers AFTER switching to IsFullScreen 
                newSwapChain.ResizeBuffers(bufferCount, Description.BackBufferWidth, Description.BackBufferHeight, (SharpDX.DXGI.Format)Description.BackBufferFormat, SwapChainFlags.AllowModeSwitch);
            }

            return newSwapChain;
        }