12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- using System.Numerics;
- using Veldrid;
- namespace TextRender
- {
- public class TextRenderer : DisposableManager
- {
- internal GraphicsDevice Device { get; private set; }
- internal TextShader Shader { get; private set; }
- internal CommandList CommandList { get; private set; }
- public Framebuffer Framebuffer { get=>_resource.framebuffer; }
- VeldridChart.VeldridResource _resource;
- private Pipeline _pipeline;
-
- public TextRenderer(VeldridChart.VeldridResource resource)
- {
- _resource = resource;
- Device = resource.Graphics;
- var factory = resource.Graphics.ResourceFactory;
- Shader = AddDisposable(new TextShader(resource));
- // Create pipeline
- var pipelineDescription = new GraphicsPipelineDescription();
- pipelineDescription.BlendState = BlendStateDescription.SingleAlphaBlend;
- pipelineDescription.DepthStencilState = new DepthStencilStateDescription(
- depthTestEnabled: true,
- depthWriteEnabled: true,
- comparisonKind: ComparisonKind.LessEqual);
- pipelineDescription.RasterizerState = new RasterizerStateDescription(
- cullMode: FaceCullMode.Back,
- fillMode: PolygonFillMode.Solid,
- frontFace: FrontFace.Clockwise,
- depthClipEnabled: true,
- scissorTestEnabled: false);
- pipelineDescription.PrimitiveTopology = PrimitiveTopology.TriangleStrip;
- pipelineDescription.ResourceLayouts = new[] { Shader.ProjViewLayout, Shader.TextureLayout };
- pipelineDescription.ShaderSet = new ShaderSetDescription(
- vertexLayouts: new[] { Shader.Layout },
- shaders: new[] { Shader.VertexShader, Shader.FragmentShader });
- pipelineDescription.Outputs =resource.framebuffer.OutputDescription;
- _pipeline = AddDisposable(factory.CreateGraphicsPipeline(pipelineDescription));
- CommandList = resource.CommandList;
- }
-
- public void BeginDraw()
- {
- //CommandList.Begin();
- //CommandList.SetFramebuffer(Framebuffer);
- //CommandList.SetFullViewports();
- CommandList.SetPipeline(_pipeline);
- CommandList.UpdateBuffer(Shader.ProjectionBuffer, 0, Matrix4x4.CreateOrthographicOffCenter(0,Framebuffer.Width, Framebuffer.Height, 0, 0, 1));
- }
-
- public void EndDraw()
- {
- //CommandList.End();
- //Device.SubmitCommands(CommandList);
- }
- }
- }
|