Subversion Repositories AndroidProjects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1452 chris 1
#region --- License ---
2
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
3
 * See license.txt for license info
4
 */
5
#endregion
6
 
7
using System;
8
using System.Collections.Generic;
9
using System.Text;
10
using System.Reflection;
11
using System.Runtime.InteropServices;
12
using System.Diagnostics;
13
 
14
using OpenTK.Graphics;
15
 
16
namespace OpenTK.Platform.X11
17
{
18
    partial class Glx : BindingsBase
19
    {
20
        const string Library = "libGL.so.1";
21
        static readonly object sync_root = new object();
22
 
23
        // Disable BeforeFieldInit optimization.
24
        static Glx() { }
25
 
26
        protected override object SyncRoot
27
        {
28
            get { return sync_root; }
29
        }
30
 
31
        protected override IntPtr GetAddress (string funcname)
32
        {
33
            return Glx.GetProcAddress(funcname);
34
        }
35
 
36
#if false
37
        #region static Delegate LoadDelegate(string name, Type signature)
38
 
39
        /// <summary>
40
        /// Creates a System.Delegate that can be used to call an OpenGL function, core or extension.
41
        /// </summary>
42
        /// <param name="name">The name of the Wgl function (eg. "wglNewList")</param>
43
        /// <param name="signature">The signature of the OpenGL function.</param>
44
        /// <returns>
45
        /// A System.Delegate that can be used to call this OpenGL function, or null if the specified
46
        /// function name did not correspond to an OpenGL function.
47
        /// </returns>
48
        static Delegate LoadDelegate(string name, Type signature)
49
        {
50
            Delegate d;
51
            string realName = name.ToLower().StartsWith("glx") ? name.Substring(3) : name;
52
 
53
            if (typeof(Glx).GetMethod(realName,
54
                BindingFlags.NonPublic | BindingFlags.Static) != null)
55
                d = GetExtensionDelegate(name, signature) ??
56
                    Delegate.CreateDelegate(signature, typeof(Glx), realName);
57
            else
58
                d = GetExtensionDelegate(name, signature);
59
 
60
            return d;
61
        }
62
 
63
        #endregion
64
 
65
        #region private static Delegate GetExtensionDelegate(string name, Type signature)
66
 
67
        /// <summary>
68
        /// Creates a System.Delegate that can be used to call a dynamically exported OpenGL function.
69
        /// </summary>
70
        /// <param name="name">The name of the OpenGL function (eg. "glNewList")</param>
71
        /// <param name="signature">The signature of the OpenGL function.</param>
72
        /// <returns>
73
        /// A System.Delegate that can be used to call this OpenGL function or null
74
        /// if the function is not available in the current OpenGL context.
75
        /// </returns>
76
        private static Delegate GetExtensionDelegate(string name, Type signature)
77
        {
78
            IntPtr address = Glx.GetProcAddress(name);
79
 
80
            if (address == IntPtr.Zero ||
81
                address == new IntPtr(1) ||     // Workaround for buggy nvidia drivers which return
82
                address == new IntPtr(2))       // 1 or 2 instead of IntPtr.Zero for some extensions.
83
                return null;
84
            else
85
                return Marshal.GetDelegateForFunctionPointer(address, signature);
86
        }
87
 
88
        #endregion
89
 
90
        #region internal static void LoadAll
91
 
92
        public static void LoadAll()
93
        {
94
            OpenTK.Platform.Utilities.LoadExtensions(typeof(Glx));
95
        }
96
 
97
        #endregion
98
#endif
99
    }
100
}