TextRenderer.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System.Numerics;
  2. using Veldrid;
  3. namespace TextRender
  4. {
  5. public class TextRenderer : DisposableManager
  6. {
  7. internal GraphicsDevice Device { get; private set; }
  8. internal TextShader Shader { get; private set; }
  9. internal CommandList CommandList { get; private set; }
  10. public Framebuffer Framebuffer { get=>_resource.framebuffer; }
  11. VeldridChart.VeldridResource _resource;
  12. private Pipeline _pipeline;
  13. public TextRenderer(VeldridChart.VeldridResource resource)
  14. {
  15. _resource = resource;
  16. Device = resource.Graphics;
  17. var factory = resource.Graphics.ResourceFactory;
  18. Shader = AddDisposable(new TextShader(resource));
  19. // Create pipeline
  20. var pipelineDescription = new GraphicsPipelineDescription();
  21. pipelineDescription.BlendState = BlendStateDescription.SingleAlphaBlend;
  22. pipelineDescription.DepthStencilState = new DepthStencilStateDescription(
  23. depthTestEnabled: true,
  24. depthWriteEnabled: true,
  25. comparisonKind: ComparisonKind.LessEqual);
  26. pipelineDescription.RasterizerState = new RasterizerStateDescription(
  27. cullMode: FaceCullMode.Back,
  28. fillMode: PolygonFillMode.Solid,
  29. frontFace: FrontFace.Clockwise,
  30. depthClipEnabled: true,
  31. scissorTestEnabled: false);
  32. pipelineDescription.PrimitiveTopology = PrimitiveTopology.TriangleStrip;
  33. pipelineDescription.ResourceLayouts = new[] { Shader.ProjViewLayout, Shader.TextureLayout };
  34. pipelineDescription.ShaderSet = new ShaderSetDescription(
  35. vertexLayouts: new[] { Shader.Layout },
  36. shaders: new[] { Shader.VertexShader, Shader.FragmentShader });
  37. pipelineDescription.Outputs =resource.framebuffer.OutputDescription;
  38. _pipeline = AddDisposable(factory.CreateGraphicsPipeline(pipelineDescription));
  39. CommandList = resource.CommandList;
  40. }
  41. public void BeginDraw()
  42. {
  43. //CommandList.Begin();
  44. //CommandList.SetFramebuffer(Framebuffer);
  45. //CommandList.SetFullViewports();
  46. CommandList.SetPipeline(_pipeline);
  47. CommandList.UpdateBuffer(Shader.ProjectionBuffer, 0, Matrix4x4.CreateOrthographicOffCenter(0,Framebuffer.Width, Framebuffer.Height, 0, 0, 1));
  48. }
  49. public void EndDraw()
  50. {
  51. //CommandList.End();
  52. //Device.SubmitCommands(CommandList);
  53. }
  54. }
  55. }