Bubble some OpenGL elements up to the DC impl.

This commit is contained in:
2026-02-02 22:02:32 +03:00
parent 36dbcac8d9
commit 027ebe8dbd
4 changed files with 38 additions and 10 deletions

View File

@@ -1,10 +1,10 @@
using System.Numerics;
using Dashboard.Collections; using Dashboard.Collections;
using Dashboard.Windowing; using Dashboard.Windowing;
using BindingFlags = System.Reflection.BindingFlags;
namespace Dashboard.Pal namespace Dashboard.Pal
{ {
public abstract class DeviceContext : IContextBase<DeviceContext, IDeviceContextExtension> public abstract class DeviceContext : IContextBase<DeviceContext, IDeviceContextExtension>, IDeviceContext
{ {
private readonly TypeDictionary<IDeviceContextExtension> _extensions = private readonly TypeDictionary<IDeviceContextExtension> _extensions =
new TypeDictionary<IDeviceContextExtension>(true); new TypeDictionary<IDeviceContextExtension>(true);
@@ -19,6 +19,9 @@ namespace Dashboard.Pal
public abstract string DriverName { get; } public abstract string DriverName { get; }
public abstract string DriverVendor { get; } public abstract string DriverVendor { get; }
public abstract Version DriverVersion { get; } public abstract Version DriverVersion { get; }
public abstract ISwapGroup SwapGroup { get; }
public abstract Vector2 FramebufferSize { get; }
public virtual bool DoubleBuffered { get; } = false;
public bool IsDisposed { get; private set; } public bool IsDisposed { get; private set; }

View File

@@ -1,5 +1,6 @@
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Numerics;
using Dashboard.Drawing; using Dashboard.Drawing;
using Dashboard.OpenGL.Drawing; using Dashboard.OpenGL.Drawing;
using Dashboard.Pal; using Dashboard.Pal;
@@ -27,6 +28,9 @@ namespace Dashboard.OpenGL
public override string DriverName => "Dashboard OpenGL Device Context"; public override string DriverName => "Dashboard OpenGL Device Context";
public override string DriverVendor => "Dashboard"; public override string DriverVendor => "Dashboard";
public override Version DriverVersion => new Version(0, 1, 0); public override Version DriverVersion => new Version(0, 1, 0);
public override ISwapGroup SwapGroup { get; }
public override Vector2 FramebufferSize => GLContext.FramebufferSize;
public override bool DoubleBuffered { get; } = true;
public Version GLVersion { get; } public Version GLVersion { get; }
public string GLRenderer { get; } public string GLRenderer { get; }
@@ -39,9 +43,11 @@ namespace Dashboard.OpenGL
private readonly ConcurrentQueue<Task> _beforeDrawActions = new ConcurrentQueue<Task>(); private readonly ConcurrentQueue<Task> _beforeDrawActions = new ConcurrentQueue<Task>();
private readonly ConcurrentQueue<Task> _afterDrawActions = new ConcurrentQueue<Task>(); private readonly ConcurrentQueue<Task> _afterDrawActions = new ConcurrentQueue<Task>();
public GLDeviceContext(Application app, IWindow? window, IGLContext context) : base(app, window) public GLDeviceContext(Application app, IWindow? window, IGLContext context, ISwapGroup swap) : base(app, window)
{ {
GLContext = context; GLContext = context;
SwapGroup = swap;
context.MakeCurrent(); context.MakeCurrent();
GLLoader.LoadBindings(new GLContextBindingsContext(context)); GLLoader.LoadBindings(new GLContextBindingsContext(context));

View File

@@ -14,11 +14,6 @@ namespace Dashboard.OpenGL
/// <remarks>-1 assigns no group.</remarks> /// <remarks>-1 assigns no group.</remarks>
public int ContextGroup { get; } public int ContextGroup { get; }
/// <summary>
/// The size of the framebuffer in pixels.
/// </summary>
public Vector2 FramebufferSize { get; }
/// <summary> /// <summary>
/// Called when the context is disposed. /// Called when the context is disposed.
/// </summary> /// </summary>

View File

@@ -64,7 +64,7 @@ namespace Dashboard.OpenTK.PAL2
{ {
Application = app; Application = app;
WindowHandle = window; WindowHandle = window;
DeviceContext = new GLDeviceContext(app, this, new Pal2GLContext(window, context)); DeviceContext = new GLDeviceContext(app, this, new Pal2GLContext(window, context), new DummySwapGroup(context));
} }
public PhysicalWindow(Application app, GraphicsApiHints hints) public PhysicalWindow(Application app, GraphicsApiHints hints)
@@ -81,7 +81,8 @@ namespace Dashboard.OpenTK.PAL2
{ {
case GraphicsApi.OpenGL: case GraphicsApi.OpenGL:
case GraphicsApi.OpenGLES: case GraphicsApi.OpenGLES:
return new GLDeviceContext(app, window, new Pal2GLContext(handle, TK.OpenGL.CreateFromWindow(handle))); OpenGLContextHandle context = TK.OpenGL.CreateFromWindow(handle);
return new GLDeviceContext(app, window, new Pal2GLContext(handle, context), new DummySwapGroup(context));
default: default:
throw new Exception($"Unknown graphics API {hints.Api}."); throw new Exception($"Unknown graphics API {hints.Api}.");
} }
@@ -146,5 +147,28 @@ namespace Dashboard.OpenTK.PAL2
return Math.Max(x, y); return Math.Max(x, y);
} }
} }
private class DummySwapGroup(OpenGLContextHandle context) : ISwapGroup
{
public int SwapInterval
{
get
{
TK.OpenGL.SetCurrentContext(context);
return TK.OpenGL.GetSwapInterval();
}
set
{
TK.OpenGL.SetCurrentContext(context);
TK.OpenGL.SetSwapInterval(value);
}
}
public void Swap()
{
TK.OpenGL.SwapBuffers(context);
}
}
} }
} }