2024-12-13 19:57:07 +01:00
|
|
|
|
using Dashboard.Drawing;
|
|
|
|
|
using System.Drawing;
|
2025-01-14 18:34:47 +01:00
|
|
|
|
using Dashboard.Drawing.OpenGL;
|
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
using OpenTK.Platform;
|
|
|
|
|
using OpenTK.Graphics.OpenGL;
|
|
|
|
|
using OpenTK.Mathematics;
|
|
|
|
|
using TK = OpenTK.Platform.Toolkit;
|
|
|
|
|
using Vector3 = System.Numerics.Vector3;
|
2024-12-13 19:57:07 +01:00
|
|
|
|
|
2025-01-14 18:34:47 +01:00
|
|
|
|
TK.Init(new ToolkitOptions()
|
|
|
|
|
{
|
|
|
|
|
ApplicationName = "Dashboard Test Application",
|
|
|
|
|
Windows = new ToolkitOptions.WindowsOptions()
|
|
|
|
|
{
|
|
|
|
|
EnableVisualStyles = true,
|
|
|
|
|
IsDPIAware = true,
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
WindowHandle wnd = TK.Window.Create(new OpenGLGraphicsApiHints()
|
|
|
|
|
{
|
|
|
|
|
Version = new Version(3, 2),
|
|
|
|
|
ForwardCompatibleFlag = true,
|
|
|
|
|
DebugFlag = true,
|
|
|
|
|
Profile = OpenGLProfile.Core,
|
|
|
|
|
sRGBFramebuffer = true,
|
|
|
|
|
|
|
|
|
|
SwapMethod = ContextSwapMethod.Undefined,
|
|
|
|
|
|
|
|
|
|
RedColorBits = 8,
|
|
|
|
|
GreenColorBits = 8,
|
|
|
|
|
BlueColorBits = 8,
|
|
|
|
|
AlphaColorBits = 8,
|
|
|
|
|
|
|
|
|
|
SupportTransparentFramebufferX11 = true,
|
|
|
|
|
});
|
|
|
|
|
TK.Window.SetTitle(wnd, "Dashboard Test Application");
|
|
|
|
|
TK.Window.SetMinClientSize(wnd, 300, 200);
|
|
|
|
|
TK.Window.SetClientSize(wnd, new Vector2i(320, 240));
|
|
|
|
|
TK.Window.SetBorderStyle(wnd, WindowBorderStyle.ResizableBorder);
|
2024-12-13 19:57:07 +01:00
|
|
|
|
|
2025-01-14 18:34:47 +01:00
|
|
|
|
OpenGLContextHandle context = TK.OpenGL.CreateFromWindow(wnd);
|
|
|
|
|
|
|
|
|
|
TK.OpenGL.SetCurrentContext(context);
|
|
|
|
|
TK.OpenGL.SetSwapInterval(1);
|
|
|
|
|
|
|
|
|
|
GLLoader.LoadBindings(new Pal2BindingsContext(TK.OpenGL, context));
|
|
|
|
|
|
|
|
|
|
DrawQueue queue = new DrawQueue();
|
2024-12-14 17:46:56 +01:00
|
|
|
|
SolidBrush fg = new SolidBrush(Color.Black);
|
|
|
|
|
SolidBrush bg = new SolidBrush(Color.White);
|
2025-01-14 18:34:47 +01:00
|
|
|
|
bool shouldExit = false;
|
2024-12-14 17:46:56 +01:00
|
|
|
|
|
2025-01-14 18:34:47 +01:00
|
|
|
|
GLEngine engine = new GLEngine();
|
|
|
|
|
engine.Initialize();
|
2024-12-13 19:57:07 +01:00
|
|
|
|
|
2025-01-14 18:34:47 +01:00
|
|
|
|
GlContext dbGlContext = new GlContext(wnd, context);
|
|
|
|
|
ContextExecutor executor = engine.GetExecutor(dbGlContext);
|
|
|
|
|
|
|
|
|
|
EventQueue.EventRaised += (handle, type, eventArgs) =>
|
2024-12-14 18:44:27 +01:00
|
|
|
|
{
|
2025-01-14 18:34:47 +01:00
|
|
|
|
if (handle != wnd)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case PlatformEventType.Close:
|
|
|
|
|
shouldExit = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TK.Window.SetMode(wnd, WindowMode.Normal);
|
2024-12-14 18:44:27 +01:00
|
|
|
|
|
2025-01-14 18:34:47 +01:00
|
|
|
|
while (!shouldExit)
|
|
|
|
|
{
|
|
|
|
|
TK.Window.ProcessEvents(true);
|
|
|
|
|
|
|
|
|
|
TK.Window.GetFramebufferSize(wnd, out Vector2i framebufferSize);
|
|
|
|
|
|
|
|
|
|
queue.Clear();
|
|
|
|
|
queue.Point(Vector3.Zero, 2f, fg);
|
|
|
|
|
queue.Line(Vector3.Zero, Vector3.One * 2, 2f, bg);
|
|
|
|
|
queue.Rect(Vector3.UnitX, 2 * Vector3.UnitX + Vector3.UnitY, fg, bg, 2f);
|
|
|
|
|
|
|
|
|
|
GL.Viewport(0, 0, framebufferSize.X, framebufferSize.Y);
|
|
|
|
|
GL.ClearColor(0.3f, 0.3f, 0.3f, 1.0f);
|
|
|
|
|
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
|
|
|
|
|
|
|
|
|
executor.Draw(queue);
|
|
|
|
|
executor.EndFrame();
|
|
|
|
|
|
|
|
|
|
TK.OpenGL.SwapBuffers(context);
|
2024-12-14 18:44:27 +01:00
|
|
|
|
}
|
|
|
|
|
|
2025-01-14 18:34:47 +01:00
|
|
|
|
class GlContext : IGLContext
|
|
|
|
|
{
|
|
|
|
|
public WindowHandle Window { get; }
|
|
|
|
|
public OpenGLContextHandle Context { get; }
|
|
|
|
|
public int ContextGroup { get; } = -1;
|
|
|
|
|
|
|
|
|
|
public Size FramebufferSize
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
TK.Window.GetFramebufferSize(Window, out Vector2i framebufferSize);
|
|
|
|
|
return new Size(framebufferSize.X, framebufferSize.Y);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public event Action? Disposed;
|
|
|
|
|
|
|
|
|
|
public GlContext(WindowHandle window, OpenGLContextHandle context)
|
|
|
|
|
{
|
|
|
|
|
Window = window;
|
|
|
|
|
Context = context;
|
|
|
|
|
|
|
|
|
|
OpenGLContextHandle? shared = TK.OpenGL.GetSharedContext(context);
|
|
|
|
|
if (shared != null)
|
|
|
|
|
{
|
|
|
|
|
ContextGroup = _contexts.IndexOf(shared);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_contexts.Add(context);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static readonly List<OpenGLContextHandle> _contexts = new List<OpenGLContextHandle>();
|
|
|
|
|
}
|