Exemple #1
0
        void Dispose(bool fin)
        {
            if (renderingState == RenderingState.Disposed)
            {
                return;
            }

            manager.WindowDisposed(this);
            renderData.Dispose();

            if (!fin)
            {
                GC.SuppressFinalize(this);
                renderData = null;
                listener   = null;
                effects    = null;
                manager    = null;
            }

            Action <IWindow> t = onDisposing;

            if (t != null)
            {
                t(this);
            }
        }
Exemple #2
0
        public Surface() : base("UI Surface")
        {
            Resources.OnInitialize += (_, e) => {
                _device = e.GraphicsDevice;

                _size = new Size(
                    (int)_device.SwapchainFramebuffer.Width,
                    (int)_device.SwapchainFramebuffer.Height
                    );

                _sampler = _device.LinearSampler;

                ResourceLayout = e.ResourceFactory.CreateResourceLayout(
                    new ResourceLayoutDescription(
                        new ResourceLayoutElementDescription(
                            "SurfaceTexture", ResourceKind.TextureReadOnly, ShaderStages.Fragment),
                        new ResourceLayoutElementDescription(
                            "SurfaceSampler", ResourceKind.Sampler, ShaderStages.Fragment)));

                CreateTexture();
            };
            Resources.OnDispose += (_, __) => {
                _textureView.Dispose();
                _texture.Dispose();
                ResourceSet.Dispose();
            };
        }
        public void Dispose()
        {
            outputPipeline.Dispose();
            outputColorPipeline.Dispose();
            glyphPipeline.Dispose();

            textPropertiesSet.Dispose();
            textTextureSet.Dispose();
            dummyTextureSet.Dispose();

            foreach (var shader in glyphShaders)
            {
                shader.Dispose();
            }

            foreach (var shader in textShaders)
            {
                shader.Dispose();
            }

            glyphTexture.Dispose();
            glyphTextureView.Dispose();
            glyphTextureFramebuffer.Dispose();
            dummyTexture.Dispose();
            dummyTextureView.Dispose();

            glyphVertexBuffer.Dispose();
            quadVertexBuffer.Dispose();
            textVertexPropertiesBuffer.Dispose();
            textFragmentPropertiesBuffer.Dispose();
        }
Exemple #4
0
        private void Resize(RenderContext context)
        {
            var vpw = Math.Max(1, _viewport.Width);
            var vph = Math.Max(1, _viewport.Height);

            if (_bitmap != null && vpw == _width && vph == _height)
            {
                return;
            }

            _width  = vpw;
            _height = vph;

            _set?.Dispose();
            _view?.Dispose();
            _texture?.Dispose();
            _bitmap?.Dispose();

            _bitmap  = new Bitmap(_width, _height, PixelFormat.Format32bppArgb);
            _texture = context.Device.ResourceFactory.CreateTexture(TextureDescription.Texture2D(
                                                                        (uint)_width, (uint)_height, 1, 1,
                                                                        Veldrid.PixelFormat.B8_G8_R8_A8_UNorm,
                                                                        TextureUsage.Sampled
                                                                        ));
            _view = context.Device.ResourceFactory.CreateTextureView(_texture);
            _set  = context.Device.ResourceFactory.CreateResourceSet(new ResourceSetDescription(
                                                                         context.ResourceLoader.TextureLayout, _view, context.ResourceLoader.OverlaySampler
                                                                         ));
        }
        private void CreateWindowSizedResources(ResourceFactory factory)
        {
            _computeTargetTexture?.Dispose();
            _computeTargetTextureView?.Dispose();
            _computeResourceSet?.Dispose();
            _graphicsResourceSet?.Dispose();

            _computeTargetTexture = factory.CreateTexture(TextureDescription.Texture2D(
                                                              (uint)_window.Width,
                                                              (uint)_window.Height,
                                                              1,
                                                              1,
                                                              PixelFormat.R32_G32_B32_A32_Float,
                                                              TextureUsage.Sampled | TextureUsage.Storage));

            _computeTargetTextureView = factory.CreateTextureView(_computeTargetTexture);

            _computeResourceSet = factory.CreateResourceSet(new ResourceSetDescription(
                                                                _computeLayout,
                                                                _computeTargetTextureView,
                                                                _screenSizeBuffer,
                                                                _shiftBuffer));

            _graphicsResourceSet = factory.CreateResourceSet(new ResourceSetDescription(
                                                                 _graphicsLayout,
                                                                 _computeTargetTextureView,
                                                                 _computeTargetTextureView,
                                                                 _computeTargetTextureView,
                                                                 _gd.PointSampler));
        }
 private void Dispose()
 {
     graphicsPipeline.Dispose();
     graphicsSet.Dispose();
     textureView.Dispose();
     transferTexture.Dispose();
     commandList.Dispose();
 }
        protected override void OnStop()
        {
            base.OnStop();

            _videoSurface.Dispose();
            _smartGlassClient.Dispose();
            _nanoClient.Dispose();
            _mcConsumer.Dispose();
        }
