Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GorgonSwapChain"/> class.
        /// </summary>
        /// <param name="graphics">Graphics interface that owns this swap chain.</param>
        /// <param name="name">The name of the swap chain.</param>
        /// <param name="settings">Settings for the swap chain.</param>
        internal GorgonSwapChain(GorgonGraphics graphics, string name, GorgonSwapChainSettings settings)
            : base(name)
        {
            Graphics = graphics;
            Settings = settings;

            // Get the parent form for our window.
            _parentForm      = Gorgon.GetTopLevelForm(settings.Window);
            _topLevelControl = Gorgon.GetTopLevelControl(settings.Window);
            settings.Window.ParentChanged += Window_ParentChanged;

            if (_topLevelControl != settings.Window)
            {
                _topLevelControl.ParentChanged += Window_ParentChanged;
            }

            AutoResize = true;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Function to intialize the swap chain.
        /// </summary>
        internal void Initialize()
        {
            var D3DSettings = new GI.SwapChainDescription();

            // Resize the window to match requested mode size.
            if ((_parentForm == Settings.Window) && (Settings.IsWindowed) && (!Settings.NoClientResize))
            {
                _parentForm.ClientSize = new Size(Settings.VideoMode.Width, Settings.VideoMode.Height);
            }

            AutoResize = !Settings.NoClientResize;
            Graphics.GetFullScreenSwapChains();
            D3DSettings.BufferCount = Settings.BufferCount;
            D3DSettings.Flags       = GI.SwapChainFlags.AllowModeSwitch;

            D3DSettings.IsWindowed        = true;
            D3DSettings.ModeDescription   = GorgonVideoMode.Convert(Settings.VideoMode);
            D3DSettings.OutputHandle      = Settings.Window.Handle;
            D3DSettings.SampleDescription = GorgonMultisampling.Convert(Settings.Multisampling);
            D3DSettings.SwapEffect        = GorgonSwapChainSettings.Convert(Settings.SwapEffect);

            if ((Settings.Flags & SwapChainUsageFlags.RenderTarget) == SwapChainUsageFlags.RenderTarget)
            {
                D3DSettings.Usage = GI.Usage.RenderTargetOutput;
            }

            if ((Settings.Flags & SwapChainUsageFlags.AllowShaderView) == SwapChainUsageFlags.AllowShaderView)
            {
                D3DSettings.Usage |= GI.Usage.ShaderInput;
            }

            if ((Settings.Flags & SwapChainUsageFlags.AllowUnorderedAccessView) == SwapChainUsageFlags.AllowUnorderedAccessView)
            {
                D3DSettings.Usage |= GI.Usage.UnorderedAccess;
            }

            Gorgon.Log.Print("GorgonSwapChain '{0}': Creating D3D11 swap chain...", LoggingLevel.Simple, Name);
            GISwapChain = new GI.SwapChain(Graphics.GIFactory, Graphics.D3DDevice, D3DSettings)
            {
                DebugName = Name + " DXGISwapChain"
            };

            // Due to an issue with winforms and DXGI, we have to manually handle transitions ourselves.
            Graphics.GIFactory.MakeWindowAssociation(Settings.Window.Handle, GI.WindowAssociationFlags.IgnoreAll);

            CreateResources();

            if (!Settings.IsWindowed)
            {
                ModeStateUpdate();
            }

            Settings.Window.Resize += Window_Resize;

            if (_parentForm == null)
            {
                return;
            }

            _parentForm.ResizeBegin += _parentForm_ResizeBegin;
            _parentForm.ResizeEnd   += _parentForm_ResizeEnd;
        }