示例#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;
        }
示例#2
0
        public void InitRenderTargetSurface(IntPtr Resource)
        {
            ZBuffer?.Dispose();
            DepthStencilViewRef?.Dispose();
            RenderTargetViewRef?.Dispose();
            RenderTarget2D?.Dispose();

            SharpDX.DXGI.Resource dxgiResource;
            using (var r = new SharpDX.ComObject(Resource)) {
                dxgiResource = r.QueryInterface <SharpDX.DXGI.Resource>();
            }

            Texture2D OutputResource = DeviceRef.OpenSharedResource <Texture2D>(dxgiResource.SharedHandle);

            using (var surface = DeviceRef.OpenSharedResource <Surface>(dxgiResource.SharedHandle)) {
                RenderTarget2D = new RenderTarget(Factory2D, surface, RenderTarget2DProperites);
            }

            //Crash everything
            //dxgiResource.Dispose();

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

            RenderTargetViewRef = new RenderTargetView(DeviceRef, OutputResource);

            Texture2DDescription OutputDesc = OutputResource.Description;

            if (OutputDesc.Width != Width || OutputDesc.Height != Height)
            {
                Width  = OutputDesc.Width;
                Height = OutputDesc.Height;
                SetUpViewport();
            }

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

            DepthStencilViewRef = new DepthStencilView(DeviceRef, ZBuffer, new DepthStencilViewDescription {
                Format    = Format.D32_Float,
                Dimension = DepthStencilViewDimension.Texture2D,
                Flags     = DepthStencilViewFlags.None,
            });

            Context.OutputMerger.SetRenderTargets(DepthStencilViewRef, RenderTargetViewRef);
            OnInitRenderTarget?.Invoke();
            OutputResource?.Dispose();
        }
示例#3
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();
        }