Exemple #8
0
 public void Shutdown()
 {
     _currentScene?.Shutdown();
     _ui.Windows.Remove(_loadingScreen);
     _loadingScreen = null;
     _loadingTextureView.Dispose();
     _loadingTextureView = null;
     _loadingTexture.Dispose();
     _loadingTexture = null;
 }
        public void Update(ResourceLayout TexLayout, int W, int H)
        {
            if (Width != W || Height != H)
            {
                Tex?.Dispose();
                TexView?.Dispose();

                Width  = W;
                Height = H;

                TextureDescription Desc = new TextureDescription((uint)W, (uint)H, 1, 1, 1, PixelFormat.B8_G8_R8_A8_UNorm, TextureUsage.Sampled, TextureType.Texture2D);
                Tex     = Fact.CreateTexture(Desc);
                TexView = Fact.CreateTextureView(Tex);

                SamplerDescription SamplerDesc = new SamplerDescription(SamplerAddressMode.Clamp, SamplerAddressMode.Clamp, SamplerAddressMode.Clamp,
                                                                        SamplerFilter.MinPoint_MagPoint_MipPoint, null, 0, 0, 0, 0, SamplerBorderColor.OpaqueBlack);
                TexSampler = Fact.CreateSampler(SamplerDesc);
            }
        }
Exemple #10
0
        //调整其子界面的大小
        public void ResizeWindow(uint width, uint height)
        {
            lock (BitmapLock)
            {
                //触发host的resize
                _windowsHeight = height;
                _windowsWidth  = width;
                if (_host != null)
                {
                    _host.WasResized();
                }
                //同时重建渲染管线
                if (_screenPipeline != null)
                {
                    _screenPipeline.Dispose();
                }
                if (_textureView != null)
                {
                    _textureView.Dispose();
                }
                if (_texture != null)
                {
                    _texture.Dispose();
                }
                if (_screenResourceSet != null)
                {
                    _screenResourceSet.Dispose();
                }


                _texture     = _gd.ResourceFactory.CreateTexture(TextureDescription.Texture2D((uint)_windowsWidth, (uint)_windowsHeight, 1, 1, PixelFormat.B8_G8_R8_A8_UNorm, TextureUsage.Sampled));
                _textureView = _gd.ResourceFactory.CreateTextureView(_texture);

                //重建resourceSet
                _screenResourceSet = _gd.ResourceFactory.CreateResourceSet(new ResourceSetDescription(
                                                                               _screenResourceLayout,
                                                                               _textureView,
                                                                               _gd.Aniso4xSampler
                                                                               ));

                var rasterizer = RasterizerStateDescription.Default;
                rasterizer.FillMode  = PolygonFillMode.Solid;
                rasterizer.FrontFace = FrontFace.CounterClockwise;
                rasterizer.CullMode  = FaceCullMode.Front;
                _screenPipeline      = _gd.ResourceFactory.CreateGraphicsPipeline(new GraphicsPipelineDescription(
                                                                                      BlendStateDescription.SingleOverrideBlend,
                                                                                      DepthStencilStateDescription.DepthOnlyLessEqual,
                                                                                      rasterizer,
                                                                                      PrimitiveTopology.TriangleList,
                                                                                      _shaderset,
                                                                                      //共享View和prj的buffer
                                                                                      new ResourceLayout[] { _screenResourceLayout },
                                                                                      _gd.MainSwapchain.Framebuffer.OutputDescription));
            }
        }
