Updated the Context class hierarchy. Now WindowsVistaContext and WindowsContext inherit from WindowsBaseContext, avoiding code duplication.
Some minor updates to the XApi, Framework and GLContext files. Updated todo.txt and changelog.txt
This commit is contained in:
parent
f34436f131
commit
261df17632
9 changed files with 106 additions and 121 deletions
|
@ -49,6 +49,16 @@ namespace OpenTK
|
|||
public void Open(string title, int width, int height, int red, int green, int blue, int alpha, int depth, int stencil, bool fullscreen)
|
||||
{
|
||||
Application.Idle += new EventHandler(OnIdle);
|
||||
|
||||
Context = GLContext.Create(this, red, green, blue, alpha, depth, stencil);
|
||||
|
||||
// Code taken from NeHe tutorials
|
||||
this.CreateParams.Style |= (int)Api.WindowClassStyle.HRedraw | (int)Api.WindowClassStyle.VRedraw | (int)Api.WindowClassStyle.OwnDC;
|
||||
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); // No Need To Erase Form Background
|
||||
this.SetStyle(ControlStyles.Opaque, true); // No Need To Draw Form Background
|
||||
//this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); // Buffer Control
|
||||
//this.SetStyle(ControlStyles.ResizeRedraw, true); // Redraw On Resize
|
||||
this.SetStyle(ControlStyles.UserPaint, true); // We'll Handle Painting Ourselves
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -73,24 +83,14 @@ namespace OpenTK
|
|||
}
|
||||
}
|
||||
|
||||
#region Open functions
|
||||
|
||||
public void WindowsOpen(string title, int width, int height, int red, int green, int blue, int alpha, int depth, int stencil, bool fullscreen)
|
||||
{
|
||||
// Hack! Should add more constructors to the GLContext class.
|
||||
Context = GLContext.Create(this, 8, 8, 8, 8, 16, 0);
|
||||
|
||||
// Todo: Why doesn't this work?
|
||||
if (title == null)
|
||||
title = "OpenTK application";
|
||||
title = "OpenTK Windows application";
|
||||
this.Text = title;
|
||||
|
||||
// Code taken from NeHe tutorials
|
||||
this.CreateParams.Style |= (int)Api.WindowClassStyle.HRedraw | (int)Api.WindowClassStyle.VRedraw | (int)Api.WindowClassStyle.OwnDC;
|
||||
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); // No Need To Erase Form Background
|
||||
this.SetStyle(ControlStyles.Opaque, true); // No Need To Draw Form Background
|
||||
//this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); // Buffer Control
|
||||
//this.SetStyle(ControlStyles.ResizeRedraw, true); // Redraw On Resize
|
||||
this.SetStyle(ControlStyles.UserPaint, true); // We'll Handle Painting Ourselves
|
||||
|
||||
if (fullscreen)
|
||||
{
|
||||
Api.DeviceMode ScreenSettings = new Api.DeviceMode(); // Device Mode
|
||||
|
@ -118,27 +118,27 @@ namespace OpenTK
|
|||
}
|
||||
|
||||
this.Size = new Size(width, height);
|
||||
|
||||
// Cross-platformness?
|
||||
|
||||
}
|
||||
|
||||
public void XOpen(string title, int width, int height, int red, int green, int blue, int alpha, int depth, int stencil, bool fullscreen)
|
||||
{
|
||||
Context = GLContext.Create(this, red, green, blue, alpha, depth, stencil);
|
||||
|
||||
if (title == null)
|
||||
title = "OpenTK X application";
|
||||
this.Text = title;
|
||||
|
||||
this.Size = new Size(width, height);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
//override protected void WndProc(ref Message m)
|
||||
//{
|
||||
// base.WndProc(ref m);
|
||||
// //OnPaint(null);
|
||||
//}
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
Application.Idle -= OnIdle;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Event Handlers
|
||||
|
||||
/// <summary>
|
||||
|
@ -172,5 +172,15 @@ namespace OpenTK
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
//GC.SuppressFinalize(true);
|
||||
Application.Idle -= OnIdle;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,8 +34,7 @@ namespace OpenTK.OpenGL
|
|||
{
|
||||
try
|
||||
{
|
||||
if (Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version.Major < 6 ||
|
||||
Environment.OSVersion.Platform == PlatformID.Win32Windows)
|
||||
if (Environment.OSVersion.Platform == PlatformID.Win32NT || Environment.OSVersion.Platform == PlatformID.Win32Windows)
|
||||
{
|
||||
return new WindowsContext(c, red, green, blue, alpha, depth, stencil);
|
||||
}
|
||||
|
|
52
Source/OpenGL/OpenGL/Contexts/WindowsBaseContext.cs
Normal file
52
Source/OpenGL/OpenGL/Contexts/WindowsBaseContext.cs
Normal file
|
@ -0,0 +1,52 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using OpenTK.OpenGL;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace OpenTK.OpenGL.Platform
|
||||
{
|
||||
public class WindowsBaseContext : GLContext
|
||||
{
|
||||
protected const string _dll_name = "OPENGL32.DLL";
|
||||
protected int _dll_handle;
|
||||
protected int _device_context;
|
||||
protected int _render_context;
|
||||
protected IntPtr _window_handle;
|
||||
|
||||
public override void SwapBuffers()
|
||||
{
|
||||
OpenTK.Platform.Windows.Api.SwapBuffers(_device_context);
|
||||
}
|
||||
|
||||
public override Delegate GetAddress(string function_string, Type function_type)
|
||||
{
|
||||
IntPtr address = Wgl.GetProcAddress(function_string);
|
||||
if (address == IntPtr.Zero)
|
||||
return null;
|
||||
else
|
||||
return Marshal.GetDelegateForFunctionPointer(address, function_type);
|
||||
}
|
||||
|
||||
public override void MakeCurrent()
|
||||
{
|
||||
Wgl.MakeCurrent(_device_context, _render_context);
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
if (_render_context != 0)
|
||||
Wgl.DeleteContext(_render_context);
|
||||
|
||||
if (_device_context != 0)
|
||||
OpenTK.Platform.Windows.Api.ReleaseDC(_window_handle.ToInt32(), _device_context);
|
||||
|
||||
if (_dll_handle != 0)
|
||||
OpenTK.Platform.Windows.Api.FreeLibrary(_dll_handle);
|
||||
|
||||
_render_context = 0;
|
||||
_device_context = 0;
|
||||
_dll_handle = 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,14 +13,8 @@ using System.Runtime.InteropServices;
|
|||
|
||||
namespace OpenTK.OpenGL.Platform
|
||||
{
|
||||
public partial class WindowsContext : OpenTK.OpenGL.GLContext
|
||||
public partial class WindowsContext : WindowsBaseContext
|
||||
{
|
||||
const string _dll_name = "OPENGL32.DLL";
|
||||
int _dll_handle;
|
||||
int _device_context;
|
||||
int _render_context;
|
||||
IntPtr _window_handle;
|
||||
|
||||
public WindowsContext(Control c, int red, int green, int blue, int alpha, int depth, int stencil)
|
||||
{
|
||||
int error_code = 0;
|
||||
|
@ -100,40 +94,5 @@ namespace OpenTK.OpenGL.Platform
|
|||
//if (load_extensions)
|
||||
// LoadExtensions();
|
||||
}
|
||||
|
||||
public override void SwapBuffers()
|
||||
{
|
||||
OpenTK.Platform.Windows.Api.SwapBuffers(_device_context);
|
||||
}
|
||||
|
||||
public override Delegate GetAddress(string function_string, Type function_type)
|
||||
{
|
||||
IntPtr address = Wgl.GetProcAddress(function_string);
|
||||
if (address == IntPtr.Zero)
|
||||
return null;
|
||||
else
|
||||
return Marshal.GetDelegateForFunctionPointer(address, function_type);
|
||||
}
|
||||
|
||||
public override void MakeCurrent()
|
||||
{
|
||||
Wgl.MakeCurrent(_device_context, _render_context);
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
if (_render_context != 0)
|
||||
Wgl.DeleteContext(_render_context);
|
||||
|
||||
if (_device_context != 0)
|
||||
OpenTK.Platform.Windows.Api.ReleaseDC(_window_handle.ToInt32(), _device_context);
|
||||
|
||||
if (_dll_handle != 0)
|
||||
OpenTK.Platform.Windows.Api.FreeLibrary(_dll_handle);
|
||||
|
||||
_render_context = 0;
|
||||
_device_context = 0;
|
||||
_dll_handle = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,14 +11,8 @@ using OpenTK.OpenGL;
|
|||
|
||||
namespace OpenTK.OpenGL.Platform
|
||||
{
|
||||
public partial class WindowsVistaContext : OpenTK.OpenGL.GLContext
|
||||
public partial class WindowsVistaContext : WindowsBaseContext
|
||||
{
|
||||
const string _dll_name = "OPENGL32.DLL";
|
||||
int _dll_handle;
|
||||
int _device_context;
|
||||
int _render_context;
|
||||
IntPtr _window_handle;
|
||||
|
||||
public WindowsVistaContext(Control c, int red, int green, int blue, int alpha, int depth, int stencil)
|
||||
{
|
||||
int error_code = 0;
|
||||
|
@ -98,40 +92,5 @@ namespace OpenTK.OpenGL.Platform
|
|||
//if (load_extensions)
|
||||
// LoadExtensions();
|
||||
}
|
||||
|
||||
public override void SwapBuffers()
|
||||
{
|
||||
OpenTK.Platform.Windows.Api.SwapBuffers(_device_context);
|
||||
}
|
||||
|
||||
public override Delegate GetAddress(string function_string, Type function_type)
|
||||
{
|
||||
IntPtr address = Wgl.GetProcAddress(function_string);
|
||||
if (address == IntPtr.Zero)
|
||||
return null;
|
||||
else
|
||||
return Marshal.GetDelegateForFunctionPointer(address, function_type);
|
||||
}
|
||||
|
||||
public override void MakeCurrent()
|
||||
{
|
||||
Wgl.MakeCurrent(_device_context, _render_context);
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
if (_render_context != 0)
|
||||
Wgl.DeleteContext(_render_context);
|
||||
|
||||
if (_device_context != 0)
|
||||
OpenTK.Platform.Windows.Api.ReleaseDC(_window_handle.ToInt32(), _device_context);
|
||||
|
||||
if (_dll_handle != 0)
|
||||
OpenTK.Platform.Windows.Api.FreeLibrary(_dll_handle);
|
||||
|
||||
_render_context = 0;
|
||||
_device_context = 0;
|
||||
_dll_handle = 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -48,10 +48,13 @@
|
|||
<Compile Include="Bindings\WindowsContextLoad.cs" />
|
||||
<Compile Include="Bindings\WindowsVistaContextLoad.cs" />
|
||||
<Compile Include="Bindings\X11ContextLoad.cs" />
|
||||
<Compile Include="Contexts\WindowsBaseContext.cs" />
|
||||
<Compile Include="Contexts\WindowsVistaContext.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Glu.cs" />
|
||||
<Compile Include="Contexts\GLContext.cs" />
|
||||
<Compile Include="Contexts\WindowsContext.cs" />
|
||||
<Compile Include="Contexts\WindowsVistaContext.cs" />
|
||||
<Compile Include="Contexts\X11Context.cs" />
|
||||
<Compile Include="Glx.cs" />
|
||||
<Compile Include="Wgl.cs" />
|
||||
|
|
|
@ -47,6 +47,7 @@ namespace OpenTK.Platform.X
|
|||
[DllImport(_dll_name, EntryPoint = "XCloseDisplay")]
|
||||
extern public static void CloseDisplay(IntPtr display);
|
||||
|
||||
//
|
||||
|
||||
[DllImport(_dll_name, EntryPoint = "XDefaultScreen")]
|
||||
extern public static int DefaultScreen(IntPtr display);
|
||||
|
@ -57,7 +58,6 @@ namespace OpenTK.Platform.X
|
|||
[DllImport(_dll_name, EntryPoint = "XFree")]
|
||||
extern public static void Free(IntPtr data);
|
||||
|
||||
|
||||
// Queue management
|
||||
[DllImport(_dll_name, EntryPoint = "XEventsQueued")]
|
||||
extern public static int EventsQueued(IntPtr Display, int mode);
|
||||
|
|
|
@ -11,7 +11,10 @@ OpenTK 0.3.4 -> 0.3.5
|
|||
+ Added bindings to some glx functions.
|
||||
+ Added the OpenTK.Platform.X class.
|
||||
+ Minor updates to the wgl bindings (int -> IntPtr).
|
||||
+ Tested the binding generator with the glx specs (the reader and the enum writer work ok, the trnaslator and the other writers need updating).
|
||||
+ Tested the binding generator with the glx specs (the reader and the enum writer work ok, the trnaslator and the other writers will need updating).
|
||||
+ Renamed the GLForm to Framework.
|
||||
+ The Framework now resides in its own project directory.
|
||||
+ Revamped the GLContext class hierarchy. WindowsContext and WindowsVistaContext now both inherit from WindowsBaseContext. This allows for less code-duplication (and thus less bugs).
|
||||
|
||||
OpenTK 0.3.3 -> 0.3.4
|
||||
+ Corrected the crash error in Release mode (it was caused by trying to Marshal the System.Windows.Forms.Message struct to PeekMessage - adding my own Message struct corrected the issue).
|
||||
|
|
12
todo.txt
12
todo.txt
|
@ -1,13 +1,13 @@
|
|||
Todo:
|
||||
+ + + Add basic GLX bindings.
|
||||
+ + + Add basic X bindings.
|
||||
+ + + Add context creation support for X.
|
||||
+ + + Correct the Dispose methods to correctly clean resources (they should also call GC.SupressFinalize(true))
|
||||
+ + + Add basic GLX bindings (in progress)
|
||||
+ + + Add basic X bindings (in progress)
|
||||
+ + + Add context creation support for X (needs testing)
|
||||
+ + + Test X support.
|
||||
+ + + Add the CLS compliant attribute to the GL class.
|
||||
+ + Add cross-platform way for overriding the Application.Idle handler.
|
||||
+ + Change the hierarchy of the WindowsContext and WindowsVistaContext classes. The should have a common ancestor who manages the windows creation (it should be the same for both).
|
||||
+ + Add cross-platform way for defining the Application.Idle handler (needs testing)
|
||||
+ + Add more constructors to the Context classes.
|
||||
+ + Add more GLForm constructors.
|
||||
+ + Add more Framework constructors.
|
||||
+ + Add comments and documentation (faqs, pitfalls, best practices).
|
||||
+ + Add a cross-platform build system (probably NAnt?)
|
||||
+ Add more examples.
|
||||
|
|
Loading…
Reference in a new issue