2009-02-22 10:43:35 +00:00
|
|
|
|
#region --- License ---
|
|
|
|
|
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
|
|
|
|
* See license.txt for license info
|
|
|
|
|
*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
|
|
|
|
|
namespace OpenTK.Platform.X11
|
|
|
|
|
{
|
2009-10-07 10:44:45 +00:00
|
|
|
|
partial class Glx : BindingsBase
|
2009-02-22 10:43:35 +00:00
|
|
|
|
{
|
2009-03-07 07:14:52 +00:00
|
|
|
|
const string Library = "libGL.so.1";
|
2009-11-03 23:26:57 +00:00
|
|
|
|
static readonly object sync_root = new object();
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
2013-11-09 17:50:53 +00:00
|
|
|
|
static Glx()
|
|
|
|
|
{
|
|
|
|
|
// GLX entry points are not bound to a context.
|
|
|
|
|
// This means we can load them without creating
|
|
|
|
|
// a context first! (unlike WGL)
|
|
|
|
|
// See
|
|
|
|
|
// for more details.
|
|
|
|
|
Debug.WriteLine("Loading GLX entry points.");
|
|
|
|
|
new Glx().LoadEntryPoints();
|
|
|
|
|
}
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
2009-11-03 23:26:57 +00:00
|
|
|
|
protected override object SyncRoot
|
|
|
|
|
{
|
|
|
|
|
get { return sync_root; }
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-09 17:50:53 +00:00
|
|
|
|
protected override IntPtr GetAddress(string funcname)
|
2009-10-07 10:44:45 +00:00
|
|
|
|
{
|
2013-11-09 17:50:53 +00:00
|
|
|
|
// We must use glXGetProcAddressARB, *not*
|
|
|
|
|
// glXGetProcAddress. See comment on function
|
|
|
|
|
// signature.
|
|
|
|
|
return Glx.Arb.GetProcAddress(funcname);
|
2009-10-07 10:44:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if false
|
2009-02-22 10:43:35 +00:00
|
|
|
|
#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)
|
|
|
|
|
{
|
|
|
|
|
Delegate d;
|
2009-03-07 10:36:51 +00:00
|
|
|
|
string realName = name.ToLower().StartsWith("glx") ? name.Substring(3) : name;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
|
|
if (typeof(Glx).GetMethod(realName,
|
|
|
|
|
BindingFlags.NonPublic | BindingFlags.Static) != null)
|
|
|
|
|
d = GetExtensionDelegate(name, signature) ??
|
|
|
|
|
Delegate.CreateDelegate(signature, typeof(Glx), realName);
|
|
|
|
|
else
|
|
|
|
|
d = GetExtensionDelegate(name, signature);
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
IntPtr address = Glx.GetProcAddress(name);
|
|
|
|
|
|
|
|
|
|
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 internal static void LoadAll
|
|
|
|
|
|
2009-03-07 07:14:52 +00:00
|
|
|
|
public static void LoadAll()
|
2009-02-22 10:43:35 +00:00
|
|
|
|
{
|
|
|
|
|
OpenTK.Platform.Utilities.LoadExtensions(typeof(Glx));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2009-10-07 10:44:45 +00:00
|
|
|
|
#endif
|
2009-02-22 10:43:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|