diff --git a/Source/OpenTK/GLContext.cs b/Source/OpenTK/GLContext.cs index e199d513..37e0ae47 100644 --- a/Source/OpenTK/GLContext.cs +++ b/Source/OpenTK/GLContext.cs @@ -19,15 +19,17 @@ namespace OpenTK { IGLContext implementation; // The actual render context implementation for the underlying platform. List dispose_queue = new List(); - bool disposed; - + + static bool share_contexts = true; + static object context_lock = new object(); static Dictionary available_contexts = new Dictionary(); // Contains all available OpenGL contexts. //delegate IntPtr GetCurrentContextDelegate(); //static GetCurrentContextDelegate StaticGetCurrentContext; + #region public GLContext(DisplayMode mode, IWindowInfo window) /// @@ -60,6 +62,20 @@ namespace OpenTK (this as IGLContextCreationHack).SetWindowHandle(window.Handle); (this as IGLContextCreationHack).SelectDisplayMode(mode, window); + if (GLContext.ShareContexts) + { + lock (context_lock) + { + // A small hack to create a shared context with the first available context. + foreach (WeakReference r in GLContext.available_contexts.Values) + { + this.CreateContext(true, (GLContext)r.Target); + return; + } + } + } + // Only reached if a shared context was not created above, or if this is the first + // context ever constructed. this.CreateContext(true, null); } @@ -104,6 +120,18 @@ namespace OpenTK #endregion + #region public static bool ShareContexts + + /// Gets or sets a System.Boolean, indicating whether GLContexts are shared + /// + /// If ShareContexts is true, new GLContexts will share resources. If this value is + /// false, new GLContexts will not share resources. + /// Changing this value will not affect already created GLContexts. + /// + public static bool ShareContexts { get { return share_contexts; } set { share_contexts = value; } } + + #endregion + #endregion #region --- IGLContext Members ---