Exemple #11
0
        public void Dispose_Texture()
        {
            Texture     t  = RF.CreateTexture(TextureDescription.Texture2D(1, 1, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.Sampled));
            TextureView tv = RF.CreateTextureView(t);

            GD.WaitForIdle(); // Required currently by Vulkan backend.
            tv.Dispose();
            Assert.True(tv.IsDisposed);
            Assert.False(t.IsDisposed);
            t.Dispose();
            Assert.True(t.IsDisposed);
        }
Exemple #12
0
        public virtual void TearDown()
        {
            for (var index = Disposables.Count - 1; index >= 0; --index)
            {
                Disposables[index].Dispose();
            }

            Disposables = null;
            CommandList?.Dispose();
            _offscreenView?.Dispose();
            Framebuffer?.Dispose();
            _offscreenDepth?.Dispose();
            _offscreenColor?.Dispose();
            GraphicsDevice?.Dispose();
        }
        public void Dispose()
        {
            _pipeline.Dispose();

            foreach (var shader in _shaders)
            {
                shader.Dispose();
            }

            _resourceSet.Dispose();
            _skeletonTexture.Dispose();
            _skeletonTextureView.Dispose();

            _vertexBuffer.Dispose();
        }
Exemple #14
0
        private void CreateTexture()
        {
            var factory = _device.ResourceFactory;

            _texture?.Dispose();
            _texture = factory.CreateTexture(TextureDescription.Texture2D(
                                                 (uint)_size.Width, (uint)_size.Height,
                                                 1, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Sampled));
            _textureView?.Dispose();
            _textureView = factory.CreateTextureView(_texture);

            ResourceSet?.Dispose();
            ResourceSet = factory.CreateResourceSet(new ResourceSetDescription(
                                                        ResourceLayout, _textureView, _sampler
                                                        ));
        }
Exemple #15
0
 public void DisposeTextures()
 {
     for (int i = 0; i < textures.Count; i++)
     {
         Texture     texture   = textures[i];
         TextureView view      = textureViews[i];
         TextureView imguiView = imguiTextureViews[i];
         view.Dispose();
         imguiView.Dispose();
         texture.Dispose();
     }
     textures.Clear();
     textureViews.Clear();
     imguiTextureViews.Clear();
     imguiTextures.Clear();
     forceRecreate = true;
 }
Exemple #16
0
        protected override void Dispose(bool disposeManagedResources)
        {
            base.Dispose(disposeManagedResources);

            if (_vertexBuffer != null && _indexBuffer != null)
            {
                _vertexBuffer.Dispose();
                _vertexBuffer = null;
                _indexBuffer.Dispose();
                _indexBuffer = null;
            }

            textureSet.Dispose();
            textureSet = null;
            textureView.Dispose();
            textureView = null;
            texture.Dispose();
            texture = null;
        }
        public bool Load(GraphicsDevice graphicsDevice, string fileName)
        {
            try
            {
                ImageSharpTexture image = new ImageSharpTexture(fileName);
                _texture    = image.CreateDeviceTexture(graphicsDevice, graphicsDevice.ResourceFactory);
                TextureView = graphicsDevice.ResourceFactory.CreateTextureView(_texture);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);

                TextureView.Dispose();
                _texture.Dispose();

                return(false);
            }

            return(true);
        }
        public void ResizeToSwapchain()
        {
            aspectWidth  = 2f / graphicsDevice.SwapchainFramebuffer.Width;
            aspectHeight = 2f / graphicsDevice.SwapchainFramebuffer.Height;

            var factory     = graphicsDevice.ResourceFactory;
            var colorFormat = PixelFormat.B8_G8_R8_A8_UNorm;

            glyphTexture?.Dispose();
            glyphTextureView?.Dispose();
            glyphTextureFramebuffer?.Dispose();
            textTextureSet.Dispose();

            glyphTexture            = factory.CreateTexture(TextureDescription.Texture2D(graphicsDevice.SwapchainFramebuffer.Width, graphicsDevice.SwapchainFramebuffer.Height, 1, 1, colorFormat, TextureUsage.RenderTarget | TextureUsage.Sampled));
            glyphTextureView        = factory.CreateTextureView(glyphTexture);
            glyphTextureFramebuffer = factory.CreateFramebuffer(new FramebufferDescription(null, glyphTexture));

            textTextureSet = factory.CreateResourceSet(new ResourceSetDescription(
                                                           textTextureLayout,
                                                           glyphTextureView,
                                                           graphicsDevice.LinearSampler));
        }
