Compare commits
No commits in common. "ef860f39bfe52db59649bb184aba31e5b33102d1" and "afa6ed4f4c2e5ac77cc819c92e8be28caa1406b4" have entirely different histories.
ef860f39bf
...
afa6ed4f4c
@ -51,7 +51,6 @@ namespace Dashboard.Drawing.OpenGL
|
|||||||
ResourcePool.IncrementReference();
|
ResourcePool.IncrementReference();
|
||||||
|
|
||||||
AddExecutor(new BaseCommandExecutor());
|
AddExecutor(new BaseCommandExecutor());
|
||||||
AddExecutor(new TextCommandExecutor());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~ContextExecutor()
|
~ContextExecutor()
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="BlurgText" Version="0.1.0-nightly-19" />
|
|
||||||
<PackageReference Include="OpenTK.Graphics" Version="5.0.0-pre.13" />
|
<PackageReference Include="OpenTK.Graphics" Version="5.0.0-pre.13" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
@ -19,8 +18,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="Executors\simple.frag" />
|
<EmbeddedResource Include="Executors\simple.frag" />
|
||||||
<EmbeddedResource Include="Executors\simple.vert" />
|
<EmbeddedResource Include="Executors\simple.vert" />
|
||||||
<EmbeddedResource Include="Executors\text.vert" />
|
|
||||||
<EmbeddedResource Include="Executors\text.frag" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,243 +0,0 @@
|
|||||||
using System.Reflection;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using BlurgText;
|
|
||||||
using Dashboard.Drawing.OpenGL.Text;
|
|
||||||
using OpenTK.Graphics.OpenGL;
|
|
||||||
using OpenTK.Mathematics;
|
|
||||||
|
|
||||||
namespace Dashboard.Drawing.OpenGL.Executors
|
|
||||||
{
|
|
||||||
public class TextCommandExecutor : ICommandExecutor, IInitializer
|
|
||||||
{
|
|
||||||
public IEnumerable<string> Extensions { get; } = new[] { "DB_Text" };
|
|
||||||
public IContextExecutor Executor { get; private set; }
|
|
||||||
private BlurgEngine Engine => Executor.ResourcePool.GetResourceManager<BlurgEngine>();
|
|
||||||
public bool IsInitialized { get; private set; }
|
|
||||||
|
|
||||||
private DrawCallRecorder _recorder;
|
|
||||||
private int _program = 0;
|
|
||||||
private int _transformsLocation = -1;
|
|
||||||
private int _atlasLocation = -1;
|
|
||||||
private int _borderWidthLocation = -1;
|
|
||||||
private int _borderColorLocation = -1;
|
|
||||||
private int _fillColorLocation = -1;
|
|
||||||
|
|
||||||
public TextCommandExecutor()
|
|
||||||
{
|
|
||||||
Executor = null!;
|
|
||||||
_recorder = new DrawCallRecorder(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Initialize()
|
|
||||||
{
|
|
||||||
if (IsInitialized)
|
|
||||||
return;
|
|
||||||
IsInitialized = true;
|
|
||||||
|
|
||||||
Assembly self = typeof(TextCommandExecutor).Assembly;
|
|
||||||
|
|
||||||
using Stream vsource = self.GetManifestResourceStream("Dashboard.Drawing.OpenGL.Executors.text.vert")!;
|
|
||||||
using Stream fsource = self.GetManifestResourceStream("Dashboard.Drawing.OpenGL.Executors.text.frag")!;
|
|
||||||
int vs = ShaderUtil.CompileShader(ShaderType.VertexShader, vsource);
|
|
||||||
int fs = ShaderUtil.CompileShader(ShaderType.FragmentShader, fsource);
|
|
||||||
_program = ShaderUtil.LinkProgram(vs, fs, new []
|
|
||||||
{
|
|
||||||
"a_v3Position",
|
|
||||||
"a_v2TexCoords",
|
|
||||||
});
|
|
||||||
GL.DeleteShader(vs);
|
|
||||||
GL.DeleteShader(fs);
|
|
||||||
|
|
||||||
_transformsLocation = GL.GetUniformLocation(_program, "m4Transforms");
|
|
||||||
_atlasLocation = GL.GetUniformLocation(_program, "txAtlas");
|
|
||||||
_borderWidthLocation = GL.GetUniformLocation(_program, "fBorderWidth");
|
|
||||||
_borderColorLocation = GL.GetUniformLocation(_program, "v4BorderColor");
|
|
||||||
_fillColorLocation = GL.GetUniformLocation(_program, "v4FillColor");
|
|
||||||
|
|
||||||
_recorder.Initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetContextExecutor(IContextExecutor executor)
|
|
||||||
{
|
|
||||||
Executor = executor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void BeginFrame()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void BeginDraw()
|
|
||||||
{
|
|
||||||
_recorder.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void EndDraw()
|
|
||||||
{
|
|
||||||
GL.UseProgram(_program);
|
|
||||||
GL.Enable(EnableCap.Blend);
|
|
||||||
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
|
|
||||||
_recorder.Execute();
|
|
||||||
GL.Disable(EnableCap.Blend);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void EndFrame()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ProcessCommand(ICommandFrame frame)
|
|
||||||
{
|
|
||||||
switch (frame.Command.Name)
|
|
||||||
{
|
|
||||||
case "Text":
|
|
||||||
DrawText(frame);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DrawText(ICommandFrame frame)
|
|
||||||
{
|
|
||||||
TextCommandArgs args = frame.GetParameter<TextCommandArgs>();
|
|
||||||
DbBlurgFont font = (DbBlurgFont)args.Font;
|
|
||||||
|
|
||||||
BlurgColor color;
|
|
||||||
switch (args.TextBrush)
|
|
||||||
{
|
|
||||||
case SolidBrush solid:
|
|
||||||
color = new BlurgColor()
|
|
||||||
{
|
|
||||||
R = solid.Color.R,
|
|
||||||
G = solid.Color.G,
|
|
||||||
B = solid.Color.B,
|
|
||||||
A = solid.Color.A,
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
color = new BlurgColor() { R = 255, G = 0, B = 255, A = 255 };
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
BlurgResult? result = Engine.Blurg.BuildString(font.Font, font.Size, color, args.Text);
|
|
||||||
|
|
||||||
if (result == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Vector3 position = new Vector3(args.Position.X, args.Position.Y, args.Position.Z);
|
|
||||||
ExecuteBlurgResult(result, position);
|
|
||||||
|
|
||||||
result.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ExecuteBlurgResult(BlurgResult result, Vector3 position)
|
|
||||||
{
|
|
||||||
Matrix4 transforms = Executor.TransformStack.Top;
|
|
||||||
|
|
||||||
for (int i = 0; i < result.Count; i++)
|
|
||||||
{
|
|
||||||
BlurgRect rect = result[i];
|
|
||||||
|
|
||||||
int texture = (int)rect.UserData;
|
|
||||||
Vector4 color = new Vector4(rect.Color.R / 255f, rect.Color.G / 255f, rect.Color.B / 255f,
|
|
||||||
rect.Color.A / 255f);
|
|
||||||
|
|
||||||
if (i == 0)
|
|
||||||
{
|
|
||||||
_recorder.Begin(PrimitiveType.Triangles, new Call()
|
|
||||||
{
|
|
||||||
Texture = texture,
|
|
||||||
FillColor = color,
|
|
||||||
Transforms = transforms,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (
|
|
||||||
_recorder.CurrentCall.Texture != texture ||
|
|
||||||
_recorder.CurrentCall.FillColor != color)
|
|
||||||
{
|
|
||||||
_recorder.End();
|
|
||||||
Call call = new Call()
|
|
||||||
{
|
|
||||||
Texture = texture,
|
|
||||||
FillColor = color,
|
|
||||||
Transforms = transforms,
|
|
||||||
};
|
|
||||||
_recorder.Begin(PrimitiveType.Triangles, call);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector3 p00 = new Vector3(rect.X, rect.Y, 0) + position;
|
|
||||||
Vector3 p10 = p00 + new Vector3(rect.Width, 0, 0);
|
|
||||||
Vector3 p11 = p00 + new Vector3(rect.Width, rect.Height, 0);
|
|
||||||
Vector3 p01 = p00 + new Vector3(0, rect.Height, 0);
|
|
||||||
|
|
||||||
Vector2 uv00 = new Vector2(rect.U0, rect.V0);
|
|
||||||
Vector2 uv10 = new Vector2(rect.U1, rect.V0);
|
|
||||||
Vector2 uv11 = new Vector2(rect.U1, rect.V1);
|
|
||||||
Vector2 uv01 = new Vector2(rect.U0, rect.V1);
|
|
||||||
|
|
||||||
_recorder.Vertex(p00, uv00);
|
|
||||||
_recorder.Vertex(p10, uv10);
|
|
||||||
_recorder.Vertex(p11, uv11);
|
|
||||||
|
|
||||||
_recorder.Vertex(p00, uv00);
|
|
||||||
_recorder.Vertex(p11, uv11);
|
|
||||||
_recorder.Vertex(p01, uv01);
|
|
||||||
}
|
|
||||||
_recorder.End();
|
|
||||||
}
|
|
||||||
|
|
||||||
private struct Call
|
|
||||||
{
|
|
||||||
public Matrix4 Transforms = Matrix4.Identity;
|
|
||||||
public int Texture = 0;
|
|
||||||
public float BorderWidth = 0f;
|
|
||||||
public Vector4 FillColor = Vector4.One;
|
|
||||||
public Vector4 BorderColor = new Vector4(0,0,0,1);
|
|
||||||
|
|
||||||
public Call()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Explicit, Size = 8 * sizeof(float))]
|
|
||||||
private struct Vertex
|
|
||||||
{
|
|
||||||
[FieldOffset(0)]
|
|
||||||
public Vector3 Position;
|
|
||||||
[FieldOffset(4 * sizeof(float))]
|
|
||||||
public Vector2 TexCoords;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class DrawCallRecorder : DrawCallRecorder<Call, Vertex>
|
|
||||||
{
|
|
||||||
private TextCommandExecutor Executor { get; }
|
|
||||||
|
|
||||||
public DrawCallRecorder(TextCommandExecutor executor)
|
|
||||||
{
|
|
||||||
Executor = executor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Vertex(Vector3 position, Vector2 texCoords)
|
|
||||||
{
|
|
||||||
Vertex(new Vertex(){Position = position, TexCoords = texCoords});
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void PrepareCall(in Call call)
|
|
||||||
{
|
|
||||||
Matrix4 transforms = call.Transforms;
|
|
||||||
GL.UniformMatrix4f(Executor._transformsLocation, 1, true, ref transforms);
|
|
||||||
GL.Uniform1f(Executor._borderWidthLocation, call.BorderWidth);
|
|
||||||
GL.Uniform4f(Executor._borderColorLocation, 1, in call.BorderColor);
|
|
||||||
GL.Uniform4f(Executor._fillColorLocation, 1, in call.FillColor);
|
|
||||||
GL.Uniform1i(Executor._atlasLocation, 0);
|
|
||||||
GL.ActiveTexture(TextureUnit.Texture0);
|
|
||||||
GL.BindTexture(TextureTarget.Texture2d, call.Texture);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void SetVertexFormat()
|
|
||||||
{
|
|
||||||
GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, VertexSize, 0);
|
|
||||||
GL.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, VertexSize, 4*sizeof(float));
|
|
||||||
GL.EnableVertexAttribArray(0);
|
|
||||||
GL.EnableVertexAttribArray(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
#version 140
|
|
||||||
|
|
||||||
in vec3 v_v3Position;
|
|
||||||
in vec2 v_v2TexCoords;
|
|
||||||
|
|
||||||
out vec4 f_Color;
|
|
||||||
|
|
||||||
uniform sampler2D txAtlas;
|
|
||||||
uniform float fBorderWidth;
|
|
||||||
uniform vec4 v4BorderColor;
|
|
||||||
uniform vec4 v4FillColor;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
// For now just honor the fill color
|
|
||||||
|
|
||||||
vec4 color = texture(txAtlas, v_v2TexCoords) * v4FillColor;
|
|
||||||
|
|
||||||
if (color.a <= 0.1)
|
|
||||||
discard;
|
|
||||||
f_Color = color;
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
#version 140
|
|
||||||
|
|
||||||
in vec3 a_v3Position;
|
|
||||||
in vec2 a_v2TexCoords;
|
|
||||||
|
|
||||||
out vec3 v_v3Position;
|
|
||||||
out vec2 v_v2TexCoords;
|
|
||||||
|
|
||||||
uniform mat4 m4Transforms;
|
|
||||||
|
|
||||||
void main(void)
|
|
||||||
{
|
|
||||||
vec4 position = vec4(a_v3Position, 1) * m4Transforms;
|
|
||||||
gl_Position = position;
|
|
||||||
v_v3Position = position.xyz/position.w;
|
|
||||||
|
|
||||||
v_v2TexCoords = a_v2TexCoords;
|
|
||||||
}
|
|
@ -1,4 +1,3 @@
|
|||||||
using Dashboard.Drawing.OpenGL.Text;
|
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
|
|
||||||
@ -19,8 +18,6 @@ namespace Dashboard.Drawing.OpenGL
|
|||||||
|
|
||||||
if (bindingsContext != null)
|
if (bindingsContext != null)
|
||||||
GLLoader.LoadBindings(bindingsContext);
|
GLLoader.LoadBindings(bindingsContext);
|
||||||
|
|
||||||
Typesetter.Backend = BlurgEngine.Global;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContextExecutor GetExecutor(IGLContext glContext)
|
public ContextExecutor GetExecutor(IGLContext glContext)
|
||||||
|
@ -1,188 +0,0 @@
|
|||||||
using System.Diagnostics;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Numerics;
|
|
||||||
using BlurgText;
|
|
||||||
using OpenTK.Graphics.OpenGL;
|
|
||||||
using OPENGL = OpenTK.Graphics.OpenGL;
|
|
||||||
|
|
||||||
namespace Dashboard.Drawing.OpenGL.Text
|
|
||||||
{
|
|
||||||
public class BlurgEngine : IResourceManager, IGLDisposable, ITypeSetter
|
|
||||||
{
|
|
||||||
public string Name { get; } = "BlurgEngine";
|
|
||||||
public Blurg Blurg { get; }
|
|
||||||
public bool SystemFontsEnabled { get; }
|
|
||||||
|
|
||||||
private readonly List<int> _textures = new List<int>();
|
|
||||||
|
|
||||||
public BlurgEngine() : this(false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
private BlurgEngine(bool global)
|
|
||||||
{
|
|
||||||
if (global)
|
|
||||||
Blurg = new Blurg(AllocateTextureGlobal, UpdateTextureGlobal);
|
|
||||||
else
|
|
||||||
Blurg = new Blurg(AllocateTexture, UpdateTexture);
|
|
||||||
|
|
||||||
SystemFontsEnabled = Blurg.EnableSystemFonts();
|
|
||||||
}
|
|
||||||
|
|
||||||
~BlurgEngine()
|
|
||||||
{
|
|
||||||
Dispose(false, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SizeF MeasureString(IFont font, string value)
|
|
||||||
{
|
|
||||||
return MeasureStringInternal(InternFont(font), value);
|
|
||||||
}
|
|
||||||
|
|
||||||
private SizeF MeasureStringInternal(DbBlurgFont font, string value)
|
|
||||||
{
|
|
||||||
Vector2 v = Blurg.MeasureString(font.Font, font.Size, value);
|
|
||||||
return new SizeF(v.X, v.Y);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IFont LoadFont(Stream stream)
|
|
||||||
{
|
|
||||||
string path;
|
|
||||||
Stream dest;
|
|
||||||
for (int i = 0;; i++)
|
|
||||||
{
|
|
||||||
path = Path.GetTempFileName();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
dest = File.Open(path, FileMode.CreateNew, FileAccess.Write, FileShare.None);
|
|
||||||
}
|
|
||||||
catch (IOException ex)
|
|
||||||
{
|
|
||||||
if (i < 3)
|
|
||||||
continue;
|
|
||||||
else
|
|
||||||
throw new Exception("Could not open a temporary file for writing the font.", ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
stream.CopyTo(dest);
|
|
||||||
dest.Dispose();
|
|
||||||
|
|
||||||
DbBlurgFont font = (DbBlurgFont)LoadFont(path);
|
|
||||||
File.Delete(path);
|
|
||||||
return font;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IFont LoadFont(string path)
|
|
||||||
{
|
|
||||||
BlurgFont? font = Blurg.AddFontFile(path) ?? throw new Exception("Failed to load the font file.");
|
|
||||||
return new DbBlurgFont(Blurg, font, 12f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IFont LoadFont(NamedFont font)
|
|
||||||
{
|
|
||||||
// Ignore the stretch argument.
|
|
||||||
bool italic = font.Slant != FontSlant.Normal;
|
|
||||||
BlurgFont? loaded = Blurg.QueryFont(font.Family, new BlurgText.FontWeight((int)font.Weight), italic);
|
|
||||||
|
|
||||||
if (loaded != null)
|
|
||||||
return new DbBlurgFont(Blurg, loaded, 12f);
|
|
||||||
else
|
|
||||||
throw new Exception("Font not found.");
|
|
||||||
}
|
|
||||||
|
|
||||||
private DbBlurgFont InternFont(IFont font)
|
|
||||||
{
|
|
||||||
if (font is NamedFont named)
|
|
||||||
{
|
|
||||||
return (DbBlurgFont)LoadFont(named);
|
|
||||||
}
|
|
||||||
else if (font is DbBlurgFont dblurg)
|
|
||||||
{
|
|
||||||
if (dblurg.Owner != Blurg)
|
|
||||||
{
|
|
||||||
throw new Exception();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return dblurg;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new Exception("Unsupported font resource.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateTexture(IntPtr texture, IntPtr buffer, int x, int y, int width, int height)
|
|
||||||
{
|
|
||||||
GL.BindTexture(TextureTarget.Texture2d, (int)texture);
|
|
||||||
GL.TexSubImage2D(TextureTarget.Texture2d, 0, x, y, width, height, OPENGL.PixelFormat.Rgba, PixelType.UnsignedByte, buffer);
|
|
||||||
// GL.TexSubImage2D(TextureTarget.Texture2d, 0, x, y, width, height, OPENGL.PixelFormat.Red, PixelType.Byte, buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
private IntPtr AllocateTexture(int width, int height)
|
|
||||||
{
|
|
||||||
int texture = GL.GenTexture();
|
|
||||||
|
|
||||||
GL.BindTexture(TextureTarget.Texture2d, texture);
|
|
||||||
GL.TexImage2D(TextureTarget.Texture2d, 0, InternalFormat.Rgba, width, height, 0, OPENGL.PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);
|
|
||||||
// GL.TexImage2D(TextureTarget.Texture2d, 0, InternalFormat.R8, width, height, 0, OPENGL.PixelFormat.Red, PixelType.Byte, IntPtr.Zero);
|
|
||||||
|
|
||||||
GL.TexParameteri(TextureTarget.Texture2d, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
|
|
||||||
GL.TexParameteri(TextureTarget.Texture2d, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
|
|
||||||
// GL.TexParameteri(TextureTarget.Texture2d, TextureParameterName.TextureSwizzleR, (int)TextureSwizzle.One);
|
|
||||||
// GL.TexParameteri(TextureTarget.Texture2d, TextureParameterName.TextureSwizzleG, (int)TextureSwizzle.One);
|
|
||||||
// GL.TexParameteri(TextureTarget.Texture2d, TextureParameterName.TextureSwizzleB, (int)TextureSwizzle.One);
|
|
||||||
// GL.TexParameteri(TextureTarget.Texture2d, TextureParameterName.TextureSwizzleA, (int)TextureSwizzle.Red);
|
|
||||||
|
|
||||||
_textures.Add(texture);
|
|
||||||
|
|
||||||
return texture;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool _isDisposed = false;
|
|
||||||
|
|
||||||
private void Dispose(bool disposing, bool safeExit)
|
|
||||||
{
|
|
||||||
if (_isDisposed)
|
|
||||||
return;
|
|
||||||
_isDisposed = true;
|
|
||||||
|
|
||||||
if (disposing)
|
|
||||||
{
|
|
||||||
Blurg.Dispose();
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (safeExit)
|
|
||||||
{
|
|
||||||
foreach (int texture in _textures)
|
|
||||||
ContextCollector.Global.DeleteTexture(texture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose() => Dispose(true, true);
|
|
||||||
|
|
||||||
public void Dispose(bool safeExit) => Dispose(true, safeExit);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The global Blurg engine implements the needed methods for command queues to work.
|
|
||||||
/// </summary>
|
|
||||||
public static BlurgEngine Global { get; } = new BlurgEngine(true);
|
|
||||||
|
|
||||||
private static void UpdateTextureGlobal(IntPtr userdata, IntPtr buffer, int x, int y, int width, int height)
|
|
||||||
{
|
|
||||||
// Report the user error.
|
|
||||||
Debug.WriteLine("Attempt to create or update a texture from the global BlurgEngine.", "Dashboard/BlurgEngine");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IntPtr AllocateTextureGlobal(int width, int height)
|
|
||||||
{
|
|
||||||
Debug.WriteLine("Attempt to create or update a texture from the global BlurgEngine.", "Dashboard/BlurgEngine");
|
|
||||||
return IntPtr.Zero;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
namespace Dashboard.Drawing.OpenGL.Text
|
|
||||||
{
|
|
||||||
public class BlurgFontExtension : IDrawExtension
|
|
||||||
{
|
|
||||||
public string Name { get; } = "BLURG_Font";
|
|
||||||
public IReadOnlyList<IDrawExtension> Requires { get; } = new [] { FontExtension.Instance };
|
|
||||||
public IReadOnlyList<IDrawCommand> Commands { get; } = new IDrawCommand[] { };
|
|
||||||
|
|
||||||
private BlurgFontExtension() {}
|
|
||||||
|
|
||||||
public static readonly BlurgFontExtension Instance = new BlurgFontExtension();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
using BlurgText;
|
|
||||||
|
|
||||||
namespace Dashboard.Drawing.OpenGL.Text
|
|
||||||
{
|
|
||||||
public class DbBlurgFont : IFont
|
|
||||||
{
|
|
||||||
public IDrawExtension Kind { get; } = BlurgFontExtension.Instance;
|
|
||||||
public Blurg Owner { get; }
|
|
||||||
public BlurgFont Font { get; }
|
|
||||||
public float Size { get; }
|
|
||||||
public string Family => Font.FamilyName;
|
|
||||||
public FontWeight Weight => (FontWeight)Font.Weight.Value;
|
|
||||||
public FontSlant Slant => Font.Italic ? FontSlant.Italic : FontSlant.Normal;
|
|
||||||
public FontStretch Stretch => FontStretch.Normal;
|
|
||||||
|
|
||||||
public DbBlurgFont(Blurg owner, BlurgFont font, float size)
|
|
||||||
{
|
|
||||||
Owner = owner;
|
|
||||||
Font = font;
|
|
||||||
Size = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DbBlurgFont WithSize(float size)
|
|
||||||
{
|
|
||||||
return new DbBlurgFont(Owner, Font, size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -119,8 +119,7 @@ namespace Dashboard.Drawing
|
|||||||
Anchor anchor = Anchor.Left)
|
Anchor anchor = Anchor.Left)
|
||||||
{
|
{
|
||||||
IDrawController controller = queue.GetController(DbBaseCommands.Instance);
|
IDrawController controller = queue.GetController(DbBaseCommands.Instance);
|
||||||
SizeF size = Typesetter.MeasureString(font, text);
|
controller.EnsureBounds(new Box2d(position.X, position.Y, position.X, position.Y), position.Z);
|
||||||
controller.EnsureBounds(new Box2d(position.X, position.Y, position.X + size.Width, position.Y + size.Height), position.Z);
|
|
||||||
controller.Write(TextExtension.Instance.TextCommand, new TextCommandArgs(font, brush, anchor, position, text));
|
controller.Write(TextExtension.Instance.TextCommand, new TextCommandArgs(font, brush, anchor, position, text));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,8 +127,7 @@ namespace Dashboard.Drawing
|
|||||||
float borderRadius, string text, IFont font, Anchor anchor = Anchor.Left, BorderKind borderKind = BorderKind.Outset)
|
float borderRadius, string text, IFont font, Anchor anchor = Anchor.Left, BorderKind borderKind = BorderKind.Outset)
|
||||||
{
|
{
|
||||||
IDrawController controller = queue.GetController(DbBaseCommands.Instance);
|
IDrawController controller = queue.GetController(DbBaseCommands.Instance);
|
||||||
SizeF size = Typesetter.MeasureString(font, text);
|
controller.EnsureBounds(new Box2d(position.X, position.Y, position.X, position.Y), position.Z);
|
||||||
controller.EnsureBounds(new Box2d(position.X, position.Y, position.X + size.Width, position.Y + size.Height), position.Z);
|
|
||||||
controller.Write(TextExtension.Instance.TextCommand, new TextCommandArgs(font, textBrush, anchor, position, text)
|
controller.Write(TextExtension.Instance.TextCommand, new TextCommandArgs(font, textBrush, anchor, position, text)
|
||||||
{
|
{
|
||||||
BorderBrush = borderBrush,
|
BorderBrush = borderBrush,
|
||||||
|
@ -19,34 +19,4 @@ namespace Dashboard.Drawing
|
|||||||
public FontSlant Slant { get; }
|
public FontSlant Slant { get; }
|
||||||
public FontStretch Stretch { get; }
|
public FontStretch Stretch { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct NamedFont : IFont
|
|
||||||
{
|
|
||||||
public IDrawExtension Kind { get; } = Instance;
|
|
||||||
|
|
||||||
public string Family { get; }
|
|
||||||
public float Size { get; }
|
|
||||||
public FontWeight Weight { get; }
|
|
||||||
public FontSlant Slant { get; }
|
|
||||||
public FontStretch Stretch { get; }
|
|
||||||
|
|
||||||
public NamedFont(string family, float size, FontWeight weight = FontWeight.Normal,
|
|
||||||
FontSlant slant = FontSlant.Normal, FontStretch stretch = FontStretch.Normal)
|
|
||||||
{
|
|
||||||
Family = family;
|
|
||||||
Size = size;
|
|
||||||
Weight = weight;
|
|
||||||
Slant = slant;
|
|
||||||
Stretch = Stretch;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static readonly IDrawExtension Instance = new Extension();
|
|
||||||
|
|
||||||
private class Extension : DrawExtension
|
|
||||||
{
|
|
||||||
public Extension() : base("DB_Font_Named", [FontExtension.Instance])
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,104 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.IO;
|
|
||||||
using System.Reflection.PortableExecutable;
|
|
||||||
|
|
||||||
namespace Dashboard.Drawing
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Interface for registered typesetters.
|
|
||||||
/// </summary>
|
|
||||||
public interface ITypeSetter
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Name of the typesetter.
|
|
||||||
/// </summary>
|
|
||||||
string Name { get; }
|
|
||||||
|
|
||||||
SizeF MeasureString(IFont font, string value);
|
|
||||||
|
|
||||||
IFont LoadFont(Stream stream);
|
|
||||||
IFont LoadFont(string path);
|
|
||||||
IFont LoadFont(NamedFont font);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Class for typesetting related functions.
|
|
||||||
/// </summary>
|
|
||||||
public static class Typesetter
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The typesetting backend for this instance.
|
|
||||||
/// </summary>
|
|
||||||
public static ITypeSetter Backend { get; set; } = new UndefinedTypeSetter();
|
|
||||||
|
|
||||||
public static string Name => Backend.Name;
|
|
||||||
|
|
||||||
public static SizeF MeasureString(IFont font, string value)
|
|
||||||
{
|
|
||||||
return Backend.MeasureString(font, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IFont LoadFont(Stream stream)
|
|
||||||
{
|
|
||||||
return Backend.LoadFont(stream);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IFont LoadFont(string path)
|
|
||||||
{
|
|
||||||
return Backend.LoadFont(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IFont LoadFont(FileInfo file)
|
|
||||||
{
|
|
||||||
return Backend.LoadFont(file.FullName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IFont LoadFont(NamedFont font)
|
|
||||||
{
|
|
||||||
return Backend.LoadFont(font);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IFont LoadFont(string family, float size, FontWeight weight = FontWeight.Normal,
|
|
||||||
FontSlant slant = FontSlant.Normal, FontStretch stretch = FontStretch.Normal)
|
|
||||||
{
|
|
||||||
return LoadFont(new NamedFont(family, size, weight, slant, stretch));
|
|
||||||
}
|
|
||||||
|
|
||||||
private class UndefinedTypeSetter : ITypeSetter
|
|
||||||
{
|
|
||||||
public string Name { get; } = "Undefined";
|
|
||||||
|
|
||||||
[DoesNotReturn]
|
|
||||||
private void Except()
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("No typesetting backend is loaded.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public SizeF MeasureString(IFont font, string value)
|
|
||||||
{
|
|
||||||
Except();
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IFont LoadFont(Stream stream)
|
|
||||||
{
|
|
||||||
Except();
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IFont LoadFont(string path)
|
|
||||||
{
|
|
||||||
Except();
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IFont LoadFont(NamedFont font)
|
|
||||||
{
|
|
||||||
Except();
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +1,6 @@
|
|||||||
using Dashboard.Drawing;
|
using Dashboard.Drawing;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using Dashboard;
|
|
||||||
using Dashboard.Drawing.OpenGL;
|
using Dashboard.Drawing.OpenGL;
|
||||||
using Dashboard.Drawing.OpenGL.Text;
|
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using OpenTK.Platform;
|
using OpenTK.Platform;
|
||||||
using OpenTK.Graphics.OpenGL;
|
using OpenTK.Graphics.OpenGL;
|
||||||
@ -98,10 +96,6 @@ TK.Window.SetMode(wnd, WindowMode.Normal);
|
|||||||
|
|
||||||
List<Vector3> points = new List<Vector3>();
|
List<Vector3> points = new List<Vector3>();
|
||||||
|
|
||||||
IFont font = Typesetter.LoadFont("Nimbus Mono", 12f);
|
|
||||||
|
|
||||||
queue.Text(new sys.Vector3(96, 96, 0), bg, "Hello World!", font);
|
|
||||||
queue.Text(new sys.Vector3(128, 12, 0), bg, "japenis too! uwa ~~~ アホ", font);
|
|
||||||
queue.Line(new sys.Vector2(64, 256), new sys.Vector2(64+256, 256), 0, 64f, fg);
|
queue.Line(new sys.Vector2(64, 256), new sys.Vector2(64+256, 256), 0, 64f, fg);
|
||||||
queue.Rect(new sys.Vector2(16, 16), new sys.Vector2(96, 96), 0, fg, bg, 8f);
|
queue.Rect(new sys.Vector2(16, 16), new sys.Vector2(96, 96), 0, fg, bg, 8f);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user