Exemplo n.º 1
0
        public Texture(Veldrid.GraphicsDevice graphicsDevice, TextureFormat textureFormat, DataBuffer textureBuffer)
        {
            _texture = graphicsDevice.ResourceFactory.CreateTexture(Veldrid.TextureDescription.Texture2D(textureFormat.Width, textureFormat.Height, 1, 1,
                                                                                                         Veldrid.PixelFormat.R8_G8_B8_A8_UNorm, Veldrid.TextureUsage.Sampled));

            _textureBuffer = textureBuffer;
            graphicsDevice.UpdateTexture(_texture, textureBuffer.GetIntPtr(), textureBuffer.GetSize(), 0, 0, 0, textureFormat.Width, textureFormat.Height, 1, 0, 0);
        }
Exemplo n.º 2
0
        private void CreateIndexBuffer(Veldrid.GraphicsDevice graphicsDevice)
        {
            ushort[] quadIndices = { 0, 1, 2, 3 };

            _indexBuffer = graphicsDevice.ResourceFactory.CreateBuffer(new Veldrid.BufferDescription(
                (uint)(quadIndices.Length * sizeof(ushort)),
                Veldrid.BufferUsage.IndexBuffer
            ));
            graphicsDevice.UpdateBuffer(_indexBuffer, 0, quadIndices);
        }
Exemplo n.º 3
0
        private void CreateResourceSet(Veldrid.GraphicsDevice graphicsDevice)
        {
            _resourceLayout = graphicsDevice.ResourceFactory.CreateResourceLayout(new Veldrid.ResourceLayoutDescription(
                    new Veldrid.ResourceLayoutElementDescription("ImageTexture", Veldrid.ResourceKind.TextureReadOnly, Veldrid.ShaderStages.Fragment),
                    new Veldrid.ResourceLayoutElementDescription("ImageSampler", Veldrid.ResourceKind.Sampler, Veldrid.ShaderStages.Fragment)
            ));

            _textureView = graphicsDevice.ResourceFactory.CreateTextureView(_texture);
            _resourceSet = graphicsDevice.ResourceFactory.CreateResourceSet(new Veldrid.ResourceSetDescription(
                _resourceLayout,
                _textureView,
                graphicsDevice.PointSampler
            ));
        }
Exemplo n.º 4
0
        private void CreateVertexBuffer(Veldrid.GraphicsDevice graphicsDevice)
        {
            ImageVertex[] quadVertices =
            {
                new ImageVertex(new Vector2(-1f, 1f), new Vector2(0,0)),
                new ImageVertex(new Vector2(1f, 1f), new Vector2(1,0)),
                new ImageVertex(new Vector2(-1f, -1f), new Vector2(0,1)),
                new ImageVertex(new Vector2(1f, -1f), new Vector2(1,1))
            };

            _vertexBuffer = graphicsDevice.ResourceFactory.CreateBuffer(new Veldrid.BufferDescription(
                (uint)(quadVertices.Length * Marshal.SizeOf(new ImageVertex())),
                Veldrid.BufferUsage.VertexBuffer
            ));
            graphicsDevice.UpdateBuffer(_vertexBuffer, 0, quadVertices);
        }
Exemplo n.º 5
0
        private void CreateShaders(Veldrid.GraphicsDevice graphicsDevice)
        {
            var vertexShader = new Veldrid.ShaderDescription(
                Veldrid.ShaderStages.Vertex,
                Encoding.UTF8.GetBytes(VertexShader),
                "main"
            );

            var fragmentShader = new Veldrid.ShaderDescription(
                Veldrid.ShaderStages.Fragment,
                Encoding.UTF8.GetBytes(FragmentShader),
                "main"
            );

            _shaders = graphicsDevice.ResourceFactory.CreateFromSpirv(vertexShader, fragmentShader);
        }
Exemplo n.º 6
0
        protected override void CreateWindow_Internal()
        {
            TickFunction WindowTick = new TickFunction
            {
                TickFunc = (DeltaTime) => {
                    var Snapshot = Window.PumpEvents();
                    VeldridInputSource.LastInputSnapshot(Snapshot);
                },
                TickPriority = TickFunction.HighPriority,
                CanTick      = true,
            };

            IEngine.Instance.GameThreadTickManager.AddTick(WindowTick);

            Veldrid.StartupUtilities.WindowCreateInfo windowCI = new Veldrid.StartupUtilities.WindowCreateInfo
            {
                X                  = 100,
                Y                  = 100,
                WindowWidth        = (int)ScreenSize.X,
                WindowHeight       = (int)ScreenSize.Y,
                WindowInitialState = Veldrid.WindowState.Normal,
                WindowTitle        = "Intro",
            };

            Window               = VeldridStartup.CreateWindow(ref windowCI);
            Window.KeyDown      += VeldridInputSource.OnWindowKeyEvent;
            Window.KeyUp        += VeldridInputSource.OnWindowKeyEvent;
            Window.MouseDown    += VeldridInputSource.OnWindowMouseEvent;
            Window.MouseUp      += VeldridInputSource.OnWindowMouseEvent;
            Window.Resized      += Window_Resized;
            Window.Closing      += Window_Closing;
            Window.Closed       += Window_Closed;
            Window.LimitPollRate = true;


            Veldrid.GraphicsDeviceOptions options = new Veldrid.GraphicsDeviceOptions()
            {
                PreferStandardClipSpaceYDirection = true,
                Debug = false,
            };

            GraphicsDevice = VeldridStartup.CreateVulkanGraphicsDevice(options, Window);


            ConstructVeldridResources();
        }
Exemplo n.º 7
0
        public Image(Veldrid.GraphicsDevice graphicsDevice, TextureFormat textureFormat, DataBuffer textureBuffer)
        {
            // Perhaps create this somewhere else...?
            // Texture begin
            _texture = graphicsDevice.ResourceFactory.CreateTexture(Veldrid.TextureDescription.Texture2D(textureFormat.Width, textureFormat.Height, 1, 1,
                        Veldrid.PixelFormat.R8_G8_B8_A8_UNorm, Veldrid.TextureUsage.Sampled));

            _textureBuffer = textureBuffer;
            graphicsDevice.UpdateTexture(_texture, textureBuffer.GetIntPtr(), textureBuffer.GetSize(), 0, 0, 0, textureFormat.Width, textureFormat.Height, 1, 0, 0);
            // Texture end

            CreateVertexBuffer(graphicsDevice);
            CreateIndexBuffer(graphicsDevice);
            CreateResourceSet(graphicsDevice);
            CreateShaders(graphicsDevice);
            CreatePipeline(graphicsDevice);
        }
Exemplo n.º 8
0
        private void CreatePipeline(Veldrid.GraphicsDevice graphicsDevice)
        {
            var vertexLayout = new Veldrid.VertexLayoutDescription(
                new Veldrid.VertexElementDescription("Position", Veldrid.VertexElementSemantic.TextureCoordinate, Veldrid.VertexElementFormat.Float2),
                new Veldrid.VertexElementDescription("TextureCoordinates", Veldrid.VertexElementSemantic.TextureCoordinate, Veldrid.VertexElementFormat.Float2)
            );

            _pipeline = graphicsDevice.ResourceFactory.CreateGraphicsPipeline(new Veldrid.GraphicsPipelineDescription
            {
                BlendState = Veldrid.BlendStateDescription.SingleDisabled,
                DepthStencilState = Veldrid.DepthStencilStateDescription.Disabled,
                RasterizerState = Veldrid.RasterizerStateDescription.CullNone,
                PrimitiveTopology = Veldrid.PrimitiveTopology.TriangleStrip,
                ResourceLayouts = new Veldrid.ResourceLayout[] { _resourceLayout },
                ShaderSet = new Veldrid.ShaderSetDescription(
                    vertexLayouts: new Veldrid.VertexLayoutDescription[] { vertexLayout },
                    shaders: _shaders
                ),
                Outputs = graphicsDevice.SwapchainFramebuffer.OutputDescription
            });
        }