Improved GL loading speed.

Added background worker thread to W03_Extensions.
Added debug output to failed WinGLContext.MakeCurrent() calls.
Removed object field from Windows.MSG struct.
This commit is contained in:
the_fiddler 2007-09-03 21:47:34 +00:00
parent fe0b2c66db
commit 5e28f31660
6 changed files with 65 additions and 28 deletions

View file

@ -29,6 +29,7 @@
private void InitializeComponent()
{
this.listBox1 = new System.Windows.Forms.ListBox();
this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
this.SuspendLayout();
//
// listBox1
@ -40,6 +41,13 @@
this.listBox1.Size = new System.Drawing.Size(284, 264);
this.listBox1.TabIndex = 0;
//
// backgroundWorker1
//
this.backgroundWorker1.WorkerReportsProgress = true;
this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork);
this.backgroundWorker1.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.backgroundWorker1_RunWorkerCompleted);
this.backgroundWorker1.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.backgroundWorker1_ProgressChanged);
//
// W03_Extensions
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -55,5 +63,6 @@
#endregion
private System.Windows.Forms.ListBox listBox1;
private System.ComponentModel.BackgroundWorker backgroundWorker1;
}
}

View file

@ -26,6 +26,8 @@ namespace Examples.WinForms
Type glClass;
Type delegatesClass;
Type importsClass;
int supported, all; // Number of supported extensions.
string driver;
public W03_Extensions()
{
@ -43,48 +45,58 @@ namespace Examples.WinForms
glControl.CreateContext();
//listBox1.BeginInvoke(new LoadExtensionsDelegate(LoadExtensions));
ThreadPool.QueueUserWorkItem(new WaitCallback(LoadExtensions));
driver =
GL.GetString(GL.Enums.StringName.VENDOR) + " " +
GL.GetString(GL.Enums.StringName.RENDERER) + " " +
GL.GetString(GL.Enums.StringName.VERSION);
all = delegatesClass.GetFields(BindingFlags.Static | BindingFlags.NonPublic).Length;
this.Text = String.Format("Loading {0} functions...", all);
this.backgroundWorker1.RunWorkerAsync();
}
delegate void LoadExtensionsDelegate(object data);
void LoadExtensions(object data)
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
glControl.MakeCurrent();
FieldInfo[] v = delegatesClass.GetFields(BindingFlags.Static | BindingFlags.NonPublic);
int i = 0, supported = 0;
int i = 0;
try
{
foreach (FieldInfo f in v)
{
Delegate d = GL.GetDelegate(f.Name, f.FieldType);
f.SetValue(null, d);
listBox1.Items.Add(String.Format("{0}/{1} {2}: {3}",
(++i).ToString(), v.Length, d != null ? "ok" : "failed", f.Name));
listBox1.Update();
//Thread.Sleep(1);
object d = f.GetValue(delegatesClass);
if (d != null)
{
++supported;
}
}
//this.Text = String.Format("Supported extensions: {0}", supported);
backgroundWorker1.ReportProgress((int)(((float)i / all) * 100.0f),
String.Format("{0}/{1} {2}: {3}", (++i).ToString(), all, d != null ? "ok" : "failed", f.Name));
}
}
catch (Exception expt)
{
MessageBox.Show("An error occured while loading extensions", "Extension loading failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
MessageBox.Show(expt.ToString(), "An error occured while loading extensions", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
throw;
}
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
listBox1.Items.Add(e.UserState as string);
/*
if ((e.UserState as string).Contains("failed"))
{
Graphics c = listBox1.CreateGraphics();
c.
c.DrawRectangle(new Pen(Color.Gray), listBox1.GetItemRectangle(listBox1.Items.Count - 1));
c.Dispose();
}
else
{
}
*/
}
#region IExample Members
@ -94,5 +106,11 @@ namespace Examples.WinForms
}
#endregion
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
this.Text = String.Format("{0}: {1}/{2} OpenGL functions supported.",
driver, supported, all);
}
}
}

View file

@ -100,6 +100,7 @@ namespace OpenTK
}
this.Visible = true;
this.CreateControl();
GL.LoadAll();
Glu.LoadAll();

View file

@ -202,10 +202,12 @@ namespace OpenTK.OpenGL
/// </returns>
public static Delegate GetDelegate(string name, Type signature)
{
MethodInfo m = importsClass.GetMethod(name.Substring(2), BindingFlags.Static | BindingFlags.NonPublic);
//MethodInfo m = importsClass.GetMethod(name.Substring(2), BindingFlags.Static | BindingFlags.NonPublic);
MethodInfo m;
return
Utilities.GetExtensionDelegate(name, signature) ??
(m != null ? Delegate.CreateDelegate(signature, m) : null);
((m = importsClass.GetMethod(name.Substring(2), BindingFlags.Static | BindingFlags.NonPublic)) != null ?
Delegate.CreateDelegate(signature, m) : null);
}
#endregion
@ -245,6 +247,10 @@ namespace OpenTK.OpenGL
}
f.SetValue(null, d);
//Type type = f.ReflectedType;
//TypedReference t = __makeref(type);
//f.SetValueDirect(t, d);
}
time.Stop();

View file

@ -2977,7 +2977,7 @@ namespace OpenTK.Platform.Windows
public IntPtr LParam;
public uint Time;
public POINT Point;
public object RefObject;
//public object RefObject;
public override string ToString()
{

View file

@ -194,7 +194,10 @@ namespace OpenTK.Platform.Windows
public void MakeCurrent()
{
Wgl.Imports.MakeCurrent(deviceContext, renderContext);
if (!Wgl.Imports.MakeCurrent(deviceContext, renderContext))
{
Debug.Print("WinGLContext.MakeCurrent() call failed. Error: {0}", Marshal.GetLastWin32Error());
}
}
#endregion