Exemple #19
0
 public void Dispose()
 {
     _deviceTexture?.Dispose();
     _textureView?.Dispose();
 }
Exemple #20
0
 public void Dispose()
 {
     Texture?.Dispose();
     TextureView?.Dispose();
 }
Exemple #21
0
 public void Dispose()
 {
     _set.Dispose();
     _view.Dispose();
     _texture.Dispose();
 }
Exemple #22
0
        public void UpdateConfigs(RenderConfig config)
        {
            Logger.AddLog("VeldridRender.UpdateConfigs");
            CheckThread();

            try
            {
                try { rubber?.Dispose(); } catch { }
                try { _textureView?.Dispose(); } catch { }
                try { textureLayout?.Dispose(); } catch { }
                try { _textureSet?.Dispose(); } catch { }

                try { _vertBuffer?.Dispose(); } catch { }
                try { _fragLightBuffer?.Dispose(); } catch { }
                try { _fragMaterialBuffer?.Dispose(); } catch { }

                try { uniformsLayout?.Dispose(); } catch { }
                try { _uniformsResourceSet?.Dispose(); } catch { }

                try { _offscreenReadOut?.Dispose(); } catch { }
                try { _offscreenFB?.Dispose(); } catch { }
                try { _offscreenColor?.Dispose(); } catch { }

                try { _pipeline?.Dispose(); } catch { }

                #region Textures
                ProcessImage tmpTexture = Helpers.ImageProcessing.PngToRgba8(new ProcessImage {
                    Load = Helpers.GetAssetByteArray("App.rubber4.png"), Type = ProcessImageType.PNG
                });
                rubber = resourceFactory.CreateTexture(TextureDescription.Texture2D((uint)tmpTexture.Width, (uint)tmpTexture.Height, 1, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Sampled));

                graphicsDevice.UpdateTexture(rubber, tmpTexture.Load, 0, 0, 0, (uint)tmpTexture.Width, (uint)tmpTexture.Height, 1, 0, 0);

                _textureView = resourceFactory.CreateTextureView(rubber);
                ResourceLayoutElementDescription[] textureLayoutDescriptions =
                {
                    new ResourceLayoutElementDescription("Tex",  ResourceKind.TextureReadOnly, ShaderStages.Fragment),
                    new ResourceLayoutElementDescription("Samp", ResourceKind.Sampler,         ShaderStages.Fragment)
                };
                textureLayout = resourceFactory.CreateResourceLayout(new ResourceLayoutDescription(textureLayoutDescriptions));
                _textureSet   = resourceFactory.CreateResourceSet(new ResourceSetDescription(textureLayout, _textureView, graphicsDevice.LinearSampler));
                #endregion

                #region Uniforms
                _vertBuffer         = resourceFactory.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer | BufferUsage.Dynamic));
                _fragLightBuffer    = resourceFactory.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer | BufferUsage.Dynamic));
                _fragMaterialBuffer = resourceFactory.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer | BufferUsage.Dynamic));

                ResourceLayoutElementDescription[] resourceLayoutElementDescriptions =
                {
                    new ResourceLayoutElementDescription("ModelViewProjection", ResourceKind.UniformBuffer, ShaderStages.Vertex),
                    new ResourceLayoutElementDescription("LightInfo",           ResourceKind.UniformBuffer, ShaderStages.Fragment),
                    new ResourceLayoutElementDescription("MaterialInfo",        ResourceKind.UniformBuffer, ShaderStages.Fragment)
                };
                uniformsLayout       = resourceFactory.CreateResourceLayout(new ResourceLayoutDescription(resourceLayoutElementDescriptions));
                _uniformsResourceSet = resourceFactory.CreateResourceSet(new ResourceSetDescription(uniformsLayout, _vertBuffer, _fragLightBuffer, _fragMaterialBuffer));
                #endregion

                var VertBufferDescription = new VertexLayoutDescription(
                    new VertexElementDescription("Position", VertexElementSemantic.Position, VertexElementFormat.Float3),
                    new VertexElementDescription("Normal", VertexElementSemantic.Normal, VertexElementFormat.Float3),
                    new VertexElementDescription("Texture", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float2));


                //Pipeline
                _offscreenReadOut = resourceFactory.CreateTexture(TextureDescription.Texture2D((uint)config.Width, (uint)config.Height, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.Staging));

                _offscreenColor = resourceFactory.CreateTexture(TextureDescription.Texture2D((uint)config.Width, (uint)config.Height, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.RenderTarget));

                _offscreenFB = resourceFactory.CreateFramebuffer(new FramebufferDescription(null, _offscreenColor));

                GraphicsPipelineDescription pipelineDescription = new GraphicsPipelineDescription()
                {
                    BlendState      = BlendStateDescription.SingleDisabled,
                    RasterizerState = new RasterizerStateDescription()
                    {
                        CullMode           = FaceCullMode.None,
                        FillMode           = PolygonFillMode.Solid,
                        FrontFace          = FrontFace.CounterClockwise,
                        DepthClipEnabled   = true,
                        ScissorTestEnabled = true
                    },
                    PrimitiveTopology = PrimitiveTopology.TriangleList,
                    ResourceLayouts   = new ResourceLayout[] { uniformsLayout, textureLayout },
                    Outputs           = _offscreenFB.OutputDescription,
                    ShaderSet         = new ShaderSetDescription()
                    {
                        Shaders       = Shaders,
                        VertexLayouts = new VertexLayoutDescription[] { VertBufferDescription }
                    },
                    ResourceBindingModel = ResourceBindingModel.Improved
                };
                _pipeline = resourceFactory.CreateGraphicsPipeline(ref pipelineDescription);


                FragLightUniforms.Lightdirection = new Vector4(Vector3.Normalize(config.LightDirection), 0);
                FragLightUniforms.Lightambient   = new Vector4(config.LightAmbient, 0);
                FragLightUniforms.Lightdiffuse   = new Vector4(config.LightDiffuse, 0);
                FragLightUniforms.Lightspecular  = new Vector4(config.LightSpecular, 0);

                FragMaterialUniforms.Materialdiffuse   = new Vector4(config.MaterialDiffuse, 0);
                FragMaterialUniforms.Materialspecular  = new Vector4(config.MaterialSpecular, 0);
                FragMaterialUniforms.Materialshininess = new Vector4(config.MaterialShininess, 0, 0, 0);

                FragMaterialUniforms.ViewDir = new Vector4(Vector3.Normalize(config.CameraPosition), 0);

                Vector3   camPos    = new Vector3(config.CameraPosition.X, config.CameraPosition.Y, config.CameraPosition.Z);
                Vector3   camLookAt = new Vector3(config.CameraLookAt.X, config.CameraLookAt.Y, config.CameraLookAt.Z);
                Matrix4x4 model     = Matrix4x4.Identity * Matrix4x4.CreateTranslation(config.ModelTranslation.X, config.ModelTranslation.Y, config.ModelTranslation.Z);
                model *= Matrix4x4.CreateFromAxisAngle(new Vector3(1.0f, 0, 0), config.ModelRotation.X)
                         * Matrix4x4.CreateFromAxisAngle(new Vector3(0, 1.0f, 0), config.ModelRotation.Y)
                         * Matrix4x4.CreateFromAxisAngle(new Vector3(0, 0, 1.0f), config.ModelRotation.Z);
                Matrix4x4 projection = Matrix4x4.CreatePerspectiveFieldOfView(DegreesToRadians(config.CameraFOV), config.Width / (float)config.Height, config.CameraNear, config.CameraFar);
                Matrix4x4 view       = Matrix4x4.CreateLookAt(camPos, camLookAt - camPos, -Vector3.UnitX);
                Matrix4x4 MVP        = model * view * projection;

                graphicsDevice.UpdateBuffer(_vertBuffer, 0, MVP);
                graphicsDevice.UpdateBuffer(_fragLightBuffer, 0, FragLightUniforms);
                graphicsDevice.UpdateBuffer(_fragMaterialBuffer, 0, FragMaterialUniforms);

                graphicsDevice.WaitForIdle();
            }
            catch (Exception ex)
            {
                Logger.AddLog(ex);
            }
        }