mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-09-13 22:27:21 +00:00
[Dummy] Improved thread-safety; added entry-point loader
DummyGLContext will now attempt to load OpenGL and OpenGL ES entry points when a suitable OpenGL context is current on the calling thread. This allows OpenTK to be used on contexts created through third-party toolkits.
This commit is contained in:
parent
8bcbb06f8e
commit
5cebaccfca
|
@ -22,7 +22,8 @@ namespace OpenTK.Platform.Dummy
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal sealed class DummyGLContext : DesktopGraphicsContext
|
internal sealed class DummyGLContext : DesktopGraphicsContext
|
||||||
{
|
{
|
||||||
// This mode is not real. To receive a real mode we'd have to create a temporary context, which is not desirable!
|
readonly GraphicsContext.GetAddressDelegate Loader;
|
||||||
|
|
||||||
bool vsync;
|
bool vsync;
|
||||||
int swap_interval;
|
int swap_interval;
|
||||||
static int handle_count;
|
static int handle_count;
|
||||||
|
@ -31,13 +32,20 @@ namespace OpenTK.Platform.Dummy
|
||||||
#region --- Constructors ---
|
#region --- Constructors ---
|
||||||
|
|
||||||
public DummyGLContext()
|
public DummyGLContext()
|
||||||
: this(new ContextHandle(new IntPtr(++handle_count)))
|
|
||||||
{
|
{
|
||||||
|
Handle = new ContextHandle(
|
||||||
|
new IntPtr(Interlocked.Increment(
|
||||||
|
ref handle_count)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public DummyGLContext(ContextHandle handle)
|
public DummyGLContext(ContextHandle handle, GraphicsContext.GetAddressDelegate loader)
|
||||||
|
: this()
|
||||||
|
{
|
||||||
|
if (handle != ContextHandle.Zero)
|
||||||
{
|
{
|
||||||
Handle = handle;
|
Handle = handle;
|
||||||
|
}
|
||||||
|
Loader = loader;
|
||||||
Mode = new GraphicsMode(new IntPtr(2), 32, 16, 0, 0, 0, 2, false);
|
Mode = new GraphicsMode(new IntPtr(2), 32, 16, 0, 0, 0, 2, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,15 +53,6 @@ namespace OpenTK.Platform.Dummy
|
||||||
|
|
||||||
#region --- IGraphicsContext Members ---
|
#region --- IGraphicsContext Members ---
|
||||||
|
|
||||||
public void CreateContext(bool direct, IGraphicsContext source)
|
|
||||||
{
|
|
||||||
if (Handle == ContextHandle.Zero)
|
|
||||||
{
|
|
||||||
++handle_count;
|
|
||||||
Handle = new ContextHandle((IntPtr)handle_count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void SwapBuffers() { }
|
public override void SwapBuffers() { }
|
||||||
|
|
||||||
public override void MakeCurrent(IWindowInfo info)
|
public override void MakeCurrent(IWindowInfo info)
|
||||||
|
@ -81,9 +80,15 @@ namespace OpenTK.Platform.Dummy
|
||||||
get { return current_thread != null && current_thread == Thread.CurrentThread; }
|
get { return current_thread != null && current_thread == Thread.CurrentThread; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IntPtr GetAddress(string function) { return IntPtr.Zero; }
|
public override IntPtr GetAddress(string function)
|
||||||
|
{
|
||||||
|
return Loader(function);
|
||||||
|
}
|
||||||
|
|
||||||
public override IntPtr GetAddress(IntPtr function) { return IntPtr.Zero; }
|
public override IntPtr GetAddress(IntPtr function)
|
||||||
|
{
|
||||||
|
return IntPtr.Zero;
|
||||||
|
}
|
||||||
|
|
||||||
public override int SwapInterval
|
public override int SwapInterval
|
||||||
{
|
{
|
||||||
|
@ -101,7 +106,14 @@ namespace OpenTK.Platform.Dummy
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
public override void LoadAll()
|
public override void LoadAll()
|
||||||
{ }
|
{
|
||||||
|
new OpenTK.Graphics.OpenGL.GL().LoadEntryPoints();
|
||||||
|
new OpenTK.Graphics.OpenGL4.GL().LoadEntryPoints();
|
||||||
|
new OpenTK.Graphics.ES10.GL().LoadEntryPoints();
|
||||||
|
new OpenTK.Graphics.ES11.GL().LoadEntryPoints();
|
||||||
|
new OpenTK.Graphics.ES20.GL().LoadEntryPoints();
|
||||||
|
new OpenTK.Graphics.ES30.GL().LoadEntryPoints();
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue