Small update to LoadAll().

This commit is contained in:
the_fiddler 2007-09-21 20:36:41 +00:00
parent 980e7138d2
commit 597cc5c07f

View file

@ -243,13 +243,17 @@ namespace OpenTK.OpenGL
/// </remarks> /// </remarks>
public static void LoadAll() public static void LoadAll()
{ {
// Using reflection is more than 3 times faster than directly loading delegates on the first
// run, probably due to code generation overhead. Subsequent runs are faster with direct loading
// than with reflection, but the first time is more significant.
int supported = 0; int supported = 0;
if (delegates == null) if (delegates == null)
{ {
delegates = delegatesClass.GetFields(BindingFlags.Static | BindingFlags.NonPublic); delegates = delegatesClass.GetFields(BindingFlags.Static | BindingFlags.NonPublic);
} }
Debug.Print("GL.LoadAll(): Loading all {0} OpenGL functions.", delegates.Length); Trace.Write("GL.LoadAll(): ");
System.Diagnostics.Stopwatch time = new System.Diagnostics.Stopwatch(); System.Diagnostics.Stopwatch time = new System.Diagnostics.Stopwatch();
time.Reset(); time.Reset();
@ -262,10 +266,10 @@ namespace OpenTK.OpenGL
{ {
++supported; ++supported;
} }
f.SetValue(null, d); f.SetValue(null, d);
} }
time.Stop(); time.Stop();
Trace.WriteLine(String.Format("{0} OpenGL extensions loaded in {1} milliseconds.", supported, time.ElapsedMilliseconds)); Trace.WriteLine(String.Format("{0} OpenGL extensions loaded in {1} milliseconds.", supported, time.ElapsedMilliseconds));
time.Reset(); time.Reset();