2007-09-03 00:52:00 +02:00
|
|
|
|
#region --- License ---
|
|
|
|
|
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
|
|
|
|
* See license.txt for license info
|
|
|
|
|
*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
using System;
|
2007-09-02 15:34:44 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
2008-01-31 15:23:20 +01:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Reflection;
|
2007-09-02 15:34:44 +02:00
|
|
|
|
|
|
|
|
|
using OpenTK;
|
2008-02-02 01:58:26 +01:00
|
|
|
|
using OpenTK.Graphics.OpenGL;
|
|
|
|
|
using OpenTK.Graphics.OpenGL.Enums;
|
2008-01-31 15:23:20 +01:00
|
|
|
|
using OpenTK.Graphics;
|
2007-09-02 15:34:44 +02:00
|
|
|
|
|
|
|
|
|
namespace Examples.WinForms
|
|
|
|
|
{
|
2007-11-11 19:44:10 +01:00
|
|
|
|
[Example("Extensions", ExampleCategory.WinForms, 3)]
|
|
|
|
|
public partial class W03_Extensions : Form
|
2007-09-02 15:34:44 +02:00
|
|
|
|
{
|
2008-02-28 14:57:48 +01:00
|
|
|
|
GLControl glControl = new GLControl(GraphicsFormat.Default);
|
2007-09-02 15:34:44 +02:00
|
|
|
|
Type glClass;
|
|
|
|
|
Type delegatesClass;
|
|
|
|
|
Type importsClass;
|
2007-09-03 23:47:34 +02:00
|
|
|
|
int supported, all; // Number of supported extensions.
|
|
|
|
|
string driver;
|
2007-09-02 15:34:44 +02:00
|
|
|
|
|
|
|
|
|
public W03_Extensions()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
2007-11-11 19:44:10 +01:00
|
|
|
|
glClass = typeof(GL);
|
2007-09-02 15:34:44 +02:00
|
|
|
|
delegatesClass = glClass.GetNestedType("Delegates", BindingFlags.Static | BindingFlags.NonPublic);
|
|
|
|
|
importsClass = glClass.GetNestedType("Imports", BindingFlags.Static | BindingFlags.NonPublic);
|
2007-09-24 21:57:37 +02:00
|
|
|
|
|
2008-02-28 14:57:48 +01:00
|
|
|
|
glControl.CreateControl();
|
2007-11-11 19:44:10 +01:00
|
|
|
|
Application.Idle += StartAsync;
|
2007-09-02 15:34:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
2008-02-28 14:57:48 +01:00
|
|
|
|
protected override void OnClosed(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
glControl.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-11 19:44:10 +01:00
|
|
|
|
void StartAsync(object sender, EventArgs e)
|
2007-09-02 15:34:44 +02:00
|
|
|
|
{
|
2007-11-11 19:44:10 +01:00
|
|
|
|
Application.Idle -= StartAsync;
|
|
|
|
|
|
2007-09-03 23:47:34 +02:00
|
|
|
|
driver =
|
2007-11-04 16:32:24 +01:00
|
|
|
|
GL.GetString(StringName.Vendor) + " " +
|
|
|
|
|
GL.GetString(StringName.Renderer) + " " +
|
|
|
|
|
GL.GetString(StringName.Version);
|
2007-09-03 01:26:12 +02:00
|
|
|
|
|
2007-09-03 23:47:34 +02:00
|
|
|
|
all = delegatesClass.GetFields(BindingFlags.Static | BindingFlags.NonPublic).Length;
|
|
|
|
|
this.Text = String.Format("Loading {0} functions...", all);
|
2007-09-03 01:26:12 +02:00
|
|
|
|
|
2007-09-03 23:47:34 +02:00
|
|
|
|
this.backgroundWorker1.RunWorkerAsync();
|
|
|
|
|
}
|
2007-09-03 01:26:12 +02:00
|
|
|
|
|
2007-09-03 23:47:34 +02:00
|
|
|
|
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
|
|
|
|
|
{
|
2007-09-02 15:34:44 +02:00
|
|
|
|
FieldInfo[] v = delegatesClass.GetFields(BindingFlags.Static | BindingFlags.NonPublic);
|
2007-09-03 23:47:34 +02:00
|
|
|
|
int i = 0;
|
|
|
|
|
|
2007-09-02 15:34:44 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
foreach (FieldInfo f in v)
|
|
|
|
|
{
|
2007-09-03 23:47:34 +02:00
|
|
|
|
object d = f.GetValue(delegatesClass);
|
2007-09-02 15:34:44 +02:00
|
|
|
|
if (d != null)
|
|
|
|
|
++supported;
|
|
|
|
|
|
2008-01-11 21:18:51 +01:00
|
|
|
|
//if (i % 500 != 0)
|
|
|
|
|
backgroundWorker1.ReportProgress((int)(((float)i / all) * 100.0f),
|
|
|
|
|
String.Format("({0}/{1}) {2}:\t{3}", i.ToString(), all, d != null ? "ok" : "failed", f.Name));
|
|
|
|
|
++i;
|
2007-09-03 23:47:34 +02:00
|
|
|
|
}
|
2007-09-02 15:34:44 +02:00
|
|
|
|
}
|
|
|
|
|
catch (Exception expt)
|
|
|
|
|
{
|
2007-09-03 23:47:34 +02:00
|
|
|
|
MessageBox.Show(expt.ToString(), "An error occured while loading extensions", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
2007-09-02 15:34:44 +02:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-11-11 19:44:10 +01:00
|
|
|
|
|
2008-01-11 21:18:51 +01:00
|
|
|
|
List<string> items = new List<string>();
|
2007-09-03 23:47:34 +02:00
|
|
|
|
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
|
|
|
|
|
{
|
2008-01-11 21:18:51 +01:00
|
|
|
|
items.Add(e.UserState as string);
|
|
|
|
|
//listBox1.Items.Add(e.UserState as string);
|
2007-09-03 23:47:34 +02:00
|
|
|
|
/*
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
}
|
2007-09-02 15:34:44 +02:00
|
|
|
|
|
2007-09-03 23:47:34 +02:00
|
|
|
|
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
|
|
|
|
|
{
|
2008-01-11 21:18:51 +01:00
|
|
|
|
listBox1.Items.AddRange(items.ToArray());
|
2007-09-03 23:47:34 +02:00
|
|
|
|
this.Text = String.Format("{0}: {1}/{2} OpenGL functions supported.",
|
|
|
|
|
driver, supported, all);
|
|
|
|
|
}
|
2007-11-11 19:44:10 +01:00
|
|
|
|
|
|
|
|
|
#region public static void Main()
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Entry point of this example.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[STAThread]
|
|
|
|
|
public static void Main()
|
|
|
|
|
{
|
|
|
|
|
using (W03_Extensions example = new W03_Extensions())
|
|
|
|
|
{
|
2008-01-15 13:24:57 +01:00
|
|
|
|
Utilities.SetWindowTitle(example);
|
2007-11-11 19:44:10 +01:00
|
|
|
|
example.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2007-09-02 15:34:44 +02:00
|
|
|
|
}
|
|
|
|
|
}
|