2007-09-02 22:52:00 +00:00
|
|
|
|
#region --- License ---
|
|
|
|
|
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
|
|
|
|
* See license.txt for license info
|
|
|
|
|
*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
using System;
|
2007-09-02 13:34:44 +00:00
|
|
|
|
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;
|
2007-09-02 13:34:44 +00:00
|
|
|
|
|
|
|
|
|
namespace Examples.WinForms
|
|
|
|
|
{
|
2007-09-02 23:40:50 +00:00
|
|
|
|
public partial class W03_Extensions : Form, IExample
|
2007-09-02 13:34:44 +00:00
|
|
|
|
{
|
|
|
|
|
GLControl glControl = new GLControl();
|
|
|
|
|
Assembly assembly;
|
|
|
|
|
Type glClass;
|
|
|
|
|
Type delegatesClass;
|
|
|
|
|
Type importsClass;
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnLoad(e);
|
|
|
|
|
|
|
|
|
|
glControl.CreateContext();
|
|
|
|
|
|
2007-09-02 23:40:50 +00:00
|
|
|
|
//listBox1.BeginInvoke(new LoadExtensionsDelegate(LoadExtensions));
|
|
|
|
|
ThreadPool.QueueUserWorkItem(new WaitCallback(LoadExtensions));
|
2007-09-02 23:26:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-02 23:40:50 +00:00
|
|
|
|
delegate void LoadExtensionsDelegate(object data);
|
2007-09-02 23:26:12 +00:00
|
|
|
|
|
2007-09-02 23:40:50 +00:00
|
|
|
|
void LoadExtensions(object data)
|
2007-09-02 23:26:12 +00:00
|
|
|
|
{
|
|
|
|
|
glControl.MakeCurrent();
|
|
|
|
|
|
2007-09-02 13:34:44 +00:00
|
|
|
|
FieldInfo[] v = delegatesClass.GetFields(BindingFlags.Static | BindingFlags.NonPublic);
|
|
|
|
|
|
|
|
|
|
int i = 0, supported = 0;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
foreach (FieldInfo f in v)
|
|
|
|
|
{
|
|
|
|
|
Delegate d = GL.GetDelegate(f.Name, f.FieldType);
|
|
|
|
|
|
|
|
|
|
f.SetValue(null, d);
|
2007-09-02 23:26:12 +00:00
|
|
|
|
listBox1.Items.Add(String.Format("{0}/{1} {2}: {3}",
|
2007-09-02 13:34:44 +00:00
|
|
|
|
(++i).ToString(), v.Length, d != null ? "ok" : "failed", f.Name));
|
2007-09-02 23:40:50 +00:00
|
|
|
|
|
|
|
|
|
listBox1.Update();
|
|
|
|
|
|
|
|
|
|
//Thread.Sleep(1);
|
2007-09-02 13:34:44 +00:00
|
|
|
|
|
|
|
|
|
if (d != null)
|
|
|
|
|
{
|
|
|
|
|
++supported;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-02 23:26:12 +00:00
|
|
|
|
//this.Text = String.Format("Supported extensions: {0}", supported);
|
2007-09-02 13:34:44 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception expt)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("An error occured while loading extensions", "Extension loading failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region IExample Members
|
|
|
|
|
|
|
|
|
|
public void Launch()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|