コード例 #1
0
        /// <summary>
        /// Resizes the backbuffer.
        /// </summary>
        /// <param name="width">Width of the back buffer</param>
        /// <param name="height">Height of the back buffer</param>
        public override void Resize(int width, int height)
        {
            //Do not resize if the dimensions have not changed
            if (_presentParams.BackBufferHeight == height && _presentParams.BackBufferWidth == width)
            {
                return;
            }
            _resetting = true;
            _presentParams.BackBufferWidth  = width;
            _presentParams.BackBufferHeight = height;

            //If resizing in full screen, resize the target/front buffer otherwise bad things seem to happen
            if (_isFullScreen)
            {
                DXGI.ModeDescription modeDesc = new DXGI.ModeDescription();
                modeDesc.Format      = D3D10Helper.ToD3DSurfaceFormat(_presentParams.BackBufferFormat);
                modeDesc.Width       = width;
                modeDesc.Height      = height;
                modeDesc.RefreshRate = new SDX.Rational(0, 0);
                _swapChain.ResizeTarget(modeDesc);
            }

            //Resize the swap chain back buffer
            DestroyViews();
            _swapChain.ResizeBuffers(1, width, height, D3D10Helper.ToD3DSurfaceFormat(_presentParams.BackBufferFormat), DXGI.SwapChainFlags.AllowModeSwitch);
            CreateViews();

            _resetting = false;
        }
コード例 #2
0
ファイル: DXHookD3D11.cs プロジェクト: anacrown/Afterglow
        /// <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 SlimDX.DXGI.ModeDescription 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(newTargetParameters).Code);
            }
        }
コード例 #3
0
 /// <summary>
 /// Toggles the swap chain to full screen mode.
 /// </summary>
 public override void ToggleFullScreen()
 {
     _resetting              = true;
     _isFullScreen           = !_isFullScreen;
     _swapChain.IsFullScreen = _isFullScreen;
     //Resize targets
     if (_isFullScreen)
     {
         DXGI.ModeDescription modeDesc = new DXGI.ModeDescription();
         modeDesc.Format      = D3D10Helper.ToD3DSurfaceFormat(_presentParams.BackBufferFormat);
         modeDesc.Width       = _presentParams.BackBufferWidth;
         modeDesc.Height      = _presentParams.BackBufferHeight;
         modeDesc.RefreshRate = new SDX.Rational(0, 0);
         _swapChain.ResizeTarget(modeDesc);
     }
     _resetting = false;
 }
コード例 #4
0
        private void CreateSwapChain(IntPtr windowHandle, PresentationParameters presentParams)
        {
            DXGI.Format surfaceFormat = D3D10Helper.ToD3DSurfaceFormat(presentParams.BackBufferFormat);

            switch (presentParams.PresentInterval)
            {
            case PresentInterval.Immediate:
                _interval = 0;
                break;

            case PresentInterval.One:
                _interval = 1;
                break;

            case PresentInterval.Two:
                _interval = 2;
                break;
            }

            DXGI.SampleDescription sampleDesc = new DXGI.SampleDescription(1, 0);
            bool msEnabled = false;

            if (presentParams.MultiSampleCount > 1)
            {
                sampleDesc.Count = presentParams.MultiSampleCount;
                int q = _graphicsDevice.CheckMultisampleQualityLevels(surfaceFormat, presentParams.MultiSampleCount);
                if (presentParams.MultiSampleQuality < q)
                {
                    sampleDesc.Quality = presentParams.MultiSampleQuality;
                }
                else
                {
                    sampleDesc.Quality = q - 1;
                }
                msEnabled = true;
            }

            DXGI.SwapEffect swap;
            if (presentParams.RenderTargetUsage == RenderTargetUsage.PlatformDefault)
            {
                if (msEnabled)
                {
                    swap = DXGI.SwapEffect.Discard;
                }
                else
                {
                    swap = DXGI.SwapEffect.Sequential;
                }
            }
            else if (presentParams.RenderTargetUsage == RenderTargetUsage.DiscardContents)
            {
                swap = DXGI.SwapEffect.Discard;
            }
            else
            {
                swap = DXGI.SwapEffect.Sequential;
            }
            DXGI.ModeDescription modeDesc = new DXGI.ModeDescription(presentParams.BackBufferWidth, presentParams.BackBufferHeight, new SDX.Rational(60, 1), surfaceFormat);
            modeDesc.Scaling = DXGI.DisplayModeScaling.Stretched;
            _swapChain       = new DXGI.SwapChain(_factory, _graphicsDevice, new DXGI.SwapChainDescription {
                BufferCount       = 1,
                Flags             = DXGI.SwapChainFlags.AllowModeSwitch,
                IsWindowed        = true,
                ModeDescription   = modeDesc,
                OutputHandle      = windowHandle,
                SampleDescription = sampleDesc,
                SwapEffect        = swap,
                Usage             = DXGI.Usage.RenderTargetOutput
            });

            //Add to tracker
            _renderer.Resources.AddTrackedObject(_swapChain.ComPointer, this);

            _factory.SetWindowAssociation(windowHandle, DXGI.WindowAssociationFlags.IgnoreAll | DXGI.WindowAssociationFlags.IgnoreAltEnter);
        }
