Bugfix: Creating a second GraphicsContext forced context sharing.
authorJonas Boesch <jonas.boesch@phonak.com>
Tue, 21 Apr 2015 14:09:48 +0000 (16:09 +0200)
committerManuel Zanin <manuel.zanin@sonova.com>
Mon, 28 Nov 2016 11:21:18 +0000 (12:21 +0100)
This fix will keep existing behavior (forced sharing) in the default case, but adds a new constructor that allows explicitly specifying the shared context. A user can now explicitly specify null for the shared context to get a new non-shared context.

src/OpenTK/Graphics/GraphicsContext.cs

index da3c9f6..62613c7 100644 (file)
@@ -97,6 +97,23 @@ namespace OpenTK.Graphics
         /// Different hardware supports different flags, major and minor versions. Invalid parameters will be silently ignored.
         /// </remarks>
         public GraphicsContext(GraphicsMode mode, IWindowInfo window, int major, int minor, GraphicsContextFlags flags)
+            : this(mode, window, FindSharedContext(), major, minor, flags)
+        {
+        }
+
+        /// <summary>
+        /// Constructs a new GraphicsContext with the specified GraphicsMode, version and flags,  and attaches it to the specified window.
+        /// </summary>
+        /// <param name="mode">The OpenTK.Graphics.GraphicsMode of the GraphicsContext.</param>
+        /// <param name="window">The OpenTK.Platform.IWindowInfo to attach the GraphicsContext to.</param>
+        /// <param name="shareContext">The GraphicsContext to share resources with, or null for explicit non-sharing.</param>
+        /// <param name="major">The major version of the new GraphicsContext.</param>
+        /// <param name="minor">The minor version of the new GraphicsContext.</param>
+        /// <param name="flags">The GraphicsContextFlags for the GraphicsContext.</param>
+        /// <remarks>
+        /// Different hardware supports different flags, major and minor versions. Invalid parameters will be silently ignored.
+        /// </remarks>
+        public GraphicsContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, int major, int minor, GraphicsContextFlags flags)
         {
             lock (SyncRoot)
             {
@@ -133,8 +150,6 @@ namespace OpenTK.Graphics
                     Debug.Print("GraphicsContextFlags: {0}", flags);
                     Debug.Print("Requested version: {0}.{1}", major, minor);
 
-                    IGraphicsContext shareContext = FindSharedContext();
-                    
                     // Todo: Add a DummyFactory implementing IPlatformFactory.
                     if (designMode)
                     {