Exemplo n.º 1
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>();
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PresentationParameters" /> class with default values.
 /// </summary>
 public PresentationParameters()
 {
     BackBufferWidth      = 800;
     BackBufferHeight     = 480;
     BackBufferFormat     = PixelFormat.R8G8B8A8.UNorm;
     PresentationInterval = PresentInterval.Immediate;
     DepthStencilFormat   = DepthFormat.Depth24Stencil8;
     MultiSampleCount     = MSAALevel.None;
     IsFullScreen         = false;
     RefreshRate          = new Rational(60, 1); // by default
     RenderTargetUsage    = Usage.BackBuffer | Usage.RenderTargetOutput;
     Flags = SwapChainFlags.AllowModeSwitch;
 }
Exemplo n.º 3
0
        void ResizeDXGIBuffers(int width, int height, bool fullscreen)
        {
            SwapChainDescription scd = CurrentSettings.Direct3D10.SwapChainDescription;

            scd.IsWindowed = !fullscreen;
            CurrentSettings.Direct3D10.SwapChainDescription = scd;

            if (Direct3D10.DepthStencil != null)
            {
                Direct3D10.DepthStencil.Dispose();
                Direct3D10.DepthStencil = null;
                Direct3D10.DepthStencilView.Dispose();
                Direct3D10.DepthStencilView = null;

                Direct3D10.RasterizerState.Dispose();
                Direct3D10.RasterizerState = null;
            }

            Direct3D10.RenderTarget.Dispose();
            Direct3D10.RenderTarget = null;

            SwapChainFlags flag = SwapChainFlags.None;

            if (fullscreen)
            {
                flag = SwapChainFlags.AllowModeSwitch;
            }

            Direct3D10.SwapChain.ResizeBuffers(CurrentSettings.Direct3D10.SwapChainDescription.BufferCount, width, height,
                                               CurrentSettings.Direct3D10.SwapChainDescription.ModeDescription.Format, flag);

            if (!doNotStoreBufferSize)
            {
                ModeDescription md = scd.ModeDescription;
                md.Width            = game.Window.ClientSize.Width;
                md.Height           = game.Window.ClientSize.Height;
                scd.ModeDescription = md;
                CurrentSettings.Direct3D10.SwapChainDescription = scd;
            }

            SetupD3D10Views();
        }
 /// <summary>
 /// Create new instance of <see cref="SwapChainDescription1"/> struct.
 /// </summary>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="format"></param>
 /// <param name="stereo"></param>
 /// <param name="usage"></param>
 /// <param name="bufferCount"></param>
 /// <param name="scaling"></param>
 /// <param name="swapEffect"></param>
 /// <param name="alphaMode"></param>
 /// <param name="flags"></param>
 public SwapChainDescription1(
     int width,
     int height,
     Format format         = Format.B8G8R8A8_UNorm,
     bool stereo           = false,
     Usage usage           = Usage.RenderTargetOutput,
     int bufferCount       = 2,
     Scaling scaling       = Scaling.None,
     SwapEffect swapEffect = SwapEffect.FlipDiscard,
     AlphaMode alphaMode   = AlphaMode.Unspecified,
     SwapChainFlags flags  = SwapChainFlags.None)
 {
     Width             = width;
     Height            = height;
     Format            = format;
     Stereo            = stereo;
     SampleDescription = new SampleDescription(1, 0);
     Usage             = usage;
     BufferCount       = bufferCount;
     Scaling           = scaling;
     SwapEffect        = swapEffect;
     AlphaMode         = alphaMode;
     Flags             = flags;
 }
Exemplo n.º 5
0
 public void ResizeBuffers(int bufferCount, int width, int height, DxgiFormat newFormat, SwapChainFlags swapChainFlags)
 {
     base.innerRefT.ResizeBuffers(bufferCount, width, height, newFormat, swapChainFlags);
 }