コード例 #5
0
ファイル: Game.cs プロジェクト: rtshadow/miscs
        /// <summary>
        /// Basic DX10 initialization. It contains: creating a window, device, swap chain, render targets, viewPort
        /// </summary>
        private void InitializeDX()
        {
            //Initializing window
            window = new Form();
            window.ClientSize = new Size(width, height);
            window.Text = "Quinta Essentia Engine ver. 0.03";

            //Creating device and swap chain (first filling the description structures)
            modeDesc = new SlimDX.DXGI.ModeDescription();
            modeDesc.Format = DXGI.Format.R8G8B8A8_UNorm;
            modeDesc.RefreshRate = new Rational(60, 1);
            modeDesc.Scaling = DXGI.DisplayModeScaling.Unspecified;
            modeDesc.ScanlineOrdering = DXGI.DisplayModeScanlineOrdering.Unspecified;
            modeDesc.Width = width;
            modeDesc.Height = height;

            DXGI.SampleDescription sampleDesc = new SlimDX.DXGI.SampleDescription();
            sampleDesc.Count = 1;
            sampleDesc.Quality = 0;

            DXGI.SwapChainDescription swapDesc = new SlimDX.DXGI.SwapChainDescription();
            swapDesc.BufferCount = 1;
            swapDesc.IsWindowed = windowed;
            swapDesc.Flags = DXGI.SwapChainFlags.AllowModeSwitch;
            swapDesc.ModeDescription = modeDesc;
            swapDesc.OutputHandle = window.Handle;
            swapDesc.SampleDescription = sampleDesc;
            swapDesc.SwapEffect = DXGI.SwapEffect.Discard;
            swapDesc.Usage = DXGI.Usage.RenderTargetOutput;
            //DEBUG FLAG ON!!! REMEMBER THIS!
            D3D10.Device.CreateWithSwapChain(null, SlimDX.Direct3D10.DriverType.Hardware,
                SlimDX.Direct3D10.DeviceCreationFlags.Debug, swapDesc, out device, out swapChain);

            //making and setting the new viewport
            viewPort = new Viewport();
            viewPort.Height = height;
            viewPort.Width = width;
            viewPort.MaxZ = 1.0f;
            viewPort.MinZ = 0.0f;
            viewPort.X = 0;
            viewPort.Y = 0;

            device.Rasterizer.SetViewports(viewPort);

            //making main render target (it is bind with back buffer of swap chain)
            using (D3D10.Texture2D temp = swapChain.GetBuffer<D3D10.Texture2D>(0))
            {
                renderTarget = new SlimDX.Direct3D10.RenderTargetView(device, temp);
            }
            CreateDepthStencil();
            device.OutputMerger.SetTargets(depthStencilView, renderTarget);
        }
コード例 #6
0
        // Resets the graphics
        public bool resetGraphics()
        {
            // Variables
            DX3D.DeviceCreationFlags	flags=	DX3D.DeviceCreationFlags.None;

            #if DEBUG
            flag|=	DX3D.DeviceCreationFlags.Debug;
            #endif

            try
            {
                dxg.device=	new DX3D.Device(settings.driverType, flags);
            }
            catch
            {
                Wfx.MessageBox.Show("Could not initiate DirectX!");
                return false;
            }

            dxg.im=	dxg.device.ImmediateContext;
            if(dxg.device.FeatureLevel!= DX3D.FeatureLevel.Level_11_0)
            {
                Wfx.MessageBox.Show("Direct3D 11 unsupported");
                return false;
            }

            try
            {
                // Variables
                DXGI.SwapChainDescription	sd=	new DXGI.SwapChainDescription();
                DXGI.ModeDescription	md=	new DXGI.ModeDescription(game.window.widthi, game.window.heighti, settings.fps, DXGI.Format.R8G8B8A8_UNorm);

                md.ScanlineOrdering=	DXGI.DisplayModeScanlineOrdering.Unspecified;
                md.Scaling=	DXGI.DisplayModeScaling.Unspecified;
                sd.ModeDescription=	md;

                sd.SampleDescription=	((settings.bEnable4XMsaa) ?
                    new DXGI.SampleDescription(4, settings.msaa4x-1):
                    new DXGI.SampleDescription(1, 0)
                );
                sd.Usage=	DXGI.Usage.RenderTargetOutput;
                sd.BufferCount=	1;
                sd.OutputHandle=	game.window.frame.Handle;
                sd.IsWindowed=	settings.bWindowed;
                sd.SwapEffect=	DXGI.SwapEffect.Discard;
                sd.Flags=	DXGI.SwapChainFlags.None;

                dxg.swapChain=	new DXGI.SwapChain(dxg.device.Factory, dxg.device, sd);
            }
            catch
            {
                Wfx.MessageBox.Show("Could not create swap chain :(");
                return false;
            }

            return true;
        }