Exemple #1
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);
        }
Exemple #2
0
        public void Dispose()
        {
            foreach (KeyValuePair <string, D2D1.Brush> p in Brushes)
            {
                p.Value.Dispose();
            }
            DashStyle.Dispose();

            D2DTarget.Dispose();
            D2DDevice.Dispose();
            D2DContext.Dispose();
            D2DFactory.Dispose();

            BlackTextureView.Dispose();
            WhiteTextureView.Dispose();
            AnisotropicSampler.Dispose();

            blendStateOpaque.Dispose();
            blendStateTransparent.Dispose();

            rasterizerStateSolidCullBack.Dispose();
            rasterizerStateWireframeCullBack.Dispose();
            rasterizerStateSolidNoCull.Dispose();
            rasterizerStateWireframeNoCull.Dispose();
            depthStencilStateDefault.Dispose();
            depthStencilStateNoDepth.Dispose();

            foreach (Camera c in Cameras)
            {
                c.Dispose();
            }
            constantBuffer.Dispose();

            swapChain.Dispose();
            Device.Dispose();
            Context.Dispose();
        }