mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-01-13 00:35:35 +00:00
Added API for OpenGL context resource sharing (GLContext.ShareContexts)
This commit is contained in:
parent
a4efc490b3
commit
fac1760c40
|
@ -19,15 +19,17 @@ namespace OpenTK
|
||||||
{
|
{
|
||||||
IGLContext implementation; // The actual render context implementation for the underlying platform.
|
IGLContext implementation; // The actual render context implementation for the underlying platform.
|
||||||
List<IDisposable> dispose_queue = new List<IDisposable>();
|
List<IDisposable> dispose_queue = new List<IDisposable>();
|
||||||
|
|
||||||
bool disposed;
|
bool disposed;
|
||||||
|
|
||||||
|
static bool share_contexts = true;
|
||||||
|
static object context_lock = new object();
|
||||||
static Dictionary<ContextHandle, WeakReference> available_contexts =
|
static Dictionary<ContextHandle, WeakReference> available_contexts =
|
||||||
new Dictionary<ContextHandle, WeakReference>(); // Contains all available OpenGL contexts.
|
new Dictionary<ContextHandle, WeakReference>(); // Contains all available OpenGL contexts.
|
||||||
|
|
||||||
//delegate IntPtr GetCurrentContextDelegate();
|
//delegate IntPtr GetCurrentContextDelegate();
|
||||||
//static GetCurrentContextDelegate StaticGetCurrentContext;
|
//static GetCurrentContextDelegate StaticGetCurrentContext;
|
||||||
|
|
||||||
|
|
||||||
#region public GLContext(DisplayMode mode, IWindowInfo window)
|
#region public GLContext(DisplayMode mode, IWindowInfo window)
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -60,6 +62,20 @@ namespace OpenTK
|
||||||
|
|
||||||
(this as IGLContextCreationHack).SetWindowHandle(window.Handle);
|
(this as IGLContextCreationHack).SetWindowHandle(window.Handle);
|
||||||
(this as IGLContextCreationHack).SelectDisplayMode(mode, window);
|
(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);
|
this.CreateContext(true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,6 +120,18 @@ namespace OpenTK
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region public static bool ShareContexts
|
||||||
|
|
||||||
|
/// <summary>Gets or sets a System.Boolean, indicating whether GLContexts are shared</summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// <para>If ShareContexts is true, new GLContexts will share resources. If this value is
|
||||||
|
/// false, new GLContexts will not share resources.</para>
|
||||||
|
/// <para>Changing this value will not affect already created GLContexts.</para>
|
||||||
|
/// </remarks>
|
||||||
|
public static bool ShareContexts { get { return share_contexts; } set { share_contexts = value; } }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region --- IGLContext Members ---
|
#region --- IGLContext Members ---
|
||||||
|
|
Loading…
Reference in a new issue