Exemple #1
0
        public void OnUserResized()
        {
            Console.WriteLine("OnUserResized client size {0}x{1}", control.ClientSize.Width, control.ClientSize.Height);

            if (ztex_view != null)
            {
                ztex_view.Dispose();
            }
            if (ztex != null)
            {
                ztex.Dispose();
            }

            if (buf0_view != null)
            {
                buf0_view.Dispose();
            }
            if (buf0 != null)
            {
                buf0.Dispose();
            }

            // Resize the backbuffer
            swap_chain.ResizeBuffers(1 /* desc.BufferCount */, control.ClientSize.Width, control.ClientSize.Height, SharpDX.DXGI.Format.Unknown, SharpDX.DXGI.SwapChainFlags.None);

            // Retrieve the back buffer of the swap chain.
            buf0      = Texture2D.FromSwapChain <Texture2D>(swap_chain, 0);
            buf0_view = new RenderTargetView(device, buf0);

            // Create the depth buffer
            ztex = new Texture2D(device, new Texture2DDescription()
            {
                Format            = SharpDX.DXGI.Format.D24_UNorm_S8_UInt,
                ArraySize         = 1,
                MipLevels         = 1,
                Width             = control.ClientSize.Width,
                Height            = control.ClientSize.Height,
                SampleDescription = new SharpDX.DXGI.SampleDescription(4, 0),
                Usage             = ResourceUsage.Default,
                BindFlags         = BindFlags.DepthStencil,
            });

            // Create the depth buffer view
            ztex_view = new DepthStencilView(device, ztex);

            ctx.OutputMerger.SetTargets(ztex_view, buf0_view);

            // Setup targets and viewport for rendering
            viewport = new Viewport(0, 0, control.ClientSize.Width, control.ClientSize.Height, 0.0f, 1.0f);
            ctx.Rasterizer.SetViewport(viewport);

            // Setup new projection matrix with correct aspect ratio
            Transform_Projection = Matrix.PerspectiveFovRH(
                MathUtil.DegreesToRadians(tso_config.Fov),
                (float)viewport.Width / (float)viewport.Height,
                tso_config.Znear,
                tso_config.Zfar);
        }