Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        private void ResizeBuffers()
        {
            // Dispose
            if (mBackBuffer != null)
            {
                mBackBuffer.Dispose();
            }
            if (mBackBufferView != null)
            {
                mBackBufferView.Dispose();
            }
            if (mRenderTarget2D != null)
            {
                mRenderTarget2D.Dispose();
            }

            // Resize swap chain
            mSwapChain.ResizeBuffers(mSwapChain.Description.BufferCount, mScreenWidth, mScreenHeight, mSwapChain.Description.ModeDescription.Format, mSwapChain.Description.Flags);

            // Re-create
            mBackBuffer     = Texture2D.FromSwapChain <Texture2D>(mSwapChain, 0);
            mBackBufferView = new RenderTargetView(mDevice, mBackBuffer);
            using (var surface = BackBuffer.QueryInterface <DXGI.Surface>())
            {
                mRenderTarget2D = new RenderTarget(mFactory2D, surface, new RenderTargetProperties(new PixelFormat(DXGI.Format.Unknown, AlphaMode.Premultiplied)));
            }
            mRenderTarget2D.AntialiasMode = AntialiasMode.PerPrimitive;
        }
Ejemplo n.º 2
0
        public void OnResize()
        {
            TextFormatFactory.DisposeItems();
            TextLayoutFactory.DisposeItems();
            ColourFactory.DisposeItems();

            var imageLoader = ImageLoader as ImageLoader;

            if (imageLoader != null)
            {
                imageLoader.DisposeAll();
            }

            Utilities.Dispose(ref backBuffer);
            Utilities.Dispose(ref backBufferView);
            Utilities.Dispose(ref renderTarget);
            Utilities.Dispose(ref factory);
            Utilities.Dispose(ref imagingFactory);

            if (swapChain != null)
            {
                swapChain.ResizeBuffers(1, Width, Height, DXGI.Format.B8G8R8A8_UNorm, DXGI.SwapChainFlags.None);
                CreateSizeDependentComponents();
            }

            children.ForEach(c => c.OnResize());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Resize backbuffer the specified width and height
        /// </summary>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <exception cref="System.Exception">
        /// </exception>
        public void Resize(int width, int height)
        {
            if (d3dDevice == null || swapChain == null || d3dContext == null)
            {
                throw new Exception(MethodBase.GetCurrentMethod().Name + "Device, DeviceContext or SwapChain is null");
            }

            if (width <= 0 || height <= 0)
            {
                throw new Exception(MethodBase.GetCurrentMethod().Name + " Width or height less than or equal to zero");
            }

            this.width  = width;
            this.height = height;

            if (d3dRenderTarget != null)
            {
                d3dContext.OutputMerger.SetRenderTargets(null, (D3D11.RenderTargetView)null);
                d3dRenderTarget.Dispose();
                d3dRenderTarget = null;
            }

            swapChain.ResizeBuffers(1,
                                    width, height,
                                    swapChain.Description.ModeDescription.Format,
                                    swapChain.Description.Flags);

            d3dRenderTarget = CreateRenderTarget();
            d3dDepthStencil = CreateDepthStencil();

            System.Diagnostics.Debug.WriteLine(MethodBase.GetCurrentMethod().Name + " Buffers resized " + width + ":" + height);

            viewport = new Viewport(0, 0, width, height);
        }
 private void ResizeBackBufferIfItExistedBefore()
 {
     if (backBuffer == null)
     {
         return;
     }
     backBuffer.Dispose();
     backBufferView.Dispose();
     surface.Dispose();
     swapChain.ResizeBuffers(SharpDXStates.BackBufferCount, Width, Height,
                             SharpDXStates.BackBufferFormat, SharpDXStates.BackBufferFlags);
 }
Ejemplo n.º 5
0
        private void ResetDeviceToNewViewportSize(Size newSizeInPixel)
        {
            backBuffer.Dispose();
            surface.Dispose();
            RenderTarget.Dispose();

            width  = (int)newSizeInPixel.Width;
            height = (int)newSizeInPixel.Height;
            swapChain.ResizeBuffers(BackBufferCount, width, height, BackBufferFormat, SwapChainFlags.None);
            backBuffer   = Resource.FromSwapChain <Texture2D>(swapChain, 0);
            surface      = backBuffer.QueryInterface <Surface>();
            RenderTarget = new RenderTarget(direct2DFactory, surface, defaultRenderTargetProperties);
            Screen       = new ScreenSpace(newSizeInPixel);
        }
Ejemplo n.º 6
0
        public void Resize()
        {
            var size = Target.ClientSize;

            mDevice.Dispose();
            mSurface.Dispose();

            mSwapChain.ResizeBuffers(1, size.Width, size.Height,
                                     mSwapChainDesc.ModeDescription.Format,
                                     mSwapChainDesc.Flags);

            mSurface = dx.Surface.FromSwapChain(mSwapChain, 0);
            mDevice  = new d2.DeviceContext(mSurface);

            mD3Device.ImmediateContext.ClearState();
            base.Resized();
        }
Ejemplo n.º 7
0
        public void Resize(int width, int height)
        {
            ResolutionX = width; ResolutionY = height;
            MainCamera.renderTargetView?.Dispose();
            MainCamera.depthStencilView?.Dispose();
            D2DTarget?.Dispose();
            D2DContext?.Dispose();

            MainCamera.AspectRatio = width / (float)height;

            swapChain.ResizeBuffers(swapChain.Description.BufferCount, width, height, DXGI.Format.Unknown, DXGI.SwapChainFlags.None);

            D2DContext = new D2D1.DeviceContext(D2DDevice, D2D1.DeviceContextOptions.None);
            using (DXGI.Surface surface = swapChain.GetBackBuffer <DXGI.Surface>(0))
                D2DTarget = new D2D1.Bitmap1(D2DContext, surface,
                                             new D2D1.BitmapProperties1(new D2D1.PixelFormat(DXGI.Format.R8G8B8A8_UNorm, D2D1.AlphaMode.Premultiplied),
                                                                        D2DFactory.DesktopDpi.Height, D2DFactory.DesktopDpi.Width, D2D1.BitmapOptions.CannotDraw | D2D1.BitmapOptions.Target)
                                             );
            D2DContext.Target = D2DTarget;

            // render target
            using (D3D11.Texture2D backBuffer = swapChain.GetBackBuffer <D3D11.Texture2D>(0))
                MainCamera.renderTargetView = new D3D11.RenderTargetView(Device, backBuffer);

            // depth buffer
            D3D11.Texture2DDescription depthDescription = new D3D11.Texture2DDescription()
            {
                Format            = DXGI.Format.D32_Float,
                ArraySize         = 1,
                MipLevels         = 1,
                Width             = width,
                Height            = height,
                SampleDescription = new DXGI.SampleDescription(SampleCount, SampleQuality),
                Usage             = D3D11.ResourceUsage.Default,
                BindFlags         = D3D11.BindFlags.DepthStencil,
                CpuAccessFlags    = D3D11.CpuAccessFlags.None,
                OptionFlags       = D3D11.ResourceOptionFlags.None
            };
            using (D3D11.Texture2D depthTexture = new D3D11.Texture2D(Device, depthDescription))
                MainCamera.depthStencilView = new D3D11.DepthStencilView(Device, depthTexture);

            // viewport
            Viewport = new Viewport(0, 0, width, height);
            Context.Rasterizer.SetViewport(Viewport);
        }
Ejemplo n.º 8
0
        private void DoResize(int width, int height)
        {
            while (Renderer.Instance.RenderingInProgress)
            {
            }
            var rt = RenderTarget.RenderTargets[0];

            rt.Clear();
            swapChain.ResizeBuffers(1, width, height, Format.Unknown, SwapChainFlags.AllowModeSwitch);
            using (var tex = Resource.FromSwapChain <Texture2D>(swapChain, 0)) {
                rt.Update(null, new RenderTargetView(Renderer.Instance.Device, tex));
                rt.SendResizeEvent();
            }
            Viewport = new Viewport(0, 0, width, height);
            OnResize?.Invoke(this, new Event.SResizeEvent {
                Size = new System.Drawing.Size(width, height)
            });
        }
Ejemplo n.º 9
0
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
            // If the form is minimized, OnResize is triggered with a client-size of (0,0).
            if (ClientSize.IsEmpty)
            {
                return;
            }
            if (_swapChain == null)
            {
                return;
            }

            CleanUpDeviceIndependentResources();
            // Resize the back buffer.
            _swapChain.ResizeBuffers(1, ClientSize.Width, ClientSize.Height, Format.B8G8R8A8_UNorm, SwapChainFlags.AllowModeSwitch);

            CreateDeviceIndependentResources();
            Invalidate();
        }
Ejemplo n.º 10
0
 public void Resize(int width, int height)
 {
     Width  = width;
     Height = height;
     chain.ResizeBuffers(bufferCount, width, height, Format.Unknown, flags);
 }