Exemplo n.º 1
0
        public virtual void Cleanup()
        {
            Context?.ClearState();
            Context?.Flush();

            BackBuffer?.Dispose();
            BackBuffer = null;
            ZBuffer?.Dispose();
            ZBuffer = null;

            RenderTargetViewRef?.Dispose();
            RenderTargetViewRef = null;

            DepthStencilSRVRef?.Dispose();
            DepthStencilSRVRef = null;

            DepthStencilViewRef?.Dispose();
            DepthStencilViewRef = null;

            FactoryDWrite?.Dispose();
            FactoryDWrite = null;
            Factory2D?.Dispose();
            Factory2D = null;
            RenderTarget2D?.Dispose();
            RenderTarget2D = null;

            Context?.Dispose();
            DeviceRef?.Dispose();
            DeviceRef = null;
        }
Exemplo n.º 2
0
        public override void InitRenderTarget()
        {
            BackBuffer?.Dispose();
            RenderTargetViewRef?.Dispose();
            DepthStencilSRVRef?.Dispose();
            ZBuffer?.Dispose();
            DepthStencilViewRef?.Dispose();
            RenderTarget2D?.Dispose();

            SwapChainRef.ResizeBuffers(1, Width, Height, Format.R8G8B8A8_UNorm, SwapChainFlags.None);

            using (Surface surface = SwapChainRef.GetBackBuffer <Surface>(0)) {
                RenderTarget2D = new RenderTarget(Factory2D, surface, RenderTarget2DProperites);
            }

            RenderTarget2D.AntialiasMode     = AntialiasMode.PerPrimitive;
            RenderTarget2D.TextAntialiasMode = TextAntialiasMode.Cleartype;

            BackBuffer                    = SwapChainRef.GetBackBuffer <Texture2D>(0);
            BackBuffer.DebugName          = "BackBuffer";
            RenderTargetViewRef           = new RenderTargetView(DeviceRef, BackBuffer);
            RenderTargetViewRef.DebugName = "BackBufferRenderTargetView";

            ZBufferTextureDescription.Width  = Width;
            ZBufferTextureDescription.Height = Height;
            ZBuffer           = new Texture2D(DeviceRef, ZBufferTextureDescription);
            ZBuffer.DebugName = "ZBuffer";

            DepthStencilViewRef = new DepthStencilView(DeviceRef, ZBuffer, new DepthStencilViewDescription {
                Format    = Format.D32_Float,
                Dimension = MSamplesCount > 1 ? DepthStencilViewDimension.Texture2DMultisampled
                    : DepthStencilViewDimension.Texture2D,
                Flags = DepthStencilViewFlags.None,
            });
            DepthStencilViewRef.DebugName = "ZBufferDepthStencilView";

            ShaderResourceViewDescription SRVDesc = new ShaderResourceViewDescription()
            {
                Format = Format.R32_Float,
            };

            if (MSamplesCount > 1)
            {
                SRVDesc.Dimension   = ShaderResourceViewDimension.Texture2DMultisampled;
                SRVDesc.Texture2DMS = new ShaderResourceViewDescription.Texture2DMultisampledResource();
            }
            else
            {
                SRVDesc.Dimension = ShaderResourceViewDimension.Texture2D;
                SRVDesc.Texture2D = new ShaderResourceViewDescription.Texture2DResource()
                {
                    MostDetailedMip = 0,
                    MipLevels       = 1,
                };
            }

            DepthStencilSRVRef           = new ShaderResourceView(DeviceRef, ZBuffer, SRVDesc);
            DepthStencilSRVRef.DebugName = "ZBufferDepthStencilSRV";

            SetUpViewport();
            OnInitRenderTarget?.Invoke();
        }