2009-02-22 10:43:35 +00:00
|
|
|
|
#region --- License ---
|
|
|
|
|
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
|
|
|
|
* See license.txt for license info
|
|
|
|
|
*
|
|
|
|
|
* Date: 12/8/2007
|
2009-07-19 17:50:41 +00:00
|
|
|
|
* Time: 6:43 <EFBFBD><EFBFBD>
|
2009-02-22 10:43:35 +00:00
|
|
|
|
*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
|
|
|
|
namespace OpenTK.Platform.Windows
|
|
|
|
|
{
|
2009-07-19 17:50:41 +00:00
|
|
|
|
internal partial class Wgl
|
2009-02-22 10:43:35 +00:00
|
|
|
|
{
|
|
|
|
|
#region --- Constructors ---
|
|
|
|
|
|
|
|
|
|
static Wgl()
|
|
|
|
|
{
|
|
|
|
|
assembly = Assembly.GetExecutingAssembly();
|
|
|
|
|
wglClass = assembly.GetType("OpenTK.Platform.Windows.Wgl");
|
|
|
|
|
delegatesClass = wglClass.GetNestedType("Delegates", BindingFlags.Static | BindingFlags.NonPublic);
|
|
|
|
|
|
2010-11-23 22:08:53 +00:00
|
|
|
|
//// Ensure core entry points are ready prior to accessing any method.
|
|
|
|
|
//// Resolves bug [#993]: "Possible bug in GraphicsContext.CreateDummyContext()"
|
|
|
|
|
//LoadAll();
|
2009-02-22 10:43:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region --- Fields ---
|
|
|
|
|
|
|
|
|
|
internal const string Library = "OPENGL32.DLL";
|
|
|
|
|
|
|
|
|
|
private static Assembly assembly;
|
|
|
|
|
private static Type wglClass;
|
|
|
|
|
private static Type delegatesClass;
|
|
|
|
|
|
|
|
|
|
private static bool rebuildExtensionList = true;
|
|
|
|
|
|
2010-11-23 22:08:53 +00:00
|
|
|
|
static readonly object SyncRoot = new object();
|
|
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region static Delegate LoadDelegate(string name, Type signature)
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a System.Delegate that can be used to call an OpenGL function, core or extension.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name">The name of the Wgl function (eg. "wglNewList")</param>
|
|
|
|
|
/// <param name="signature">The signature of the OpenGL function.</param>
|
|
|
|
|
/// <returns>
|
|
|
|
|
/// A System.Delegate that can be used to call this OpenGL function, or null if the specified
|
|
|
|
|
/// function name did not correspond to an OpenGL function.
|
|
|
|
|
/// </returns>
|
|
|
|
|
static Delegate LoadDelegate(string name, Type signature)
|
|
|
|
|
{
|
2013-11-28 22:22:35 +00:00
|
|
|
|
Delegate d = GetExtensionDelegate(name, signature);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
return d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region private static Delegate GetExtensionDelegate(string name, Type signature)
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a System.Delegate that can be used to call a dynamically exported OpenGL function.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name">The name of the OpenGL function (eg. "glNewList")</param>
|
|
|
|
|
/// <param name="signature">The signature of the OpenGL function.</param>
|
|
|
|
|
/// <returns>
|
|
|
|
|
/// A System.Delegate that can be used to call this OpenGL function or null
|
|
|
|
|
/// if the function is not available in the current OpenGL context.
|
|
|
|
|
/// </returns>
|
|
|
|
|
private static Delegate GetExtensionDelegate(string name, Type signature)
|
|
|
|
|
{
|
2013-11-28 22:22:35 +00:00
|
|
|
|
IntPtr address = GetProcAddress(name);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
|
|
if (address == IntPtr.Zero ||
|
|
|
|
|
address == new IntPtr(1) || // Workaround for buggy nvidia drivers which return
|
|
|
|
|
address == new IntPtr(2)) // 1 or 2 instead of IntPtr.Zero for some extensions.
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return Marshal.GetDelegateForFunctionPointer(address, signature);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public static void LoadAll()
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Loads all Wgl entry points, core and extensions.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void LoadAll()
|
|
|
|
|
{
|
2010-11-23 22:08:53 +00:00
|
|
|
|
lock (SyncRoot)
|
|
|
|
|
{
|
|
|
|
|
OpenTK.Platform.Utilities.LoadExtensions(typeof(Wgl));
|
|
|
|
|
}
|
2009-02-22 10:43:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public static bool Load(string function)
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Loads the given Wgl entry point.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="function">The name of the function to load.</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool Load(string function)
|
|
|
|
|
{
|
|
|
|
|
return OpenTK.Platform.Utilities.TryLoadExtension(typeof(Wgl), function);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public static partial class Arb
|
|
|
|
|
|
|
|
|
|
/// <summary>Contains ARB extensions for WGL.</summary>
|
|
|
|
|
public static partial class Arb
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if a Wgl extension is supported by the given context.
|
|
|
|
|
/// </summary>
|
2009-03-25 21:53:12 +00:00
|
|
|
|
/// <param name="context">The device context.</param>
|
2009-02-22 10:43:35 +00:00
|
|
|
|
/// <param name="ext">The extension to check.</param>
|
|
|
|
|
/// <returns>True if the extension is supported by the given context, false otherwise</returns>
|
|
|
|
|
public static bool SupportsExtension(WinGLContext context, string ext)
|
|
|
|
|
{
|
2009-11-03 23:36:37 +00:00
|
|
|
|
// We cache this locally, as another thread might create a context which doesn't support this method.
|
|
|
|
|
// The design is far from ideal, but there's no good solution to this issue as long as we are using
|
|
|
|
|
// static WGL/GL classes. Fortunately, this issue is extremely unlikely to arise in practice, as you'd
|
|
|
|
|
// have to create one accelerated and one non-accelerated context in the same application, with the
|
|
|
|
|
// non-accelerated context coming second.
|
|
|
|
|
Wgl.Delegates.GetExtensionsStringARB get = Wgl.Delegates.wglGetExtensionsStringARB;
|
|
|
|
|
|
|
|
|
|
if (get != null)
|
2009-02-22 10:43:35 +00:00
|
|
|
|
{
|
2009-11-03 23:36:37 +00:00
|
|
|
|
string[] extensions = null;
|
|
|
|
|
unsafe
|
2009-02-22 10:43:35 +00:00
|
|
|
|
{
|
2009-11-03 23:36:37 +00:00
|
|
|
|
extensions = new string((sbyte*)get(context.DeviceContext))
|
|
|
|
|
.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
}
|
2009-11-03 23:36:37 +00:00
|
|
|
|
if (extensions == null || extensions.Length == 0)
|
|
|
|
|
return false;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
2009-11-03 23:36:37 +00:00
|
|
|
|
foreach (string s in extensions)
|
|
|
|
|
if (s == ext)
|
|
|
|
|
return true;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public static partial class Ext
|
|
|
|
|
|
|
|
|
|
/// <summary>Contains EXT extensions for WGL.</summary>
|
|
|
|
|
public static partial class Ext
|
|
|
|
|
{
|
|
|
|
|
private static string[] extensions;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if a Wgl extension is supported by the given context.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ext">The extension to check.</param>
|
|
|
|
|
/// <returns>True if the extension is supported by the given context, false otherwise</returns>
|
|
|
|
|
public static bool SupportsExtension(string ext)
|
|
|
|
|
{
|
|
|
|
|
if (Wgl.Delegates.wglGetExtensionsStringEXT != null)
|
|
|
|
|
{
|
|
|
|
|
if (extensions == null || rebuildExtensionList)
|
|
|
|
|
{
|
|
|
|
|
extensions = Wgl.Ext.GetExtensionsString().Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
Array.Sort(extensions);
|
|
|
|
|
rebuildExtensionList = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Array.BinarySearch(extensions, ext) != -1;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|