104 lines
3.4 KiB
C#
104 lines
3.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using OpenTK.Windowing.Desktop;
|
|
using OpenTK.Windowing.GraphicsLibraryFramework;
|
|
using Dashboard.CommandMachine;
|
|
using Dashboard.Media;
|
|
using Dashboard.OpenGL;
|
|
using Dashboard.PAL;
|
|
|
|
namespace Dashboard.OpenTK
|
|
{
|
|
public class OpenTKPlatform : IQuikPlatform
|
|
{
|
|
private readonly List<OpenTKPort> _ports = new List<OpenTKPort>();
|
|
|
|
// These shall remain a sad nop for now.
|
|
public string? Title { get; set; }
|
|
public QImage? Icon { get; set; } = null;
|
|
|
|
public event EventHandler? EventRaised;
|
|
|
|
public NativeWindowSettings DefaultSettings { get; set; } = NativeWindowSettings.Default;
|
|
|
|
public IReadOnlyList<OpenTKPort> Ports => _ports;
|
|
|
|
private bool IsGLInitialized = false;
|
|
|
|
public IQuikPortHandle CreatePort()
|
|
{
|
|
NativeWindow window = new NativeWindow(DefaultSettings);
|
|
OpenTKPort port = new OpenTKPort(window);
|
|
_ports.Add(port);
|
|
|
|
if (!IsGLInitialized)
|
|
{
|
|
window.Context.MakeCurrent();
|
|
GL.LoadBindings(GLFW.GetProcAddress);
|
|
IsGLInitialized = true;
|
|
}
|
|
|
|
window.Closing += (ea) =>
|
|
{
|
|
Environment.Exit(0);
|
|
};
|
|
|
|
return port;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
// FIXME: dispose pattern here!
|
|
|
|
// Copy the array to prevent collection modification exceptions.
|
|
foreach (OpenTKPort port in _ports.ToArray())
|
|
{
|
|
port.Dispose();
|
|
}
|
|
}
|
|
|
|
public void ProcessEvents(bool block)
|
|
{
|
|
NativeWindow.ProcessWindowEvents(block);
|
|
}
|
|
|
|
public void DestroyPort(IQuikPortHandle port) => ((OpenTKPort)port).Dispose();
|
|
|
|
public string PortGetTitle(IQuikPortHandle port) => ((OpenTKPort)port).Title;
|
|
|
|
public void PortSetTitle(IQuikPortHandle port, string title) => ((OpenTKPort)port).Title = title;
|
|
|
|
public QVec2 PortGetSize(IQuikPortHandle port) => ((OpenTKPort)port).Size;
|
|
|
|
public void PortSetSize(IQuikPortHandle port, QVec2 size) => ((OpenTKPort)port).Size = size;
|
|
|
|
public QVec2 PortGetPosition(IQuikPortHandle port) => ((OpenTKPort)port).Position;
|
|
|
|
public void PortSetPosition(IQuikPortHandle port, QVec2 position) => ((OpenTKPort)port).Position = position;
|
|
|
|
public bool PortIsValid(IQuikPortHandle port) => ((OpenTKPort)port).IsValid;
|
|
|
|
public void PortSubscribeEvent(IQuikPortHandle port, EventHandler handler) => ((OpenTKPort)port).EventRaised += handler;
|
|
|
|
public void PortUnsubscribeEvent(IQuikPortHandle port, EventHandler handler) => ((OpenTKPort)port).EventRaised -= handler;
|
|
|
|
public void PortFocus(IQuikPortHandle port) => ((OpenTKPort)port).Focus();
|
|
|
|
public void PortShow(IQuikPortHandle port, bool shown = true) => ((OpenTKPort)port).Show(shown);
|
|
|
|
public void PortPaint(IQuikPortHandle port, CommandList commands) => ((OpenTKPort)port).Paint(commands);
|
|
|
|
public void GetMaximumImage(out int width, out int height)
|
|
{
|
|
GL.Get(GLEnum.GL_MAX_TEXTURE_SIZE, out int value);
|
|
width = height = value;
|
|
}
|
|
|
|
public void GetMaximumImage(out int width, out int height, out int depth)
|
|
{
|
|
GetMaximumImage(out width, out height);
|
|
GL.Get(GLEnum.GL_MAX_ARRAY_TEXTURE_LAYERS, out int value);
|
|
depth = value;
|
|
}
|
|
}
|
|
} |