Exemplo n.º 6
0
 public Result ResizeBuffers1(int bufferCount, int width, int height, Format format = Format.Unknown, SwapChainFlags swapChainFlags = SwapChainFlags.None)
 {
     return(ResizeBuffers1(bufferCount, width, height, format, swapChainFlags, null, null));
 }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PresentationParameters" /> class with default values.
 /// </summary>
 public PresentationParameters()
 {
     BackBufferWidth = 800;
     BackBufferHeight = 480;
     BackBufferFormat = PixelFormat.R8G8B8A8.UNorm;
     PresentationInterval = PresentInterval.Immediate;
     DepthStencilFormat = DepthFormat.Depth24Stencil8;
     MultiSampleCount = MSAALevel.None;
     IsFullScreen = false;
     RefreshRate = new Rational(60, 1); // by default
     RenderTargetUsage = Usage.BackBuffer | Usage.RenderTargetOutput;
     Flags = SwapChainFlags.None;
 }
        public SwapChainDescription CreateSwapChain(int PBufferCount, Usage PUsage, IntPtr PFormHandle, bool PIsWindowed, int PModeDescriptionWidth, int PModeDescriptionHeight, Rational PModeDescriptionRefreshRate, Format PModeDescriptionFormat, int PSampleDescriptionCount, int PSampleDescriptionQuality, SwapChainFlags PSwapChainFlags, SwapEffect PSwapEffect)
        {
            this._BufferCount                = PBufferCount;
            this._Usage                      = PUsage;
            this._FormHandle                 = PFormHandle;
            this._IsWindowed                 = PIsWindowed;
            this._ModeDescriptionWidth       = PModeDescriptionWidth;
            this._ModeDescriptionHeight      = PModeDescriptionHeight;
            this._ModeDescriptionRefreshRate = PModeDescriptionRefreshRate;
            this._ModeDescriptionFormat      = PModeDescriptionFormat;
            this._SampleDescriptionCount     = PSampleDescriptionCount;
            this._SampleDescriptionQuality   = PSampleDescriptionQuality;
            this._SwapChainFlags             = PSwapChainFlags;
            this._SwapEffect                 = PSwapEffect;
            _SampleDescription               = new SampleDescription(_SampleDescriptionCount, _SampleDescriptionQuality);
            _ModeDescription                 = new ModeDescription(_ModeDescriptionWidth, _ModeDescriptionHeight, _ModeDescriptionRefreshRate, _ModeDescriptionFormat);
            _SwapChainDesc                   = new SwapChainDescription()
            {
                BufferCount       = _BufferCount,
                Usage             = _Usage,
                OutputHandle      = _FormHandle,
                IsWindowed        = _IsWindowed,
                ModeDescription   = _ModeDescription,
                SampleDescription = _SampleDescription,
                Flags             = _SwapChainFlags,
                SwapEffect        = _SwapEffect
            };

            return(_SwapChainDesc);
        }
Exemplo n.º 9
0
 private int ResizeBuffers(IntPtr swapChainPtr, int bufferCount, int width, int height, Format newFormat, SwapChainFlags swapChainFlags)
 {
     var swapChain = (SwapChain) swapChainPtr;
     try
     {
         CleanupRenderer();
     }
     catch (Exception ex)
     {
         Log.Write("Failed resizeBuffers: {0}", ex.Message);
     }
     finally
     {
         swapChain.ResizeBuffers(bufferCount, width, height, newFormat, swapChainFlags);
     }
     return Result.Ok.Code;
 }
Exemplo n.º 10
0
        public SwapChainDescription CreateSwapChain(int PBufferCount, Usage PUsage, IntPtr PFormHandle, bool PIsWindowed, int PModeDescriptionWidth, int PModeDescriptionHeight, Rational PModeDescriptionRefreshRate, Format PModeDescriptionFormat, int PSampleDescriptionCount, int PSampleDescriptionQuality, SwapChainFlags PSwapChainFlags, SwapEffect PSwapEffect)
        {
            this._BufferCount = PBufferCount;
            this._Usage = PUsage;
            this._FormHandle = PFormHandle;
            this._IsWindowed = PIsWindowed;
            this._ModeDescriptionWidth = PModeDescriptionWidth;
            this._ModeDescriptionHeight = PModeDescriptionHeight;
            this._ModeDescriptionRefreshRate = PModeDescriptionRefreshRate;
            this._ModeDescriptionFormat = PModeDescriptionFormat;
            this._SampleDescriptionCount = PSampleDescriptionCount;
            this._SampleDescriptionQuality = PSampleDescriptionQuality;
            this._SwapChainFlags = PSwapChainFlags;
            this._SwapEffect = PSwapEffect;
            _SampleDescription = new SampleDescription(_SampleDescriptionCount, _SampleDescriptionQuality);
            _ModeDescription = new ModeDescription(_ModeDescriptionWidth, _ModeDescriptionHeight, _ModeDescriptionRefreshRate, _ModeDescriptionFormat);
            _SwapChainDesc = new SwapChainDescription() {
                BufferCount = _BufferCount,
                Usage=_Usage,
                OutputHandle=_FormHandle,
                IsWindowed=_IsWindowed,
                ModeDescription=_ModeDescription,
                SampleDescription=_SampleDescription,
                Flags=_SwapChainFlags,
                SwapEffect=_SwapEffect };

            return _SwapChainDesc;
        }