public virtual void DestroyDeviceObjects()
 {
     ProjectionMatrixBuffer.Dispose();
     ViewMatrixBuffer.Dispose();
     LightInfoBuffer.Dispose();
     LightViewProjectionBuffer0.Dispose();
     LightViewProjectionBuffer1.Dispose();
     LightViewProjectionBuffer2.Dispose();
     DepthLimitsBuffer.Dispose();
     CameraInfoBuffer.Dispose();
     PointLightsBuffer.Dispose();
     MainSceneColorTexture.Dispose();
     MainSceneResolvedColorTexture.Dispose();
     MainSceneResolvedColorView.Dispose();
     MainSceneDepthTexture.Dispose();
     MainSceneFramebuffer.Dispose();
     MainSceneViewResourceSet.Dispose();
     DuplicatorTarget0.Dispose();
     DuplicatorTarget1.Dispose();
     DuplicatorTargetView0.Dispose();
     DuplicatorTargetView1.Dispose();
     DuplicatorTargetSet0.Dispose();
     DuplicatorTargetSet1.Dispose();
     DuplicatorFramebuffer.Dispose();
     TextureSamplerResourceLayout.Dispose();
     ReflectionColorTexture.Dispose();
     ReflectionDepthTexture.Dispose();
     ReflectionColorView.Dispose();
     ReflectionFramebuffer.Dispose();
     ReflectionViewProjBuffer.Dispose();
     MirrorClipPlaneBuffer.Dispose();
     NoClipPlaneBuffer.Dispose();
     ShadowMaps.DestroyDeviceObjects();
 }
 public virtual void DisposeGraphicsDeviceObjects()
 {
     CameraInfoBuffer.Dispose();
     MainSceneColorTexture.Dispose();
     MainSceneResolvedColorTexture.Dispose();
     MainSceneResolvedColorView.Dispose();
     MainSceneDepthTexture.Dispose();
     MainSceneFramebuffer.Dispose();
     MainSceneViewResourceSet.Dispose();
     DuplicatorTarget0.Dispose();
     DuplicatorTarget1.Dispose();
     DuplicatorTargetView0.Dispose();
     DuplicatorTargetView1.Dispose();
     DuplicatorTargetSet0.Dispose();
     DuplicatorTargetSet1.Dispose();
     DuplicatorFramebuffer.Dispose();
     TextureSamplerResourceLayout.Dispose();
 }
        internal void RecreateWindowSizedResources(GraphicsDevice gd, CommandList cl)
        {
            MainSceneColorTexture?.Dispose();
            MainSceneDepthTexture?.Dispose();
            MainSceneResolvedColorTexture?.Dispose();
            MainSceneResolvedColorView?.Dispose();
            MainSceneViewResourceSet?.Dispose();
            MainSceneFramebuffer?.Dispose();
            DuplicatorTarget0?.Dispose();
            DuplicatorTarget1?.Dispose();
            DuplicatorTargetView0?.Dispose();
            DuplicatorTargetView1?.Dispose();
            DuplicatorTargetSet0?.Dispose();
            DuplicatorTargetSet1?.Dispose();
            DuplicatorFramebuffer?.Dispose();

            ResourceFactory factory = gd.ResourceFactory;

            TextureSampleCount mainSceneSampleCountCapped = (TextureSampleCount)Math.Min(
                (int)gd.GetSampleCountLimit(PixelFormat.R8_G8_B8_A8_UNorm, false),
                (int)MainSceneSampleCount);

            TextureDescription mainColorDesc = TextureDescription.Texture2D(
                gd.SwapchainFramebuffer.Width,
                gd.SwapchainFramebuffer.Height,
                1,
                1,
                PixelFormat.R8_G8_B8_A8_UNorm,
                TextureUsage.RenderTarget | TextureUsage.Sampled,
                mainSceneSampleCountCapped);

            MainSceneColorTexture = factory.CreateTexture(ref mainColorDesc);
            if (mainSceneSampleCountCapped != TextureSampleCount.Count1)
            {
                mainColorDesc.SampleCount     = TextureSampleCount.Count1;
                MainSceneResolvedColorTexture = factory.CreateTexture(ref mainColorDesc);
            }
            else
            {
                MainSceneResolvedColorTexture = MainSceneColorTexture;
            }
            MainSceneResolvedColorView = factory.CreateTextureView(MainSceneResolvedColorTexture);
            MainSceneDepthTexture      = factory.CreateTexture(TextureDescription.Texture2D(
                                                                   gd.SwapchainFramebuffer.Width,
                                                                   gd.SwapchainFramebuffer.Height,
                                                                   1,
                                                                   1,
                                                                   PixelFormat.R16_UNorm,
                                                                   TextureUsage.DepthStencil,
                                                                   mainSceneSampleCountCapped));
            MainSceneFramebuffer     = factory.CreateFramebuffer(new FramebufferDescription(MainSceneDepthTexture, MainSceneColorTexture));
            MainSceneViewResourceSet = factory.CreateResourceSet(new ResourceSetDescription(TextureSamplerResourceLayout, MainSceneResolvedColorView, gd.PointSampler));

            TextureDescription colorTargetDesc = TextureDescription.Texture2D(
                gd.SwapchainFramebuffer.Width,
                gd.SwapchainFramebuffer.Height,
                1,
                1,
                PixelFormat.R8_G8_B8_A8_UNorm,
                TextureUsage.RenderTarget | TextureUsage.Sampled);

            DuplicatorTarget0     = factory.CreateTexture(ref colorTargetDesc);
            DuplicatorTargetView0 = factory.CreateTextureView(DuplicatorTarget0);
            DuplicatorTarget1     = factory.CreateTexture(ref colorTargetDesc);
            DuplicatorTargetView1 = factory.CreateTextureView(DuplicatorTarget1);
            DuplicatorTargetSet0  = factory.CreateResourceSet(new ResourceSetDescription(TextureSamplerResourceLayout, DuplicatorTargetView0, gd.PointSampler));
            DuplicatorTargetSet1  = factory.CreateResourceSet(new ResourceSetDescription(TextureSamplerResourceLayout, DuplicatorTargetView1, gd.PointSampler));

            FramebufferDescription fbDesc = new FramebufferDescription(null, DuplicatorTarget0, DuplicatorTarget1);

            DuplicatorFramebuffer = factory.CreateFramebuffer(ref fbDesc);
        }
