Beispiel #1
0
        void resize()
        {
            if (renderView == null)//first show
            {
                var dxgiFactory = device.QueryInterface <IDXGIDevice>().GetParent <IDXGIAdapter>().GetParent <IDXGIFactory>();

                var swapchainDesc = new SwapChainDescription()
                {
                    BufferCount       = 1,
                    BufferDescription = new ModeDescription(Win32Window.Width, Win32Window.Height, format),
                    IsWindowed        = true,
                    OutputWindow      = Win32Window.Handle,
                    SampleDescription = new SampleDescription(1, 0),
                    SwapEffect        = SwapEffect.Discard,
                    Usage             = Vortice.DXGI.Usage.RenderTargetOutput
                };

                swapChain = dxgiFactory.CreateSwapChain(device, swapchainDesc);
                dxgiFactory.MakeWindowAssociation(Win32Window.Handle, WindowAssociationFlags.IgnoreAll);

                backBuffer = swapChain.GetBuffer <ID3D11Texture2D>(0);
                renderView = device.CreateRenderTargetView(backBuffer);
            }
            else
            {
                renderView.Dispose();
                backBuffer.Dispose();

                swapChain.ResizeBuffers(1, Win32Window.Width, Win32Window.Height, format, SwapChainFlags.None);

                backBuffer = swapChain.GetBuffer <ID3D11Texture2D1>(0);
                renderView = device.CreateRenderTargetView(backBuffer);
            }
        }
Beispiel #2
0
        private void CreateSwapChainForDesktop()
        {
            ModeDescription BackBufferDesc = new ModeDescription()
            {
                Width       = Description.BackBufferWidth,
                Height      = Description.BackBufferHeight,
                Format      = Format.R8G8B8A8_UNorm,
                RefreshRate = new Rational()
                {
                    Numerator   = 60,
                    Denominator = 1
                },
                ScanlineOrdering = ModeScanlineOrder.Unspecified,
                Scaling          = ModeScaling.Unspecified,
            };

            SampleDescription sampleDescription = new SampleDescription()
            {
                Count   = 1,
                Quality = 0
            };

            SwapChainFlags Flags = Description.Settings.Fullscreen ? SwapChainFlags.None : SwapChainFlags.AllowModeSwitch;



            SwapChainDescription swapChainDesc = new SwapChainDescription()      // Initialize the swap chain description.
            {
                BufferCount       = bufferCount,                                 // Set to a single back buffer.
                BufferDescription = BackBufferDesc,                              // Set the width and height of the back buffer.
                Usage             = Usage.Backbuffer | Usage.RenderTargetOutput, // Set the usage of the back buffer.
                OutputWindow      = Description.DeviceHandle,                    // Set the handle for the window to render to.
                SampleDescription = sampleDescription,                           // Turn multisampling off.
                IsWindowed        = true,                                        // Set to full screen or windowed mode.
                Flags             = Flags,                                       // Don't set the advanced flags.
                SwapEffect        = SwapEffect.FlipDiscard,                      // Discard the back buffer content after presenting.
            };



            IDXGIFactory4 Factory = GraphicsDevice.NativeAdapter.NativeFactory;

            IDXGISwapChain swapChain = Factory.CreateSwapChain(GraphicsDevice.NativeDirectCommandQueue.Queue, swapChainDesc);

            if (Description.Settings.Fullscreen)
            {
                // Before fullscreen switch
                swapChain.ResizeTarget(BackBufferDesc);

                // Switch to full screen
                swapChain.SetFullscreenState(true, default);

                // This is really important to call ResizeBuffers AFTER switching to IsFullScreen
                swapChain.ResizeBuffers(3, Description.BackBufferWidth, Description.BackBufferHeight, Format.R8G8B8A8_UNorm, SwapChainFlags.AllowModeSwitch);
            }



            NativeSwapChain = swapChain.QueryInterface <IDXGISwapChain3>();
        }