Go over vertex generator.
This commit is contained in:
parent
3856b3c66e
commit
21591c3d11
@ -12,7 +12,7 @@ namespace Dashboard.OpenTK
|
||||
{
|
||||
private readonly NativeWindow _window;
|
||||
private readonly GL21Driver _glDriver;
|
||||
private readonly VertexGeneratorEngine _vertexEngine;
|
||||
private readonly VertexDrawingEngine _vertexEngine;
|
||||
|
||||
public string Title
|
||||
{
|
||||
@ -57,7 +57,7 @@ namespace Dashboard.OpenTK
|
||||
{
|
||||
_window = window;
|
||||
_glDriver = new GL21Driver();
|
||||
_vertexEngine = new VertexGeneratorEngine();
|
||||
_vertexEngine = new VertexDrawingEngine();
|
||||
}
|
||||
|
||||
public void Focus()
|
||||
|
@ -27,7 +27,7 @@ namespace Dashboard.OpenGL
|
||||
private int tx2darray;
|
||||
|
||||
private bool isDiposed;
|
||||
private readonly Dictionary<DrawQueue, DrawData> data = new Dictionary<DrawQueue, DrawData>();
|
||||
private readonly Dictionary<DrawCallQueue, DrawData> data = new Dictionary<DrawCallQueue, DrawData>();
|
||||
private readonly TextureManager textures = new TextureManager();
|
||||
|
||||
public bool IsInit { get; private set; } = false;
|
||||
@ -87,7 +87,7 @@ namespace Dashboard.OpenGL
|
||||
if (!IsInit) throw new InvalidOperationException("Initialize the driver first.");
|
||||
}
|
||||
|
||||
public void Draw(DrawQueue queue, in QRectangle view)
|
||||
public void Draw(DrawCallQueue queue, in QRectangle view)
|
||||
{
|
||||
AssertInit();
|
||||
|
||||
@ -159,7 +159,7 @@ namespace Dashboard.OpenGL
|
||||
GL.Disable(GL_BLEND);
|
||||
}
|
||||
|
||||
public void ClearDrawQueue(DrawQueue queue)
|
||||
public void ClearDrawQueue(DrawCallQueue queue)
|
||||
{
|
||||
AssertInit();
|
||||
|
||||
@ -260,14 +260,14 @@ namespace Dashboard.OpenGL
|
||||
|
||||
private class DrawData : IDisposable
|
||||
{
|
||||
public DrawQueue Queue { get; }
|
||||
public DrawCallQueue Queue { get; }
|
||||
public int VertexArray { get; }
|
||||
|
||||
private readonly GL21Driver driver;
|
||||
private int vbo1, vbo2;
|
||||
private int ebo1, ebo2;
|
||||
|
||||
public DrawData(GL21Driver driver, DrawQueue queue)
|
||||
public DrawData(GL21Driver driver, DrawCallQueue queue)
|
||||
{
|
||||
Queue = queue;
|
||||
this.driver = driver;
|
||||
@ -290,13 +290,13 @@ namespace Dashboard.OpenGL
|
||||
|
||||
GL.BindVertexArray(VertexArray);
|
||||
GL.BindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
GL.BufferData(GL_ARRAY_BUFFER, QuikVertex.Stride * Queue.VertexCount, Queue.VertexArray, GL_STREAM_DRAW);
|
||||
GL.BufferData(GL_ARRAY_BUFFER, DbVertex.Stride * Queue.VertexCount, Queue.VertexArray, GL_STREAM_DRAW);
|
||||
|
||||
GL.VertexAttribPointer(driver.v2Position, 2, GL_FLOAT, false, QuikVertex.Stride, QuikVertex.PositionOffset);
|
||||
GL.VertexAttribPointer(driver.fZIndex, 1, GL_UNSIGNED_INT, false, QuikVertex.Stride, QuikVertex.ZIndexOffset);
|
||||
GL.VertexAttribPointer(driver.v2TexPos, 2, GL_FLOAT, false, QuikVertex.Stride, QuikVertex.TextureCoordinatesOffset);
|
||||
GL.VertexAttribPointer(driver.fTexLayer, 1, GL_FLOAT, false, QuikVertex.Stride, QuikVertex.TextureLayerOffset);
|
||||
GL.VertexAttribPointer(driver.v4Color, 4, GL_UNSIGNED_BYTE, true, QuikVertex.Stride, QuikVertex.ColorOffset);
|
||||
GL.VertexAttribPointer(driver.v2Position, 2, GL_FLOAT, false, DbVertex.Stride, DbVertex.PositionOffset);
|
||||
GL.VertexAttribPointer(driver.fZIndex, 1, GL_UNSIGNED_INT, false, DbVertex.Stride, DbVertex.ZIndexOffset);
|
||||
GL.VertexAttribPointer(driver.v2TexPos, 2, GL_FLOAT, false, DbVertex.Stride, DbVertex.TextureCoordinatesOffset);
|
||||
GL.VertexAttribPointer(driver.fTexLayer, 1, GL_FLOAT, false, DbVertex.Stride, DbVertex.TextureLayerOffset);
|
||||
GL.VertexAttribPointer(driver.v4Color, 4, GL_UNSIGNED_BYTE, true, DbVertex.Stride, DbVertex.ColorOffset);
|
||||
GL.EnableVertexAttribArray(driver.v2Position);
|
||||
GL.EnableVertexAttribArray(driver.fZIndex);
|
||||
GL.EnableVertexAttribArray(driver.v2TexPos);
|
||||
|
@ -6,7 +6,7 @@ namespace Dashboard.VertexGenerator
|
||||
/// Represents a GPU vertex.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("XY={Position} RGBA={Color}, UV={TextureCoordinates}")]
|
||||
public struct QuikVertex
|
||||
public struct DbVertex
|
||||
{
|
||||
/// <summary>
|
||||
/// Position value.
|
||||
@ -38,6 +38,6 @@ namespace Dashboard.VertexGenerator
|
||||
public static unsafe int ColorOffset => 2 * sizeof(QVec2);
|
||||
public static unsafe int ZIndexOffset => ColorOffset + sizeof(QColor);
|
||||
public static unsafe int TextureLayerOffset => ZIndexOffset + sizeof(int);
|
||||
public static unsafe int Stride => sizeof(QuikVertex);
|
||||
public static unsafe int Stride => sizeof(DbVertex);
|
||||
}
|
||||
}
|
@ -6,9 +6,9 @@ using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Dashboard.VertexGenerator
|
||||
{
|
||||
public class DrawQueue : IEnumerable<DrawCall>
|
||||
public class DrawCallQueue : IEnumerable<DrawCall>
|
||||
{
|
||||
private readonly RefList<QuikVertex> _vertices = new RefList<QuikVertex>();
|
||||
private readonly RefList<DbVertex> _vertices = new RefList<DbVertex>();
|
||||
private readonly RefList<int> _elements = new RefList<int>();
|
||||
private readonly List<DrawCall> _drawCalls = new List<DrawCall>();
|
||||
private int _start;
|
||||
@ -17,7 +17,7 @@ namespace Dashboard.VertexGenerator
|
||||
private QImage? _texture;
|
||||
|
||||
public int ZDepth { get; private set; }
|
||||
public QuikVertex[] VertexArray => _vertices.InternalArray;
|
||||
public DbVertex[] VertexArray => _vertices.InternalArray;
|
||||
public int VertexCount => _vertices.Count;
|
||||
public int[] ElementArray => _elements.InternalArray;
|
||||
public int ElementCount => _elements.Count;
|
||||
@ -51,7 +51,7 @@ namespace Dashboard.VertexGenerator
|
||||
public void StartDrawCall(in QRectangle bounds, QImage texture) => StartDrawCall(bounds, texture, _vertices.Count);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void AddVertex(in QuikVertex vertex)
|
||||
public void AddVertex(in DbVertex vertex)
|
||||
{
|
||||
_vertices.Add(in vertex);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ namespace Dashboard.VertexGenerator
|
||||
/// A small list which whose items can be used by reference.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Container type.</typeparam>
|
||||
public class RefList<T>
|
||||
internal class RefList<T>
|
||||
{
|
||||
private T[] _array = Array.Empty<T>();
|
||||
private int _count = 0;
|
||||
|
32
Dashboard/VertexGenerator/VertexCommandEngine.cs → Dashboard/VertexGenerator/VertexDrawingEngine.cs
32
Dashboard/VertexGenerator/VertexCommandEngine.cs → Dashboard/VertexGenerator/VertexDrawingEngine.cs
@ -6,9 +6,9 @@ using Dashboard.Typography;
|
||||
|
||||
namespace Dashboard.VertexGenerator
|
||||
{
|
||||
public class VertexGeneratorEngine : DrawingEngine
|
||||
public class VertexDrawingEngine : DrawingEngine
|
||||
{
|
||||
public DrawQueue DrawQueue { get; } = new DrawQueue();
|
||||
public DrawCallQueue DrawQueue { get; } = new DrawCallQueue();
|
||||
|
||||
/// <summary>
|
||||
/// Granularity for rounded geometry.
|
||||
@ -18,18 +18,18 @@ namespace Dashboard.VertexGenerator
|
||||
protected bool BlendTextures =>
|
||||
(Style["-vertex-blend-textures"] is bool value) ? value : false;
|
||||
|
||||
protected QuikVertex StrokeVertex => new QuikVertex()
|
||||
protected DbVertex StrokeVertex => new DbVertex()
|
||||
{
|
||||
ZIndex = Style.ZIndex ?? this.ZIndex,
|
||||
Color = Style.StrokeColor ?? QColor.Black,
|
||||
};
|
||||
protected QuikVertex FillVertex => new QuikVertex()
|
||||
protected DbVertex FillVertex => new DbVertex()
|
||||
{
|
||||
ZIndex = Style.ZIndex ?? this.ZIndex,
|
||||
Color = Style.Color ?? QColor.White,
|
||||
};
|
||||
|
||||
protected QuikVertex ImageVertex => new QuikVertex()
|
||||
protected DbVertex ImageVertex => new DbVertex()
|
||||
{
|
||||
ZIndex = Style.ZIndex ?? this.ZIndex,
|
||||
Color = BlendTextures ? (Style.Color ?? QColor.White) : QColor.White,
|
||||
@ -126,8 +126,8 @@ namespace Dashboard.VertexGenerator
|
||||
|
||||
private LineInfo GenerateLineSegment(in QLine line)
|
||||
{
|
||||
QuikVertex vertex = StrokeVertex;
|
||||
QuikVertex a, b, c, d;
|
||||
DbVertex vertex = StrokeVertex;
|
||||
DbVertex a, b, c, d;
|
||||
QVec2 normal = line.Normal();
|
||||
float width = Style.StrokeWidth ?? 1;
|
||||
|
||||
@ -171,7 +171,7 @@ namespace Dashboard.VertexGenerator
|
||||
return;
|
||||
}
|
||||
|
||||
QuikVertex vertex = StrokeVertex;
|
||||
DbVertex vertex = StrokeVertex;
|
||||
float radius = Style.StrokeWidth/2 ?? 0.5f;
|
||||
float arc = MathF.Acos(QVec2.Dot(prevNormal, nextNormal));
|
||||
int resolution = GetRoundingResolution(radius, arc);
|
||||
@ -240,7 +240,7 @@ namespace Dashboard.VertexGenerator
|
||||
bool endCap)
|
||||
{
|
||||
int lastIndex, startIndex;
|
||||
QuikVertex vertex = StrokeVertex;
|
||||
DbVertex vertex = StrokeVertex;
|
||||
float radius = Style.StrokeWidth ?? 1.0f;
|
||||
int resolution = GetRoundingResolution(radius, MathF.PI);
|
||||
|
||||
@ -380,7 +380,7 @@ namespace Dashboard.VertexGenerator
|
||||
int resolution = GetRoundingResolution(radius, bezier.RasterizationArc);
|
||||
|
||||
DrawQueue.RestoreOffset();
|
||||
QuikVertex v = StrokeVertex;
|
||||
DbVertex v = StrokeVertex;
|
||||
int vbase = DrawQueue.BaseOffset;
|
||||
int index = 2;
|
||||
|
||||
@ -480,7 +480,7 @@ namespace Dashboard.VertexGenerator
|
||||
|
||||
QVec2 aPos, bPos, cPos, dPos;
|
||||
|
||||
QuikVertex v = FillVertex;
|
||||
DbVertex v = FillVertex;
|
||||
aPos = v.Position = new QVec2(rectangle.Left + radius, rectangle.Bottom - radius);
|
||||
DrawQueue.AddVertex(v);
|
||||
bPos = v.Position = new QVec2(rectangle.Right - radius, rectangle.Bottom - radius);
|
||||
@ -616,7 +616,7 @@ namespace Dashboard.VertexGenerator
|
||||
0 1 2 3 4 5 6 7
|
||||
*/
|
||||
|
||||
QuikVertex v = StrokeVertex;
|
||||
DbVertex v = StrokeVertex;
|
||||
float stroke = Style.StrokeWidth ?? 1.0f;
|
||||
|
||||
DrawQueue.RestoreOffset();
|
||||
@ -673,7 +673,7 @@ namespace Dashboard.VertexGenerator
|
||||
u v w x
|
||||
20: 0 1 2 3
|
||||
*/
|
||||
QuikVertex v = StrokeVertex;
|
||||
DbVertex v = StrokeVertex;
|
||||
QVec2 nPos, qPos, tPos, wPos;
|
||||
float stroke = Style.StrokeWidth ?? 1.0f;
|
||||
|
||||
@ -862,7 +862,7 @@ namespace Dashboard.VertexGenerator
|
||||
10: 0 1 2 3 4 5
|
||||
*/
|
||||
|
||||
QuikVertex v = StrokeVertex;
|
||||
DbVertex v = StrokeVertex;
|
||||
float stroke = Style.StrokeWidth ?? 1.0f;
|
||||
float innerRadius = radius - stroke;
|
||||
DrawQueue.RestoreOffset();
|
||||
@ -1048,7 +1048,7 @@ namespace Dashboard.VertexGenerator
|
||||
}
|
||||
|
||||
DrawQueue.RestoreOffset();
|
||||
QuikVertex vertex = ImageVertex;
|
||||
DbVertex vertex = ImageVertex;
|
||||
|
||||
vertex.Position = new QVec2(rect.Left, rect.Top);
|
||||
vertex.TextureCoordinates = new QVec2(uvs.Left, uvs.Top);
|
||||
@ -1084,7 +1084,7 @@ namespace Dashboard.VertexGenerator
|
||||
int layer = (int)queue.Dequeue();
|
||||
|
||||
DrawQueue.RestoreOffset();
|
||||
QuikVertex vertex = ImageVertex;
|
||||
DbVertex vertex = ImageVertex;
|
||||
vertex.TextureLayer = layer;
|
||||
|
||||
vertex.Position = new QVec2(rect.Top, rect.Left);
|
Loading…
Reference in New Issue
Block a user