示例#4
0
        internal void RecreateWindowSizedResources(GraphicsDevice gd, CommandList cl)
        {
            MainSceneColorTexture?.Dispose();
            MainSceneDepthTexture?.Dispose();
            MainSceneResolvedColorTexture?.Dispose();
            MainSceneResolvedColorView?.Dispose();
            MainSceneViewResourceSet?.Dispose();
            MainSceneFramebuffer?.Dispose();
            DuplicatorTarget0?.Dispose();
            DuplicatorTarget1?.Dispose();
            DuplicatorTargetView0?.Dispose();
            DuplicatorTargetView1?.Dispose();
            DuplicatorTargetSet0?.Dispose();
            DuplicatorTargetSet1?.Dispose();
            DuplicatorFramebuffer?.Dispose();

            ResourceFactory factory = gd.ResourceFactory;

            gd.GetPixelFormatSupport(
                PixelFormat.R8_G8_B8_A8_UNorm,
                TextureType.Texture2D,
                TextureUsage.RenderTarget,
                out PixelFormatProperties properties);

            TextureSampleCount sampleCount = MainSceneSampleCount;

            while (!properties.IsSampleCountSupported(sampleCount))
            {
                sampleCount = (TextureSampleCount)(sampleCount - 1);
            }

            TextureDescription mainColorDesc = TextureDescription.Texture2D(
                gd.SwapchainFramebuffer.Width,
                gd.SwapchainFramebuffer.Height,
                1,
                1,
                PixelFormat.R8_G8_B8_A8_UNorm,
                TextureUsage.RenderTarget | TextureUsage.Sampled,
                sampleCount);

            MainSceneColorTexture = factory.CreateTexture(ref mainColorDesc);
            if (sampleCount != TextureSampleCount.Count1)
            {
                mainColorDesc.SampleCount     = TextureSampleCount.Count1;
                MainSceneResolvedColorTexture = factory.CreateTexture(ref mainColorDesc);
            }
            else
            {
                MainSceneResolvedColorTexture = MainSceneColorTexture;
            }
            MainSceneResolvedColorView = factory.CreateTextureView(MainSceneResolvedColorTexture);
            MainSceneDepthTexture      = factory.CreateTexture(TextureDescription.Texture2D(
                                                                   gd.SwapchainFramebuffer.Width,
                                                                   gd.SwapchainFramebuffer.Height,
                                                                   1,
                                                                   1,
                                                                   PixelFormat.R32_Float,
                                                                   TextureUsage.DepthStencil,
                                                                   sampleCount));
            MainSceneFramebuffer     = factory.CreateFramebuffer(new FramebufferDescription(MainSceneDepthTexture, MainSceneColorTexture));
            MainSceneViewResourceSet = factory.CreateResourceSet(new ResourceSetDescription(TextureSamplerResourceLayout, MainSceneResolvedColorView, gd.PointSampler));

            TextureDescription colorTargetDesc = TextureDescription.Texture2D(
                gd.SwapchainFramebuffer.Width,
                gd.SwapchainFramebuffer.Height,
                1,
                1,
                PixelFormat.R8_G8_B8_A8_UNorm,
                TextureUsage.RenderTarget | TextureUsage.Sampled);

            DuplicatorTarget0     = factory.CreateTexture(ref colorTargetDesc);
            DuplicatorTargetView0 = factory.CreateTextureView(DuplicatorTarget0);
            DuplicatorTarget1     = factory.CreateTexture(ref colorTargetDesc);
            DuplicatorTargetView1 = factory.CreateTextureView(DuplicatorTarget1);
            DuplicatorTargetSet0  = factory.CreateResourceSet(new ResourceSetDescription(TextureSamplerResourceLayout, DuplicatorTargetView0, gd.PointSampler));
            DuplicatorTargetSet1  = factory.CreateResourceSet(new ResourceSetDescription(TextureSamplerResourceLayout, DuplicatorTargetView1, gd.PointSampler));

            FramebufferDescription fbDesc = new FramebufferDescription(null, DuplicatorTarget0, DuplicatorTarget1);

            DuplicatorFramebuffer = factory.CreateFramebuffer(ref fbDesc);
        }