Opentk/Source/Examples/WinForms/W03_Extensions.cs

121 lines
3.9 KiB
C#
Raw Normal View History

#region --- License ---
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
* See license.txt for license info
*/
#endregion
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using OpenTK;
using System.Reflection;
using OpenTK.OpenGL;
2007-09-02 23:40:50 +00:00
using System.Threading;
namespace Examples.WinForms
{
2007-09-02 23:40:50 +00:00
public partial class W03_Extensions : Form, IExample
{
GLControl glControl = new GLControl();
Assembly assembly;
Type glClass;
Type delegatesClass;
Type importsClass;
int supported, all; // Number of supported extensions.
string driver;
public W03_Extensions()
{
InitializeComponent();
assembly = Assembly.Load("OpenTK");
glClass = assembly.GetType("OpenTK.OpenGL.GL");
delegatesClass = glClass.GetNestedType("Delegates", BindingFlags.Static | BindingFlags.NonPublic);
importsClass = glClass.GetNestedType("Imports", BindingFlags.Static | BindingFlags.NonPublic);
glControl.Load += new EventHandler(glControl_Load);
glControl.CreateControl();
}
void glControl_Load(object sender, EventArgs e)
{
Application.Idle += StartAsync;
driver =
GL.GetString(GL.Enums.StringName.VENDOR) + " " +
GL.GetString(GL.Enums.StringName.RENDERER) + " " +
GL.GetString(GL.Enums.StringName.VERSION);
2007-09-02 23:26:12 +00:00
all = delegatesClass.GetFields(BindingFlags.Static | BindingFlags.NonPublic).Length;
this.Text = String.Format("Loading {0} functions...", all);
}
void StartAsync(object sender, EventArgs e)
{
Application.Idle -= StartAsync;
2007-09-02 23:26:12 +00:00
this.backgroundWorker1.RunWorkerAsync();
}
2007-09-02 23:26:12 +00:00
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
FieldInfo[] v = delegatesClass.GetFields(BindingFlags.Static | BindingFlags.NonPublic);
int i = 0;
try
{
foreach (FieldInfo f in v)
{
object d = f.GetValue(delegatesClass);
if (d != null)
{
++supported;
}
backgroundWorker1.ReportProgress((int)(((float)i / all) * 100.0f),
String.Format("({0}/{1}) {2}:\t{3}", (++i).ToString(), all, d != null ? "ok" : "failed", f.Name));
}
}
catch (Exception expt)
{
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
2007-10-20 10:54:40 +00:00
public void Launch() { }
2007-10-20 10:54:40 +00:00
public static readonly int order = 3;
#endregion
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
this.Text = String.Format("{0}: {1}/{2} OpenGL functions supported.",
driver, supported, all);
}
}
}