2007-09-09 16:07:39 +00:00
|
|
|
|
#region --- License ---
|
2008-02-28 13:57:07 +00:00
|
|
|
|
/* Licensed under the MIT/X11 license.
|
|
|
|
|
* Copyright (c) 2006-2008 the OpenTK Team.
|
|
|
|
|
* This notice may not be removed from any source distribution.
|
|
|
|
|
* See license.txt for licensing detailed licensing details.
|
2007-09-09 16:07:39 +00:00
|
|
|
|
*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
2008-03-01 13:15:31 +00:00
|
|
|
|
using System.Diagnostics;
|
2007-09-09 16:07:39 +00:00
|
|
|
|
|
|
|
|
|
using OpenTK.Platform;
|
|
|
|
|
|
2008-01-31 14:22:37 +00:00
|
|
|
|
namespace OpenTK.Graphics
|
2007-09-09 16:07:39 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Represents and provides methods to manipulate an OpenGL render context.
|
|
|
|
|
/// </summary>
|
2008-03-24 13:24:32 +00:00
|
|
|
|
public sealed class GraphicsContext : IGraphicsContext, IGraphicsContextInternal
|
2007-09-09 16:07:39 +00:00
|
|
|
|
{
|
2008-01-31 13:17:42 +00:00
|
|
|
|
IGraphicsContext implementation; // The actual render context implementation for the underlying platform.
|
2007-12-09 18:15:51 +00:00
|
|
|
|
List<IDisposable> dispose_queue = new List<IDisposable>();
|
2008-01-11 20:31:59 +00:00
|
|
|
|
bool disposed;
|
2008-01-22 14:53:44 +00:00
|
|
|
|
|
|
|
|
|
static bool share_contexts = true;
|
2008-03-01 13:15:31 +00:00
|
|
|
|
static bool direct_rendering = true;
|
2008-01-22 14:53:44 +00:00
|
|
|
|
static object context_lock = new object();
|
2008-03-01 13:15:31 +00:00
|
|
|
|
// Maps OS-specific context handles to GraphicsContext weak references.
|
2008-03-03 12:44:56 +00:00
|
|
|
|
static Dictionary<ContextHandle, WeakReference> available_contexts = new Dictionary<ContextHandle, WeakReference>();
|
2007-12-09 18:15:51 +00:00
|
|
|
|
|
2008-01-31 14:39:54 +00:00
|
|
|
|
#region public GraphicsContext(DisplayMode mode, IWindowInfo window)
|
2007-09-09 16:07:39 +00:00
|
|
|
|
|
2008-03-01 13:15:31 +00:00
|
|
|
|
/// <summary>This method is obsolete.</summary>
|
2007-09-09 16:07:39 +00:00
|
|
|
|
/// <param name="mode"></param>
|
|
|
|
|
/// <param name="window"></param>
|
2008-01-31 14:39:54 +00:00
|
|
|
|
public GraphicsContext(DisplayMode mode, IWindowInfo window)
|
2008-02-28 15:28:40 +00:00
|
|
|
|
: this(mode.ToGraphicsMode(), window)
|
2008-02-28 13:57:07 +00:00
|
|
|
|
{ }
|
|
|
|
|
|
2008-03-01 13:15:31 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public GraphicsContext(GraphicsMode format, IWindowInfo window)
|
|
|
|
|
|
2008-03-03 12:44:56 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructs a new GraphicsContext with the specified format, and attaches it to the specified window.
|
|
|
|
|
/// </summary>
|
2008-03-01 13:15:31 +00:00
|
|
|
|
/// <param name="format">The OpenTK.Graphics.GraphicsMode of the GraphicsContext.</param>
|
|
|
|
|
/// <param name="window">The OpenTK.Platform.IWindowInfo to attach the GraphicsContext to.</param>
|
2008-03-24 13:24:32 +00:00
|
|
|
|
public GraphicsContext(GraphicsMode mode, IWindowInfo window)
|
2007-09-09 16:07:39 +00:00
|
|
|
|
{
|
2008-03-24 13:24:32 +00:00
|
|
|
|
bool designMode = false;
|
|
|
|
|
if (mode == null && window == null)
|
|
|
|
|
designMode = true;
|
|
|
|
|
else if (mode == null) throw new ArgumentNullException("mode", "Must be a valid GraphicsMode.");
|
|
|
|
|
else if (window == null) throw new ArgumentNullException("window", "Must point to a valid window.");
|
2008-03-01 13:15:31 +00:00
|
|
|
|
|
|
|
|
|
Debug.Print("Creating GraphicsContext.");
|
2008-04-20 17:47:26 +00:00
|
|
|
|
try
|
2008-01-22 14:53:44 +00:00
|
|
|
|
{
|
2008-04-20 17:47:26 +00:00
|
|
|
|
Debug.Indent();
|
|
|
|
|
Debug.Print("GraphicsMode: {0}", mode);
|
|
|
|
|
Debug.Print("IWindowInfo: {0}", window);
|
|
|
|
|
|
|
|
|
|
IGraphicsContext shareContext = null;
|
|
|
|
|
if (GraphicsContext.ShareContexts)
|
2008-01-22 14:53:44 +00:00
|
|
|
|
{
|
2008-04-20 17:47:26 +00:00
|
|
|
|
lock (context_lock)
|
2008-01-22 14:53:44 +00:00
|
|
|
|
{
|
2008-04-20 17:47:26 +00:00
|
|
|
|
// A small hack to create a shared context with the first available context.
|
|
|
|
|
foreach (WeakReference r in GraphicsContext.available_contexts.Values)
|
|
|
|
|
{
|
|
|
|
|
shareContext = (IGraphicsContext)r.Target;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2008-01-22 14:53:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2008-02-28 13:57:07 +00:00
|
|
|
|
|
2008-04-20 17:47:26 +00:00
|
|
|
|
if (designMode)
|
|
|
|
|
implementation = new OpenTK.Platform.DummyGLContext(mode);
|
|
|
|
|
else if (Configuration.RunningOnWindows)
|
|
|
|
|
implementation = new OpenTK.Platform.Windows.WinGLContext(mode, window, shareContext);
|
|
|
|
|
else if (Configuration.RunningOnX11)
|
|
|
|
|
implementation = new OpenTK.Platform.X11.X11GLContext(mode, window, shareContext, DirectRendering);
|
|
|
|
|
else
|
|
|
|
|
throw new PlatformNotSupportedException("Please, refer to http://www.opentk.com for more information.");
|
2008-04-04 21:08:09 +00:00
|
|
|
|
|
2008-04-20 17:47:26 +00:00
|
|
|
|
lock (context_lock)
|
|
|
|
|
{
|
|
|
|
|
available_contexts.Add((this as IGraphicsContextInternal).Context, new WeakReference(this));
|
|
|
|
|
}
|
|
|
|
|
//(implementation as IGraphicsContextInternal).LoadAll();
|
|
|
|
|
}
|
|
|
|
|
finally
|
2008-03-26 19:43:57 +00:00
|
|
|
|
{
|
2008-04-20 17:47:26 +00:00
|
|
|
|
Debug.Unindent();
|
2008-03-26 19:43:57 +00:00
|
|
|
|
}
|
2007-09-09 16:07:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-12-09 18:15:51 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2008-01-31 13:17:42 +00:00
|
|
|
|
#region void ContextDestroyed(IGraphicsContext context, EventArgs e)
|
2007-12-09 18:15:51 +00:00
|
|
|
|
|
2008-01-11 20:31:59 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handles the Destroy event.
|
|
|
|
|
/// </summary>
|
2008-01-31 13:17:42 +00:00
|
|
|
|
/// <param name="context">The OpenTK.Platform.IGraphicsContext that was destroyed.</param>
|
2008-01-11 20:31:59 +00:00
|
|
|
|
/// <param name="e">Not used.</param>
|
2008-01-31 13:17:42 +00:00
|
|
|
|
void ContextDestroyed(IGraphicsContext context, EventArgs e)
|
2007-12-09 18:15:51 +00:00
|
|
|
|
{
|
2008-01-11 20:31:59 +00:00
|
|
|
|
this.Destroy -= ContextDestroyed;
|
2008-03-03 12:44:56 +00:00
|
|
|
|
//available_contexts.Remove(((IGraphicsContextInternal)this).Context);
|
2007-12-09 18:15:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2008-01-11 20:31:59 +00:00
|
|
|
|
#region --- Public Members ---
|
2007-09-09 16:07:39 +00:00
|
|
|
|
|
2008-01-31 13:17:42 +00:00
|
|
|
|
#region public static IGraphicsContext CurrentContext
|
2007-09-09 16:07:39 +00:00
|
|
|
|
|
2008-01-11 20:31:59 +00:00
|
|
|
|
internal delegate ContextHandle GetCurrentContextDelegate();
|
|
|
|
|
internal static GetCurrentContextDelegate GetCurrentContext;
|
2007-09-09 16:07:39 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2008-01-31 13:15:17 +00:00
|
|
|
|
/// Gets or sets the current GraphicsContext in the calling thread.
|
2007-09-09 16:07:39 +00:00
|
|
|
|
/// </summary>
|
2008-01-31 14:39:54 +00:00
|
|
|
|
public static GraphicsContext CurrentContext
|
2007-09-09 16:07:39 +00:00
|
|
|
|
{
|
2008-01-11 20:31:59 +00:00
|
|
|
|
get
|
2008-04-04 21:08:09 +00:00
|
|
|
|
{
|
|
|
|
|
lock (context_lock)
|
2008-03-01 13:15:31 +00:00
|
|
|
|
{
|
2008-03-26 19:43:57 +00:00
|
|
|
|
if (available_contexts.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
ContextHandle handle = GetCurrentContext();
|
|
|
|
|
if (handle.Handle != IntPtr.Zero)
|
|
|
|
|
return (GraphicsContext)available_contexts[handle].Target;
|
|
|
|
|
}
|
2008-04-04 21:08:09 +00:00
|
|
|
|
return null;
|
2008-03-01 13:15:31 +00:00
|
|
|
|
}
|
2008-01-11 20:31:59 +00:00
|
|
|
|
}
|
2008-03-03 12:44:56 +00:00
|
|
|
|
//set
|
|
|
|
|
//{
|
|
|
|
|
// if (value != null)
|
|
|
|
|
// value.MakeCurrent();
|
|
|
|
|
// else if (CurrentContext != null)
|
|
|
|
|
// CurrentContext.IsCurrent = false;
|
|
|
|
|
//}
|
2007-09-09 16:07:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-11 20:31:59 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2008-01-22 14:53:44 +00:00
|
|
|
|
#region public static bool ShareContexts
|
|
|
|
|
|
2008-03-01 13:15:31 +00:00
|
|
|
|
/// <summary>Gets or sets a System.Boolean, indicating whether GraphicsContext resources are shared</summary>
|
2008-01-22 14:53:44 +00:00
|
|
|
|
/// <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; } }
|
|
|
|
|
|
2008-01-23 12:42:47 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2008-03-01 13:15:31 +00:00
|
|
|
|
#region public static bool DirectRendering
|
|
|
|
|
|
|
|
|
|
/// <summary>Gets or sets a System.Boolean, indicating whether GraphicsContexts will perform direct rendering.</summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// <para>
|
|
|
|
|
/// If DirectRendering is true, new contexts will be constructed with direct rendering capabilities, if possible.
|
|
|
|
|
/// If DirectRendering is false, new contexts will be constructed with indirect rendering capabilities.
|
|
|
|
|
/// </para>
|
|
|
|
|
/// <para>This property does not affect existing GraphicsContexts, unless they are recreated.</para>
|
|
|
|
|
/// <para>
|
|
|
|
|
/// This property is ignored on Operating Systems without support for indirect rendering, like Windows and OS X.
|
|
|
|
|
/// </para>
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public static bool DirectRendering
|
|
|
|
|
{
|
|
|
|
|
get { return direct_rendering; }
|
|
|
|
|
set { direct_rendering = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2008-01-23 12:42:47 +00:00
|
|
|
|
#region public static AvailableDisplayFormats
|
|
|
|
|
|
|
|
|
|
|
2008-01-22 14:53:44 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2008-01-11 20:31:59 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2008-01-31 13:17:42 +00:00
|
|
|
|
#region --- IGraphicsContext Members ---
|
2008-01-11 20:31:59 +00:00
|
|
|
|
|
2007-09-09 16:07:39 +00:00
|
|
|
|
/// <summary>
|
2008-03-24 13:24:32 +00:00
|
|
|
|
/// Creates an OpenGL context with the specified direct/indirect rendering mode and sharing state with the
|
|
|
|
|
/// specified IGraphicsContext.
|
2007-09-09 16:07:39 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="direct">Set to true for direct rendering or false otherwise.</param>
|
2008-03-24 13:24:32 +00:00
|
|
|
|
/// <param name="source">The source IGraphicsContext to share state from.</param>.
|
2007-09-09 16:07:39 +00:00
|
|
|
|
/// <remarks>
|
|
|
|
|
/// <para>
|
|
|
|
|
/// Direct rendering is the default rendering mode for OpenTK, since it can provide higher performance
|
|
|
|
|
/// in some circumastances.
|
|
|
|
|
/// </para>
|
|
|
|
|
/// <para>
|
|
|
|
|
/// The 'direct' parameter is a hint, and will ignored if the specified mode is not supported (e.g. setting
|
|
|
|
|
/// indirect rendering on Windows platforms).
|
|
|
|
|
/// </para>
|
|
|
|
|
/// </remarks>
|
2008-03-24 13:24:32 +00:00
|
|
|
|
void CreateContext(bool direct, IGraphicsContext source)
|
2007-09-09 16:07:39 +00:00
|
|
|
|
{
|
2008-01-11 20:31:59 +00:00
|
|
|
|
this.Destroy += ContextDestroyed;
|
2008-04-04 21:08:09 +00:00
|
|
|
|
|
2008-03-26 19:43:57 +00:00
|
|
|
|
lock (context_lock)
|
2008-04-04 21:08:09 +00:00
|
|
|
|
{
|
|
|
|
|
available_contexts.Add((this as IGraphicsContextInternal).Context, new WeakReference(this));
|
2008-03-26 19:43:57 +00:00
|
|
|
|
}
|
2008-03-01 13:15:31 +00:00
|
|
|
|
|
2008-02-28 13:57:07 +00:00
|
|
|
|
//OpenTK.Graphics.OpenGL.GL.Clear(OpenTK.Graphics.OpenGL.ClearBufferMask.ColorBufferBit);
|
2008-01-11 20:31:59 +00:00
|
|
|
|
//if (StaticGetCurrentContext == null)
|
|
|
|
|
// StaticGetCurrentContext = implementation.GetCurrentContext;
|
2007-09-09 16:07:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Swaps buffers on a context. This presents the rendered scene to the user.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void SwapBuffers()
|
|
|
|
|
{
|
|
|
|
|
implementation.SwapBuffers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2008-03-03 12:44:56 +00:00
|
|
|
|
/// Makes the GraphicsContext the current rendering target.
|
2007-09-09 16:07:39 +00:00
|
|
|
|
/// </summary>
|
2008-03-03 12:44:56 +00:00
|
|
|
|
/// <param name="info">A System.Platform.IWindowInfo structure for the window this context is bound to.</param>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// You can use this method to bind the GraphicsContext to a different window than the one it was created from.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public void MakeCurrent(IWindowInfo info)
|
2007-09-09 16:07:39 +00:00
|
|
|
|
{
|
2008-03-03 12:44:56 +00:00
|
|
|
|
implementation.MakeCurrent(info);
|
2007-09-09 16:07:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-12-09 18:15:51 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a System.Boolean indicating whether this Context is current in the calling thread.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsCurrent
|
|
|
|
|
{
|
|
|
|
|
get { return implementation.IsCurrent; }
|
2008-03-03 12:44:56 +00:00
|
|
|
|
//set { implementation.IsCurrent = value; }
|
2007-12-09 18:15:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2008-01-11 20:31:59 +00:00
|
|
|
|
/// Raised when a Context is destroyed.
|
2007-12-09 18:15:51 +00:00
|
|
|
|
/// </summary>
|
2008-01-31 13:17:42 +00:00
|
|
|
|
public event DestroyEvent<IGraphicsContext> Destroy
|
2007-12-09 18:15:51 +00:00
|
|
|
|
{
|
2008-01-11 20:31:59 +00:00
|
|
|
|
add { implementation.Destroy += value; }
|
|
|
|
|
remove { implementation.Destroy -= value; }
|
2007-12-09 18:15:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2008-01-11 20:31:59 +00:00
|
|
|
|
/// Gets or sets a value indicating whether VSync is enabled.
|
2007-12-09 18:15:51 +00:00
|
|
|
|
/// </summary>
|
2008-01-11 20:31:59 +00:00
|
|
|
|
public bool VSync
|
2007-12-09 18:15:51 +00:00
|
|
|
|
{
|
2008-01-11 20:31:59 +00:00
|
|
|
|
get { return implementation.VSync; }
|
|
|
|
|
set { implementation.VSync = value; }
|
2007-12-09 18:15:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-11 20:31:59 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region --- IGLContextInternal Members ---
|
|
|
|
|
|
2008-03-01 13:15:31 +00:00
|
|
|
|
#region void LoadAll()
|
|
|
|
|
|
|
|
|
|
void IGraphicsContextInternal.LoadAll()
|
|
|
|
|
{
|
|
|
|
|
(implementation as IGraphicsContextInternal).LoadAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <internal />
|
|
|
|
|
/// <summary>Gets a handle to the OpenGL rendering context.</summary>
|
|
|
|
|
ContextHandle IGraphicsContextInternal.Context
|
2007-09-09 16:07:39 +00:00
|
|
|
|
{
|
2008-03-01 13:15:31 +00:00
|
|
|
|
get { return ((IGraphicsContextInternal)implementation).Context; }
|
2007-09-09 16:07:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-03-03 12:44:56 +00:00
|
|
|
|
/*
|
2007-09-09 16:07:39 +00:00
|
|
|
|
/// <summary>
|
2008-01-11 20:31:59 +00:00
|
|
|
|
/// Gets the IWindowInfo describing the window associated with this context.
|
2007-09-09 16:07:39 +00:00
|
|
|
|
/// </summary>
|
2008-03-01 13:15:31 +00:00
|
|
|
|
IWindowInfo IGraphicsContextInternal.Info
|
2007-09-09 16:07:39 +00:00
|
|
|
|
{
|
2008-03-01 13:15:31 +00:00
|
|
|
|
get { return (implementation as IGraphicsContextInternal).Info; }
|
2008-01-11 20:31:59 +00:00
|
|
|
|
//internal set { (implementation as IGLContextInternal).Info = value; }
|
2007-09-09 16:07:39 +00:00
|
|
|
|
}
|
2008-03-03 12:44:56 +00:00
|
|
|
|
*/
|
2007-09-09 16:07:39 +00:00
|
|
|
|
|
2007-09-29 15:24:55 +00:00
|
|
|
|
/// <summary>
|
2008-01-11 20:31:59 +00:00
|
|
|
|
/// Gets the DisplayMode of the context.
|
2007-09-29 15:24:55 +00:00
|
|
|
|
/// </summary>
|
2008-03-01 13:15:31 +00:00
|
|
|
|
GraphicsMode IGraphicsContextInternal.GraphicsMode
|
2007-09-29 15:24:55 +00:00
|
|
|
|
{
|
2008-03-01 13:15:31 +00:00
|
|
|
|
get { return (implementation as IGraphicsContextInternal).GraphicsMode; }
|
2008-01-11 20:31:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-31 13:15:17 +00:00
|
|
|
|
///// <summary>
|
|
|
|
|
///// Gets a System.IntPtr containing the handle to the OpenGL context which is current in the
|
|
|
|
|
///// calling thread, or IntPtr.Zero if no OpenGL context is current.
|
|
|
|
|
///// </summary>
|
|
|
|
|
///// <returns>A System.IntPtr that holds the handle to the current OpenGL context.</returns>
|
|
|
|
|
//ContextHandle IGLContextInternal.GetCurrentContext()
|
|
|
|
|
//{
|
|
|
|
|
// return (implementation as IGLContextInternal).GetCurrentContext();
|
|
|
|
|
//}
|
2007-09-29 15:24:55 +00:00
|
|
|
|
|
2007-12-09 18:15:51 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Registers an OpenGL resource for disposal.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="resource">The OpenGL resource to dispose.</param>
|
2008-03-01 13:15:31 +00:00
|
|
|
|
void IGraphicsContextInternal.RegisterForDisposal(IDisposable resource)
|
2007-12-09 18:15:51 +00:00
|
|
|
|
{
|
|
|
|
|
GC.KeepAlive(resource);
|
|
|
|
|
dispose_queue.Add(resource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Disposes all registered OpenGL resources.
|
|
|
|
|
/// </summary>
|
2008-03-01 13:15:31 +00:00
|
|
|
|
void IGraphicsContextInternal.DisposeResources()
|
2007-12-09 18:15:51 +00:00
|
|
|
|
{
|
|
|
|
|
foreach (IDisposable resource in dispose_queue)
|
|
|
|
|
resource.Dispose();
|
2008-01-11 20:31:59 +00:00
|
|
|
|
|
2007-12-09 18:15:51 +00:00
|
|
|
|
dispose_queue.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-11 20:31:59 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the address of an OpenGL extension function.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="function">The name of the OpenGL function (e.g. "glGetString")</param>
|
|
|
|
|
/// <returns>
|
|
|
|
|
/// A pointer to the specified function or IntPtr.Zero if the function isn't
|
|
|
|
|
/// available in the current opengl context.
|
|
|
|
|
/// </returns>
|
|
|
|
|
/// <see cref="Marshal.GetDelegateForFunctionPointer"/>
|
2008-03-01 13:15:31 +00:00
|
|
|
|
IntPtr IGraphicsContextInternal.GetAddress(string function)
|
2008-01-11 20:31:59 +00:00
|
|
|
|
{
|
2008-03-01 13:15:31 +00:00
|
|
|
|
return (implementation as IGraphicsContextInternal).GetAddress(function);
|
2008-01-11 20:31:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-09 16:07:39 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2008-01-11 20:31:59 +00:00
|
|
|
|
#region --- IDisposable Members ---
|
2007-09-09 16:07:39 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2008-01-31 14:39:54 +00:00
|
|
|
|
/// Disposes of the GraphicsContext.
|
2007-09-09 16:07:39 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
2008-01-11 20:31:59 +00:00
|
|
|
|
this.Dispose(true);
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Dispose(bool manual)
|
|
|
|
|
{
|
|
|
|
|
if (!disposed)
|
2008-04-04 21:08:09 +00:00
|
|
|
|
{
|
|
|
|
|
Debug.WriteLine("Disposing context {0}.", (this as IGraphicsContextInternal).Context.ToString());
|
|
|
|
|
lock (context_lock)
|
2008-03-03 12:44:56 +00:00
|
|
|
|
{
|
2008-04-04 21:08:09 +00:00
|
|
|
|
available_contexts.Remove((this as IGraphicsContextInternal).Context);
|
|
|
|
|
}
|
2008-03-03 12:44:56 +00:00
|
|
|
|
|
2008-03-26 19:43:57 +00:00
|
|
|
|
if (manual)
|
|
|
|
|
{
|
2008-02-28 13:57:07 +00:00
|
|
|
|
if (implementation != null)
|
|
|
|
|
implementation.Dispose();
|
2008-03-03 12:44:56 +00:00
|
|
|
|
}
|
2008-01-20 19:00:03 +00:00
|
|
|
|
disposed = true;
|
2008-01-11 20:31:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-26 19:43:57 +00:00
|
|
|
|
//~GraphicsContext()
|
|
|
|
|
//{
|
|
|
|
|
// this.Dispose(false);
|
|
|
|
|
//}
|
2007-09-09 16:07:39 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
2008-01-23 00:20:02 +00:00
|
|
|
|
|
2008-03-03 12:44:56 +00:00
|
|
|
|
#region public class GraphicsException : Exception
|
|
|
|
|
|
2008-01-23 00:20:02 +00:00
|
|
|
|
/// <summary>Represents errors related to Graphics operations.</summary>
|
|
|
|
|
public class GraphicsException : Exception
|
|
|
|
|
{
|
2008-03-03 12:44:56 +00:00
|
|
|
|
/// <summary>Constructs a new GraphicsException.</summary>
|
2008-01-23 00:20:02 +00:00
|
|
|
|
public GraphicsException() : base() { }
|
2008-03-03 12:44:56 +00:00
|
|
|
|
/// <summary>Constructs a new GraphicsException with the specified excpetion message.</summary>
|
|
|
|
|
/// <param name="message"></param>
|
2008-01-23 00:20:02 +00:00
|
|
|
|
public GraphicsException(string message) : base(message) { }
|
|
|
|
|
}
|
2008-03-03 12:44:56 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
2008-04-04 21:08:09 +00:00
|
|
|
|
}
|