Bubble some OpenGL elements up to the DC impl.
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
using System.Numerics;
|
||||
using Dashboard.Collections;
|
||||
using Dashboard.Windowing;
|
||||
using BindingFlags = System.Reflection.BindingFlags;
|
||||
|
||||
namespace Dashboard.Pal
|
||||
{
|
||||
public abstract class DeviceContext : IContextBase<DeviceContext, IDeviceContextExtension>
|
||||
public abstract class DeviceContext : IContextBase<DeviceContext, IDeviceContextExtension>, IDeviceContext
|
||||
{
|
||||
private readonly TypeDictionary<IDeviceContextExtension> _extensions =
|
||||
new TypeDictionary<IDeviceContextExtension>(true);
|
||||
@@ -19,6 +19,9 @@ namespace Dashboard.Pal
|
||||
public abstract string DriverName { get; }
|
||||
public abstract string DriverVendor { 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; }
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Immutable;
|
||||
using System.Numerics;
|
||||
using Dashboard.Drawing;
|
||||
using Dashboard.OpenGL.Drawing;
|
||||
using Dashboard.Pal;
|
||||
@@ -27,6 +28,9 @@ namespace Dashboard.OpenGL
|
||||
public override string DriverName => "Dashboard OpenGL Device Context";
|
||||
public override string DriverVendor => "Dashboard";
|
||||
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 string GLRenderer { get; }
|
||||
@@ -39,9 +43,11 @@ namespace Dashboard.OpenGL
|
||||
private readonly ConcurrentQueue<Task> _beforeDrawActions = 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;
|
||||
SwapGroup = swap;
|
||||
|
||||
context.MakeCurrent();
|
||||
GLLoader.LoadBindings(new GLContextBindingsContext(context));
|
||||
|
||||
|
||||
@@ -14,11 +14,6 @@ namespace Dashboard.OpenGL
|
||||
/// <remarks>-1 assigns no group.</remarks>
|
||||
public int ContextGroup { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The size of the framebuffer in pixels.
|
||||
/// </summary>
|
||||
public Vector2 FramebufferSize { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Called when the context is disposed.
|
||||
/// </summary>
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace Dashboard.OpenTK.PAL2
|
||||
{
|
||||
Application = app;
|
||||
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)
|
||||
@@ -81,7 +81,8 @@ namespace Dashboard.OpenTK.PAL2
|
||||
{
|
||||
case GraphicsApi.OpenGL:
|
||||
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:
|
||||
throw new Exception($"Unknown graphics API {hints.Api}.");
|
||||
}
|
||||
@@ -146,5 +147,28 @@ namespace Dashboard.OpenTK.PAL2
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user