[GLControl] Use dummy context in design mode

Creating a GraphicsContext with null parameters is not a guarantee that
we will get a dummy context that does not call any OpenGL functions. We
need to explicitly define and construct a dummy context that is safe to
use inside the designer.

Affects issue #49
This commit is contained in:
Stefanos A. 2014-01-18 18:33:25 +01:00
parent b87b9e0a27
commit c2e3328f59

View file

@ -37,7 +37,7 @@ namespace OpenTK
public IGraphicsContext CreateContext(int major, int minor, GraphicsContextFlags flags)
{
return new GraphicsContext(null, null);
return new DummyContext();
}
public bool IsIdle
@ -51,5 +51,121 @@ namespace OpenTK
}
#endregion
#region class DummyContext
class DummyContext : IGraphicsContext, IGraphicsContextInternal
{
static int instance_count;
readonly ContextHandle handle = new ContextHandle(new IntPtr(
System.Threading.Interlocked.Increment(ref instance_count)));
IWindowInfo current_window;
bool is_disposed;
int swap_interval;
#region IGraphicsContext Members
public void SwapBuffers()
{
}
public void MakeCurrent(IWindowInfo window)
{
current_window = window;
}
public bool IsCurrent
{
get { return current_window != null; }
}
public bool IsDisposed
{
get { return is_disposed; }
}
public bool VSync
{
get
{
return SwapInterval != 0;
}
set
{
SwapInterval = value ? 1 : 0;
}
}
public int SwapInterval
{
get
{
return swap_interval;
}
set
{
swap_interval = value;
}
}
public void Update(IWindowInfo window)
{
}
public GraphicsMode GraphicsMode
{
get { return GraphicsMode.Default; }
}
public bool ErrorChecking
{
get
{
return false;
}
set
{
}
}
public void LoadAll()
{
}
public void Dispose()
{
is_disposed = true;
}
#endregion
#region IGraphicsContextInternal
public ContextHandle Context
{
get { return handle; }
}
public IntPtr GetAddress(IntPtr function)
{
return IntPtr.Zero;
}
public IntPtr GetAddress(string function)
{
return IntPtr.Zero;
}
public IGraphicsContext Implementation
{
get { return this; }
}
#endregion
}
#endregion
}
}