From 695dcd4d6055438f3146dfe3e18b9da8f8313cbf Mon Sep 17 00:00:00 2001 From: Virgile Bello Date: Fri, 20 May 2016 12:52:33 +0900 Subject: [PATCH 1/3] Egl & Cocoa: Don't change context when creating/deleting them --- Source/OpenTK/Platform/Egl/EglContext.cs | 5 ++--- Source/OpenTK/Platform/MacOS/CocoaContext.cs | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Source/OpenTK/Platform/Egl/EglContext.cs b/Source/OpenTK/Platform/Egl/EglContext.cs index 07673d35..18b33717 100644 --- a/Source/OpenTK/Platform/Egl/EglContext.cs +++ b/Source/OpenTK/Platform/Egl/EglContext.cs @@ -98,8 +98,6 @@ namespace OpenTK.Platform.Egl int[] attrib_list = new int[] { Egl.CONTEXT_CLIENT_VERSION, major, Egl.NONE }; HandleAsEGLContext = Egl.CreateContext(window.Display, config, shared != null ? shared.HandleAsEGLContext : IntPtr.Zero, attrib_list); - - MakeCurrent(window); } public EglContext(ContextHandle handle, EglWindowInfo window, IGraphicsContext sharedContext, @@ -199,7 +197,8 @@ namespace OpenTK.Platform.Egl { if (manual) { - Egl.MakeCurrent(WindowInfo.Display, WindowInfo.Surface, WindowInfo.Surface, IntPtr.Zero); + if (IsCurrent) + Egl.MakeCurrent(WindowInfo.Display, WindowInfo.Surface, WindowInfo.Surface, IntPtr.Zero); Egl.DestroyContext(WindowInfo.Display, HandleAsEGLContext); } IsDisposed = true; diff --git a/Source/OpenTK/Platform/MacOS/CocoaContext.cs b/Source/OpenTK/Platform/MacOS/CocoaContext.cs index 58dcec2d..5ae0c789 100644 --- a/Source/OpenTK/Platform/MacOS/CocoaContext.cs +++ b/Source/OpenTK/Platform/MacOS/CocoaContext.cs @@ -143,7 +143,6 @@ namespace OpenTK Mode = GetGraphicsMode(context); Update(cocoaWindow); - MakeCurrent(cocoaWindow); } private IntPtr SelectPixelFormat(GraphicsMode mode, int majorVersion, int minorVersion) @@ -336,7 +335,8 @@ namespace OpenTK if (!NSApplication.IsUIThread) return; - Cocoa.SendVoid(NSOpenGLContext, Selector.Get("clearCurrentContext")); + if (IsCurrent) + Cocoa.SendVoid(NSOpenGLContext, Selector.Get("clearCurrentContext")); Cocoa.SendVoid(Handle.Handle, Selector.Get("clearDrawable")); Cocoa.SendVoid(Handle.Handle, Selector.Get("release")); From 623cfa7e9d16d9f2ff28d9af707f6eb4b5d3423c Mon Sep 17 00:00:00 2001 From: Virgile Bello Date: Fri, 20 May 2016 12:53:21 +0900 Subject: [PATCH 2/3] Egl: Unset context when calling MakeCurrent(null) --- Source/OpenTK/Platform/Egl/EglContext.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Source/OpenTK/Platform/Egl/EglContext.cs b/Source/OpenTK/Platform/Egl/EglContext.cs index 18b33717..9312ad81 100644 --- a/Source/OpenTK/Platform/Egl/EglContext.cs +++ b/Source/OpenTK/Platform/Egl/EglContext.cs @@ -126,9 +126,16 @@ namespace OpenTK.Platform.Egl // trying to make the EglContext current on a non-EGL window will do, // nothing (the EglContext will remain current on the previous EGL window // or the window it was constructed on (which may not be EGL)). - if (window is EglWindowInfo) - WindowInfo = (EglWindowInfo)window; - Egl.MakeCurrent(WindowInfo.Display, WindowInfo.Surface, WindowInfo.Surface, HandleAsEGLContext); + if (window != null) + { + if (window is EglWindowInfo) + WindowInfo = (EglWindowInfo) window; + Egl.MakeCurrent(WindowInfo.Display, WindowInfo.Surface, WindowInfo.Surface, HandleAsEGLContext); + } + else + { + Egl.MakeCurrent(WindowInfo.Display, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); + } } public override bool IsCurrent From 1652cf0d237b7db6c088ee3be5029ddf17ed1afe Mon Sep 17 00:00:00 2001 From: Virgile Bello Date: Fri, 20 May 2016 17:22:25 +0900 Subject: [PATCH 3/3] Egl: Fix context sharing --- Source/OpenTK/Platform/Egl/EglContext.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Source/OpenTK/Platform/Egl/EglContext.cs b/Source/OpenTK/Platform/Egl/EglContext.cs index 9312ad81..c61ec778 100644 --- a/Source/OpenTK/Platform/Egl/EglContext.cs +++ b/Source/OpenTK/Platform/Egl/EglContext.cs @@ -53,8 +53,6 @@ namespace OpenTK.Platform.Egl if (window == null) throw new ArgumentNullException("window"); - EglContext shared = (EglContext)sharedContext; - WindowInfo = window; // Select an EGLConfig that matches the desired mode. We cannot use the 'mode' @@ -97,7 +95,7 @@ namespace OpenTK.Platform.Egl window.CreateWindowSurface(config); int[] attrib_list = new int[] { Egl.CONTEXT_CLIENT_VERSION, major, Egl.NONE }; - HandleAsEGLContext = Egl.CreateContext(window.Display, config, shared != null ? shared.HandleAsEGLContext : IntPtr.Zero, attrib_list); + HandleAsEGLContext = Egl.CreateContext(window.Display, config, sharedContext != null ? (sharedContext as IGraphicsContextInternal).Context.Handle : IntPtr.Zero, attrib_list); } public EglContext(ContextHandle handle, EglWindowInfo window, IGraphicsContext sharedContext,