/// <summary>
        /// Creates a default SwapChain for the given target control.
        /// </summary>
        /// <param name="targetControl">Target control of the swap chain.</param>
        /// <param name="device">Graphics device.</param>
        /// <param name="gfxConfig">The current graphics configuration.</param>
        internal static IDXGISwapChain1 CreateSwapChainForWinForms(WinForms.Control targetControl, EngineDevice device, GraphicsViewConfiguration gfxConfig)
        {
            targetControl.EnsureNotNull(nameof(targetControl));
            device.EnsureNotNull(nameof(device));
            gfxConfig.EnsureNotNull(nameof(gfxConfig));

            // Create the swap chain description
            var swapChainDesc = new SwapChainDescription1();

            if (gfxConfig.AntialiasingEnabled && device.IsStandardAntialiasingPossible)
            {
                swapChainDesc.BufferCount       = 2;
                swapChainDesc.SampleDescription = device.Internals.GetSampleDescription(gfxConfig.AntialiasingQuality);
            }
            else
            {
                swapChainDesc.BufferCount       = 2;
                swapChainDesc.SampleDescription = new SampleDescription(1, 0);
            }

            // Set common parameters
            swapChainDesc.Width      = targetControl.Width;
            swapChainDesc.Height     = targetControl.Height;
            swapChainDesc.Format     = GraphicsHelper.Internals.DEFAULT_TEXTURE_FORMAT;
            swapChainDesc.Scaling    = Scaling.Stretch;
            swapChainDesc.SwapEffect = SwapEffect.Discard;
            swapChainDesc.Usage      = Usage.RenderTargetOutput;

            // Create and return the swap chain and the render target
            return(device.Internals.FactoryDxgi.CreateSwapChainForHwnd(
                       device.Internals.DeviceD3D11_1, targetControl.Handle,
                       swapChainDesc));
        }
Exemplo n.º 2
0
        public static System.Windows.Forms.Form GetParentForm(this System.Windows.Forms.Control control)
        {
            control.EnsureNotNull(nameof(control));

            while (!(control is System.Windows.Forms.Form))
            {
                control = control.Parent;
                if (control == null)
                {
                    return(null);
                }
            }

            return(control as System.Windows.Forms.Form);
        }