diff --git a/Dashboard.Common/Drawing/DrawCall.cs b/Dashboard.Common/Drawing/DrawCall.cs index 7eabfeb..87c4fd9 100644 --- a/Dashboard.Common/Drawing/DrawCall.cs +++ b/Dashboard.Common/Drawing/DrawCall.cs @@ -1,3 +1,4 @@ +using System.Collections.Immutable; using System.Diagnostics.CodeAnalysis; using System.Drawing; using System.Numerics; @@ -176,11 +177,27 @@ namespace Dashboard.Drawing public int Divisor { get; init; } = 1; } + public record VertexSpecification( + ImmutableList Attributes, + ImmutableList VertexBuffers + ) + { + public IBuffer? ElementBuffer { get; init; } = null; + } + public record struct UniformDescriptor(int Location, UniformType Type, long Offset, long Size); - public struct DrawCall(MeshPrimitive primitive, IBuffer vertexBuffer, int first, int count) + public struct DrawCall(MeshPrimitive primitive, VertexSpecification vertexSpec, int first, int count) { public IShader? ShaderPipeline { get; init; } + public VertexSpecification VertexSpecification { get; init; } = vertexSpec; + + public MeshPrimitive Primitive { get; init; } = primitive; + public int First { get; init; } = first; + public int Count { get; init; } = count; + public int BaseVertex { get; init; } = 0; + public long Offset { get; init; } = 0; + public Box2d ViewportRegion { get; init; } = new Box2d(Vector2.Zero, Vector2.PositiveInfinity); public Box2d ScissorRegion { get; init; } = new Box2d(Vector2.PositiveInfinity, Vector2.PositiveInfinity); public WindingOrder FrontFace { get; init; } = WindingOrder.Counterclockwise; @@ -197,19 +214,11 @@ namespace Dashboard.Drawing public float PointSize { get; init; }= 1.0f; public float LineWidth { get; init; }= 1.0f; - public MeshPrimitive Primitive { get; init; } = primitive; + public List Textures { get; init; } = []; - public List Attributes { get; init; } = []; public List Uniforms { get; init; } = []; public IndexType IndexType { get; init; } = IndexType.UnsignedShort; - public int First { get; init; } = first; - public int Count { get; init; } = count; - public long Offset { get; init; } = 0; - public int BaseVertex { get; init; } = 0; - - public IBuffer VertexBuffer { get; init; } = vertexBuffer; - public IBuffer? ElementBuffer { get; init; } public ReadOnlyMemory UniformData { get; init; } = ReadOnlyMemory.Empty; public IBuffer? UniformBuffer { get; init; } } diff --git a/Dashboard.OpenGL/Drawing/DirectRendering.cs b/Dashboard.OpenGL/Drawing/DirectRendering.cs index 74c7179..67f9c4a 100644 --- a/Dashboard.OpenGL/Drawing/DirectRendering.cs +++ b/Dashboard.OpenGL/Drawing/DirectRendering.cs @@ -60,7 +60,7 @@ namespace Dashboard.OpenGL.Drawing Vector2 size = Context.FramebufferSize; drawCall.SetAll(size, _vao, false); - if (drawCall.ElementBuffer is null) + if (drawCall.VertexSpecification.ElementBuffer is null) { GL.DrawArrays(drawCall.Primitive.OpenGL, drawCall.First, drawCall.Count); } diff --git a/Dashboard.OpenGL/Drawing/GLStateExtensions.cs b/Dashboard.OpenGL/Drawing/GLStateExtensions.cs index f09faed..7182605 100644 --- a/Dashboard.OpenGL/Drawing/GLStateExtensions.cs +++ b/Dashboard.OpenGL/Drawing/GLStateExtensions.cs @@ -336,15 +336,21 @@ namespace Dashboard.OpenGL.Drawing { GL.BindVertexArray(vao); - if (call.ElementBuffer != null) + VertexSpecification spec = call.VertexSpecification; + + if (spec.ElementBuffer != null) { - GL.BindBuffer(BufferTarget.ElementArrayBuffer, (call.ElementBuffer as GLBuffer)?.Handle ?? 0); + GL.BindBuffer(BufferTarget.ElementArrayBuffer, (spec.ElementBuffer as GLBuffer)?.Handle ?? 0); } - GL.BindBuffer(BufferTarget.ArrayBuffer, (call.VertexBuffer as GLBuffer)?.Handle ?? 0); - foreach(VertexAttribute attrib in call.Attributes) + for (int i = 0; i < spec.Attributes.Count; i++) { + VertexAttribute attrib = spec.Attributes[i]; + IBuffer? buffer = spec.VertexBuffers[i]; + + GL.BindBuffer(BufferTarget.ArrayBuffer, (buffer as GLBuffer)?.Handle ?? 0); + GL.VertexAttribPointer( (uint)attrib.Location, attrib.Components, diff --git a/tests/Dashboard.TestApplication/Program.cs b/tests/Dashboard.TestApplication/Program.cs index d55aa57..a98e0ac 100644 --- a/tests/Dashboard.TestApplication/Program.cs +++ b/tests/Dashboard.TestApplication/Program.cs @@ -113,14 +113,17 @@ IShader shader = direct.CreatePipeline(new GlslShaderCreateInfo() """, }); -DrawCall call = new DrawCall(MeshPrimitive.Triangle, vertex, 0, 3) -{ - ShaderPipeline = shader, - Attributes = +VertexSpecification spec = new VertexSpecification( [ new VertexAttribute(0, 3, VertexAttributeType.Float, 0, 8 * sizeof(float)), new VertexAttribute(1, 4, VertexAttributeType.Float, 4 * sizeof(float), 8 * sizeof(float)) ], + [vertex, vertex] +); + +DrawCall call = new DrawCall(MeshPrimitive.Triangle, spec, 0, 3) +{ + ShaderPipeline = shader }; window.EventRaised += (sender, eventArgs) =>