diff --git a/Quik.FreeType/FreeTypeFont.cs b/Quik.FreeType/FreeTypeFont.cs
index 1c2ad34..6d2112d 100644
--- a/Quik.FreeType/FreeTypeFont.cs
+++ b/Quik.FreeType/FreeTypeFont.cs
@@ -64,15 +64,15 @@ namespace Quik.FreeType
entry.Atlas = new Atlas(_owner.Context.TextureManager, _library);
_textures.Add(entry.Atlas);
}
- entry.Atlas.AttachGlyph(_face.Glyph, out QuikRectangle uvs);
+ entry.Atlas.AttachGlyph(_face.Glyph, out QRectangle uvs);
entry.Metrics = new QuikGlyph(
character,
uvs,
- new QuikVec2(_face.Glyph.Metrics.Width / 64f, _face.Glyph.Metrics.Height / 64f),
- new QuikVec2(_face.Glyph.Metrics.HorizontalBearingX / 64f, _face.Glyph.Metrics.HorizontalBearingY / 64f),
- new QuikVec2(_face.Glyph.Metrics.VerticalBearingX / 64f , _face.Glyph.Metrics.VerticalBearingY / 64f),
- new QuikVec2(_face.Glyph.Metrics.HorizontalAdvance / 64f, _face.Glyph.Metrics.VerticalAdvance / 64f));
+ new QVec2(_face.Glyph.Metrics.Width / 64f, _face.Glyph.Metrics.Height / 64f),
+ new QVec2(_face.Glyph.Metrics.HorizontalBearingX / 64f, _face.Glyph.Metrics.HorizontalBearingY / 64f),
+ new QVec2(_face.Glyph.Metrics.VerticalBearingX / 64f , _face.Glyph.Metrics.VerticalBearingY / 64f),
+ new QVec2(_face.Glyph.Metrics.HorizontalAdvance / 64f, _face.Glyph.Metrics.VerticalAdvance / 64f));
_entries[character] = entry;
@@ -104,7 +104,7 @@ namespace Quik.FreeType
{
public QuikTexture Texture;
- private QuikVec2 _pointer = new QuikVec2();
+ private QVec2 _pointer = new QVec2();
private float _verticalAdvance = 0;
private FTLibrary _ft;
private FTBitmap _bitmap;
@@ -112,7 +112,7 @@ namespace Quik.FreeType
public Atlas(IQuikTextureManager textureManager, FTLibrary ft)
{
Texture = textureManager.CreateTexture(
- new QuikVec2(4096, 4096),
+ new QVec2(4096, 4096),
false,
QuikImageFormat.RgbaU8);
@@ -126,14 +126,14 @@ namespace Quik.FreeType
return true;
}
- public void AttachGlyph(in FTGlyphSlot slot, out QuikRectangle UVs)
+ public void AttachGlyph(in FTGlyphSlot slot, out QRectangle UVs)
{
FT.BitmapConvert(_ft, slot.Bitmap, ref _bitmap, 1);
- QuikRectangle position =
- new QuikRectangle(
- _pointer + new QuikVec2(_bitmap.Width + 1, _bitmap.Rows + 1),
- _pointer + new QuikVec2(1, 1));
+ QRectangle position =
+ new QRectangle(
+ _pointer + new QVec2(_bitmap.Width + 1, _bitmap.Rows + 1),
+ _pointer + new QVec2(1, 1));
Texture.SubImage(
_bitmap.Buffer,
@@ -145,7 +145,7 @@ namespace Quik.FreeType
_pointer.X += _bitmap.Width + 2;
_verticalAdvance = Math.Max(_verticalAdvance, slot.Bitmap.Rows + 2);
- UVs = new QuikRectangle(
+ UVs = new QRectangle(
position.Right / 4096,
position.Bottom / 4096,
position.Left / 4096,
diff --git a/Quik.OpenTK/GL30Driver.cs b/Quik.OpenTK/GL30Driver.cs
index 7a01caa..bee3f57 100644
--- a/Quik.OpenTK/GL30Driver.cs
+++ b/Quik.OpenTK/GL30Driver.cs
@@ -2,6 +2,8 @@ using System;
using System.IO;
using System.Reflection;
using Quik.OpenGL;
+using Quik.VertexGenerator;
+using Matrix4 = OpenTK.Mathematics.Matrix4;
using static Quik.OpenGL.GLEnum;
namespace Quik.OpenTK
@@ -86,9 +88,16 @@ namespace Quik.OpenTK
{
location = GL.GetAttribLocation(_sp, name);
}
+
+ _vbo = GL.GenBuffer();
+ _ebo = GL.GenBuffer();
+ _vao = GL.GenVertexArray();
}
private readonly int _sp;
+ private readonly int _vao;
+ private readonly int _vbo;
+ private readonly int _ebo;
private const string _nameM4View = "m4View";
private readonly int _locM4View;
@@ -122,6 +131,38 @@ namespace Quik.OpenTK
SdfAuxEnable = 1 << 3,
}
+ public void Draw(DrawQueue queue)
+ {
+ GL.UseProgram(_sp);
+ GL.BindVertexArray(_vao);
+
+ GL.BindBuffer(GL_ARRAY_BUFFER, _vbo);
+ GL.BufferData(GL_ARRAY_BUFFER, queue.VertexCount * QuikVertex.Stride, queue.VertexArray, GL_STREAM_DRAW);
+ GL.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ebo);
+ GL.BufferData(GL_ELEMENT_ARRAY_BUFFER, queue.ElementCount * sizeof(int), queue.ElementArray, GL_STREAM_DRAW);
+
+ GL.VertexAttribPointer(_locV2Position, 2, GL_FLOAT, false, QuikVertex.Stride, QuikVertex.PositionOffset);
+ GL.VertexAttribPointer(_locV2Texture, 2, GL_FLOAT, false, QuikVertex.Stride, QuikVertex.TextureCoordinatesOffset);
+ GL.VertexAttribPointer(_locV4Color, 4, GL_UNSIGNED_BYTE, false, QuikVertex.Stride, QuikVertex.ColorOffset);
+ GL.EnableVertexAttribArray(_locV2Position);
+ GL.EnableVertexAttribArray(_locV2Texture);
+ GL.EnableVertexAttribArray(_locV4Color);
+
+ GL.Enable(GL_BLEND);
+ GL.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ Matrix4 m = Matrix4.Identity;
+ GL.UniformMatrix4(_locM4Model, false, ref m.Row0.X);
+
+ foreach (DrawCall call in queue)
+ {
+ GL.BindTexture(GL_TEXTURE_2D, ((OpenGLTexture)call.Texture)?.TextureId ?? 0);
+ m = Matrix4.CreateOrthographicOffCenter(0, call.Bounds.Right, 0, call.Bounds.Top, 1.0f, -1.0f);
+ GL.UniformMatrix4(_locM4View, false, ref m.Row0.X);
+ GL.DrawElements(GL_TRIANGLES, call.Count, GL_UNSIGNED_INT, call.Start);
+ }
+ }
+
private bool _isDisposed = false;
private void Dispose(bool disposing)
{
diff --git a/Quik.OpenTK/OpenGLTexture.cs b/Quik.OpenTK/OpenGLTexture.cs
index dfa17b0..2fc8481 100644
--- a/Quik.OpenTK/OpenGLTexture.cs
+++ b/Quik.OpenTK/OpenGLTexture.cs
@@ -13,7 +13,7 @@ namespace Quik.OpenTK
private int _height;
private bool _mipmaps;
- internal OpenGLTexture(OpenGLTextureManager manager, QuikImageFormat format, QuikVec2 size, bool mipmaps)
+ internal OpenGLTexture(OpenGLTextureManager manager, QuikImageFormat format, QVec2 size, bool mipmaps)
{
Manager = manager;
_mipmaps = mipmaps;
@@ -61,7 +61,7 @@ namespace Quik.OpenTK
public override bool Mipmaps => _mipmaps;
///
- public override void Image(IntPtr data, QuikImageFormat format, QuikVec2 size, int level, int alignment = 4)
+ public override void Image(IntPtr data, QuikImageFormat format, QVec2 size, int level, int alignment = 4)
{
GL.BindTexture(GL_TEXTURE_2D, TextureId);
GL.PixelStore(GL_UNPACK_ALIGNMENT, alignment);
@@ -69,7 +69,7 @@ namespace Quik.OpenTK
}
///
- public override void SubImage(IntPtr data, QuikImageFormat format, QuikRectangle location, int level, int alignment = 4)
+ public override void SubImage(IntPtr data, QuikImageFormat format, QRectangle location, int level, int alignment = 4)
{
GL.BindTexture(GL_TEXTURE_2D, TextureId);
GL.PixelStore(GL_UNPACK_ALIGNMENT, alignment);
diff --git a/Quik.OpenTK/OpenGLTextureManager.cs b/Quik.OpenTK/OpenGLTextureManager.cs
index 3ff73cc..79f6052 100644
--- a/Quik.OpenTK/OpenGLTextureManager.cs
+++ b/Quik.OpenTK/OpenGLTextureManager.cs
@@ -9,7 +9,7 @@ namespace Quik.OpenTK
private List _reclaimList = new List();
- public QuikTexture CreateTexture(QuikVec2 size, bool mipmaps, QuikImageFormat format)
+ public QuikTexture CreateTexture(QVec2 size, bool mipmaps, QuikImageFormat format)
{
return new OpenGLTexture(this, format, size, mipmaps);
}
diff --git a/Quik/CommandMachine/CommandEngine.cs b/Quik/CommandMachine/CommandEngine.cs
index 246bb8e..4514b23 100644
--- a/Quik/CommandMachine/CommandEngine.cs
+++ b/Quik/CommandMachine/CommandEngine.cs
@@ -9,14 +9,14 @@ namespace Quik.CommandMachine
private readonly Stack _zStack = new Stack();
public int ZIndex => _zIndex;
- private QuikRectangle _viewport;
- private readonly Stack _viewportStack = new Stack();
+ private QRectangle _viewport;
+ private readonly Stack _viewportStack = new Stack();
private readonly Stack