[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:
thefiddler 2013-12-28 01:09:59 +01:00
parent 8bcbb06f8e
commit 5cebaccfca

View file

@ -22,7 +22,8 @@ namespace OpenTK.Platform.Dummy
/// </summary>
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;
int swap_interval;
static int handle_count;
@ -31,13 +32,20 @@ namespace OpenTK.Platform.Dummy
#region --- Constructors ---
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()
{
Handle = handle;
if (handle != ContextHandle.Zero)
{
Handle = handle;
}
Loader = loader;
Mode = new GraphicsMode(new IntPtr(2), 32, 16, 0, 0, 0, 2, false);
}
@ -45,15 +53,6 @@ namespace OpenTK.Platform.Dummy
#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 MakeCurrent(IWindowInfo info)
@ -81,9 +80,15 @@ namespace OpenTK.Platform.Dummy
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
{
@ -101,7 +106,14 @@ namespace OpenTK.Platform.Dummy
{ }
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