Exemple #1
0
        private void PostImageLoad()
        {
            uint tx = (uint)Size.X;
            uint ty = (uint)Size.Y;

            Texture = Renderer.VeldridFactory.CreateTexture(new Veldrid.TextureDescription(
                                                                tx, ty, 1,
                                                                1, 1,
                                                                Veldrid.PixelFormat.R8_G8_B8_A8_UNorm, Veldrid.TextureUsage.Sampled, Veldrid.TextureType.Texture2D));

            Veldrid.Texture StagingTexture = Renderer.VeldridFactory.CreateTexture(new Veldrid.TextureDescription(
                                                                                       tx, ty, 1,
                                                                                       1, 1,
                                                                                       Veldrid.PixelFormat.R8_G8_B8_A8_UNorm, Veldrid.TextureUsage.Staging, Veldrid.TextureType.Texture2D));

            Span <Rgba32> Pixels;

            InternalTexture.TryGetSinglePixelSpan(out Pixels);

            Span <byte> Bytes = MemoryMarshal.AsBytes(Pixels);


            //TODO: Fix this copy (Bytes.ToArray()) and use the memory directly.  UpdateTexture takes an intptr so get that
            Renderer.GraphicsDevice.UpdateTexture(StagingTexture, Bytes.ToArray(),
                                                  0, 0, 0,
                                                  tx, ty, 1,
                                                  0, 0);

            using (Veldrid.CommandList cl = Renderer.VeldridFactory.CreateCommandList())
            {
                cl.Begin();
                cl.CopyTexture(StagingTexture, Texture);
                cl.End();
                Renderer.GraphicsDevice.SubmitCommands(cl);
                Renderer.GraphicsDevice.WaitForIdle();
            }
        }