* X11GLContext.cs: Remove context field in favor of GraphicsContextBase.Handle. Fixes issue 1121: "GraphicsContext fails with KeyNotFoundException on SVN trunk".
This commit is contained in:
parent
43e0e2c5e5
commit
8de1f8b0c8
1 changed files with 17 additions and 18 deletions
|
@ -20,7 +20,6 @@ namespace OpenTK.Platform.X11
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal sealed class X11GLContext : DesktopGraphicsContext
|
internal sealed class X11GLContext : DesktopGraphicsContext
|
||||||
{
|
{
|
||||||
ContextHandle context;
|
|
||||||
X11WindowInfo currentWindow;
|
X11WindowInfo currentWindow;
|
||||||
bool vsync_supported;
|
bool vsync_supported;
|
||||||
int vsync_interval;
|
int vsync_interval;
|
||||||
|
@ -100,17 +99,17 @@ namespace OpenTK.Platform.X11
|
||||||
}
|
}
|
||||||
attributes.Add(0);
|
attributes.Add(0);
|
||||||
|
|
||||||
context = new ContextHandle(Glx.Arb.CreateContextAttribs(currentWindow.Display, *fbconfigs,
|
Handle = new ContextHandle(Glx.Arb.CreateContextAttribs(currentWindow.Display, *fbconfigs,
|
||||||
shareHandle.Handle, direct, attributes.ToArray()));
|
shareHandle.Handle, direct, attributes.ToArray()));
|
||||||
|
|
||||||
if (context == ContextHandle.Zero)
|
if (Handle == ContextHandle.Zero)
|
||||||
{
|
{
|
||||||
Debug.Write(String.Format("failed. Trying direct: {0}... ", !direct));
|
Debug.Write(String.Format("failed. Trying direct: {0}... ", !direct));
|
||||||
context = new ContextHandle(Glx.Arb.CreateContextAttribs(currentWindow.Display, *fbconfigs,
|
Handle = new ContextHandle(Glx.Arb.CreateContextAttribs(currentWindow.Display, *fbconfigs,
|
||||||
shareHandle.Handle, !direct, attributes.ToArray()));
|
shareHandle.Handle, !direct, attributes.ToArray()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context == ContextHandle.Zero)
|
if (Handle == ContextHandle.Zero)
|
||||||
Debug.WriteLine("failed.");
|
Debug.WriteLine("failed.");
|
||||||
else
|
else
|
||||||
Debug.WriteLine("success!");
|
Debug.WriteLine("success!");
|
||||||
|
@ -120,26 +119,26 @@ namespace OpenTK.Platform.X11
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context == ContextHandle.Zero)
|
if (Handle == ContextHandle.Zero)
|
||||||
{
|
{
|
||||||
Debug.Write("Using legacy context creation... ");
|
Debug.Write("Using legacy context creation... ");
|
||||||
|
|
||||||
XVisualInfo info = currentWindow.VisualInfo; // Cannot pass a Property by reference.
|
XVisualInfo info = currentWindow.VisualInfo; // Cannot pass a Property by reference.
|
||||||
context = new ContextHandle(Glx.CreateContext(currentWindow.Display, ref info, shareHandle.Handle, direct));
|
Handle = new ContextHandle(Glx.CreateContext(currentWindow.Display, ref info, shareHandle.Handle, direct));
|
||||||
|
|
||||||
if (context == ContextHandle.Zero)
|
if (Handle == ContextHandle.Zero)
|
||||||
{
|
{
|
||||||
Debug.WriteLine(String.Format("failed. Trying direct: {0}... ", !direct));
|
Debug.WriteLine(String.Format("failed. Trying direct: {0}... ", !direct));
|
||||||
context = new ContextHandle(Glx.CreateContext(currentWindow.Display, ref info, IntPtr.Zero, !direct));
|
Handle = new ContextHandle(Glx.CreateContext(currentWindow.Display, ref info, IntPtr.Zero, !direct));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context != ContextHandle.Zero)
|
if (Handle != ContextHandle.Zero)
|
||||||
Debug.Print("Context created (id: {0}).", context);
|
Debug.Print("Context created (id: {0}).", Handle);
|
||||||
else
|
else
|
||||||
throw new GraphicsContextException("Failed to create OpenGL context. Glx.CreateContext call returned 0.");
|
throw new GraphicsContextException("Failed to create OpenGL context. Glx.CreateContext call returned 0.");
|
||||||
|
|
||||||
if (!Glx.IsDirect(currentWindow.Display, context.Handle))
|
if (!Glx.IsDirect(currentWindow.Display, Handle.Handle))
|
||||||
Debug.Print("Warning: Context is not direct.");
|
Debug.Print("Warning: Context is not direct.");
|
||||||
|
|
||||||
graphics_mode = mode;
|
graphics_mode = mode;
|
||||||
|
@ -209,12 +208,12 @@ namespace OpenTK.Platform.X11
|
||||||
bool result;
|
bool result;
|
||||||
|
|
||||||
Debug.Write(String.Format("Making context {0} current on thread {1} (Display: {2}, Screen: {3}, Window: {4})... ",
|
Debug.Write(String.Format("Making context {0} current on thread {1} (Display: {2}, Screen: {3}, Window: {4})... ",
|
||||||
context, System.Threading.Thread.CurrentThread.ManagedThreadId, w.Display, w.Screen, w.WindowHandle));
|
Handle, System.Threading.Thread.CurrentThread.ManagedThreadId, w.Display, w.Screen, w.WindowHandle));
|
||||||
|
|
||||||
if (w.Display == IntPtr.Zero || w.WindowHandle == IntPtr.Zero || context == ContextHandle.Zero)
|
if (w.Display == IntPtr.Zero || w.WindowHandle == IntPtr.Zero || Handle == ContextHandle.Zero)
|
||||||
throw new InvalidOperationException("Invalid display, window or context.");
|
throw new InvalidOperationException("Invalid display, window or context.");
|
||||||
|
|
||||||
result = Glx.MakeCurrent(w.Display, w.WindowHandle, context);
|
result = Glx.MakeCurrent(w.Display, w.WindowHandle, Handle);
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
throw new GraphicsContextException("Failed to make context current.");
|
throw new GraphicsContextException("Failed to make context current.");
|
||||||
|
@ -229,7 +228,7 @@ namespace OpenTK.Platform.X11
|
||||||
|
|
||||||
public override bool IsCurrent
|
public override bool IsCurrent
|
||||||
{
|
{
|
||||||
get { return Glx.GetCurrentContext() == this.context.Handle; }
|
get { return Glx.GetCurrentContext() == this.Handle.Handle; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -304,10 +303,10 @@ namespace OpenTK.Platform.X11
|
||||||
if (manuallyCalled)
|
if (manuallyCalled)
|
||||||
{
|
{
|
||||||
if (GraphicsContext.CurrentContext != null &&
|
if (GraphicsContext.CurrentContext != null &&
|
||||||
((IGraphicsContextInternal)GraphicsContext.CurrentContext).Context == context)
|
((IGraphicsContextInternal)GraphicsContext.CurrentContext).Context == Handle)
|
||||||
GraphicsContext.CurrentContext.MakeCurrent(null);
|
GraphicsContext.CurrentContext.MakeCurrent(null);
|
||||||
|
|
||||||
Glx.DestroyContext(currentWindow.Display, context);
|
Glx.DestroyContext(currentWindow.Display, Handle);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue