TextShader.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using Veldrid;
  3. namespace TextRender
  4. {
  5. public class TextShader : ShaderAbstract
  6. {
  7. public DeviceBuffer ProjectionBuffer;
  8. public DeviceBuffer WorldBuffer;
  9. public ResourceLayout ProjViewLayout;
  10. public ResourceLayout TextureLayout;
  11. public ResourceSet ProjViewSet;
  12. public TextShader(VeldridChart.VeldridResource resource) : base(resource, "Text")
  13. {
  14. Layout = new VertexLayoutDescription(
  15. new VertexElementDescription("Position", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float2),
  16. new VertexElementDescription("TexCoords", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float2),
  17. new VertexElementDescription("Color", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float4));
  18. ProjectionBuffer = resource.Graphics.ResourceFactory.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer));
  19. WorldBuffer = resource.Graphics.ResourceFactory.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer));
  20. ProjViewLayout = resource.Graphics.ResourceFactory.CreateResourceLayout(
  21. new ResourceLayoutDescription(
  22. new ResourceLayoutElementDescription("Projection", ResourceKind.UniformBuffer, ShaderStages.Vertex),
  23. new ResourceLayoutElementDescription("World", ResourceKind.UniformBuffer, ShaderStages.Vertex))
  24. );
  25. TextureLayout = resource.Graphics.ResourceFactory.CreateResourceLayout(
  26. new ResourceLayoutDescription(
  27. new ResourceLayoutElementDescription("SourceTexture", ResourceKind.TextureReadOnly, ShaderStages.Fragment),
  28. new ResourceLayoutElementDescription("SourceSampler", ResourceKind.Sampler, ShaderStages.Fragment)));
  29. ProjViewSet = resource.Graphics.ResourceFactory.CreateResourceSet(new ResourceSetDescription(
  30. ProjViewLayout,
  31. ProjectionBuffer,
  32. WorldBuffer));
  33. }
  34. public void UpdateBuffers()
  35. {
  36. }
  37. public override void Dispose()
  38. {
  39. base.Dispose();
  40. ProjectionBuffer.Dispose();
  41. WorldBuffer.Dispose();
  42. TextureLayout.Dispose();
  43. ProjViewLayout.Dispose();
  44. ProjViewSet.Dispose();
  45. }
  46. }
  47. }