2007-07-23 02:15:18 +02:00
|
|
|
|
#region --- License ---
|
|
|
|
|
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
|
|
|
|
* Contributions from Erik Ylvisaker
|
|
|
|
|
* See license.txt for license info
|
|
|
|
|
*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-09-09 17:10:21 +02:00
|
|
|
|
#region --- Using Directives ---
|
|
|
|
|
|
2007-07-23 02:15:18 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Runtime.InteropServices;
|
2007-09-09 17:10:21 +02:00
|
|
|
|
using System.Diagnostics;
|
2007-07-23 02:15:18 +02:00
|
|
|
|
|
2008-02-02 01:58:26 +01:00
|
|
|
|
using OpenTK.Graphics.OpenGL;
|
2008-01-31 15:22:37 +01:00
|
|
|
|
using OpenTK.Graphics;
|
2007-09-09 17:10:21 +02:00
|
|
|
|
|
|
|
|
|
#endregion
|
2007-07-23 02:15:18 +02:00
|
|
|
|
|
|
|
|
|
namespace OpenTK.Platform.Windows
|
|
|
|
|
{
|
2007-09-09 13:52:09 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Provides methods to create and control an opengl context on the Windows platform.
|
2007-12-09 19:15:51 +01:00
|
|
|
|
/// This class supports OpenTK, and is not intended for use by OpenTK programs.
|
2007-09-09 13:52:09 +02:00
|
|
|
|
/// </summary>
|
2008-03-03 13:44:56 +01:00
|
|
|
|
internal sealed class WinGLContext : IGraphicsContext, IGraphicsContextInternal//, IGLContextCreationHack
|
2007-07-23 02:15:18 +02:00
|
|
|
|
{
|
2008-03-03 13:44:56 +01:00
|
|
|
|
//IntPtr deviceContext;
|
|
|
|
|
WinWindowInfo currentWindow;
|
2008-02-28 14:57:07 +01:00
|
|
|
|
ContextHandle renderContext;
|
|
|
|
|
static IntPtr opengl32Handle;
|
|
|
|
|
const string opengl32Name = "OPENGL32.DLL";
|
2008-03-03 13:44:56 +01:00
|
|
|
|
//WinWindowInfo windowInfo = new WinWindowInfo();
|
2007-07-23 02:15:18 +02:00
|
|
|
|
|
2008-02-28 16:26:13 +01:00
|
|
|
|
GraphicsMode format;
|
2008-02-28 14:57:07 +01:00
|
|
|
|
//DisplayMode mode = null;
|
|
|
|
|
bool vsync_supported;
|
2007-08-20 14:25:48 +02:00
|
|
|
|
|
2008-02-28 14:57:07 +01:00
|
|
|
|
bool disposed;
|
2007-07-23 02:15:18 +02:00
|
|
|
|
|
|
|
|
|
#region --- Contructors ---
|
|
|
|
|
|
2008-01-31 14:15:17 +01:00
|
|
|
|
static WinGLContext()
|
2007-09-09 13:52:09 +02:00
|
|
|
|
{
|
2008-01-31 14:15:17 +01:00
|
|
|
|
// Set the GetCurrentContext implementation.
|
2008-02-28 14:57:07 +01:00
|
|
|
|
// TODO: Does this belong here?
|
2008-01-31 15:39:54 +01:00
|
|
|
|
if (GraphicsContext.GetCurrentContext == null)
|
|
|
|
|
GraphicsContext.GetCurrentContext = WinGLContext.GetCurrentContext;
|
2008-02-28 14:57:07 +01:00
|
|
|
|
|
|
|
|
|
// Dynamically load the OpenGL32.dll in order to use the extension loading capabilities of Wgl.
|
|
|
|
|
if (opengl32Handle == IntPtr.Zero)
|
|
|
|
|
{
|
|
|
|
|
opengl32Handle = Functions.LoadLibrary(opengl32Name);
|
|
|
|
|
if (opengl32Handle == IntPtr.Zero)
|
|
|
|
|
throw new ApplicationException(String.Format("LoadLibrary(\"{0}\") call failed with code {1}",
|
|
|
|
|
opengl32Name, Marshal.GetLastWin32Error()));
|
|
|
|
|
Debug.WriteLine(String.Format("Loaded opengl32.dll: {0}", opengl32Handle));
|
|
|
|
|
}
|
2008-01-31 14:15:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
2008-02-28 16:26:13 +01:00
|
|
|
|
public WinGLContext(GraphicsMode format, IWindowInfo window, IGraphicsContext sharedContext)
|
2008-02-28 14:57:07 +01:00
|
|
|
|
{
|
2008-03-03 13:44:56 +01:00
|
|
|
|
if (window == null) throw new ArgumentNullException("window", "Must point to a valid window.");
|
2008-02-28 14:57:07 +01:00
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
currentWindow = (WinWindowInfo)window;
|
|
|
|
|
if (currentWindow.WindowHandle == IntPtr.Zero) throw new ArgumentException("window", "Must be a valid window.");
|
2008-02-28 14:57:07 +01:00
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
Debug.Print("OpenGL will be bound to handle: {0}", currentWindow.WindowHandle);
|
|
|
|
|
|
2008-04-20 19:52:27 +02:00
|
|
|
|
Debug.Write("Setting pixel format... ");
|
2008-03-03 13:44:56 +01:00
|
|
|
|
this.SetGraphicsModePFD(format, (WinWindowInfo)window);
|
2008-02-28 14:57:07 +01:00
|
|
|
|
|
|
|
|
|
// Do not rely on OpenTK.Platform.Windows.Wgl - the context is not ready yet,
|
|
|
|
|
// and Wgl extensions will fail to load.
|
2008-03-03 13:44:56 +01:00
|
|
|
|
Debug.Write("Creating render context... ");
|
|
|
|
|
renderContext = new ContextHandle(Wgl.Imports.CreateContext(currentWindow.DeviceContext));
|
|
|
|
|
if (renderContext == IntPtr.Zero)
|
|
|
|
|
renderContext = new ContextHandle(Wgl.Imports.CreateContext(currentWindow.DeviceContext));
|
2008-02-28 14:57:07 +01:00
|
|
|
|
if (renderContext == IntPtr.Zero)
|
|
|
|
|
throw new GraphicsContextException(String.Format("Context creation failed. Wgl.CreateContext() error: {0}.",
|
|
|
|
|
Marshal.GetLastWin32Error()));
|
|
|
|
|
|
|
|
|
|
Debug.WriteLine(String.Format("done! (id: {0})", renderContext));
|
|
|
|
|
|
|
|
|
|
if (sharedContext != null)
|
|
|
|
|
{
|
|
|
|
|
Debug.Print("Sharing state with context {0}", sharedContext.ToString());
|
2008-04-13 15:54:24 +02:00
|
|
|
|
Wgl.Imports.ShareLists((sharedContext as IGraphicsContextInternal).Context, renderContext);
|
2008-02-28 14:57:07 +01:00
|
|
|
|
}
|
2007-08-20 14:25:48 +02:00
|
|
|
|
}
|
2007-07-23 02:15:18 +02:00
|
|
|
|
|
2008-05-19 22:54:07 +02:00
|
|
|
|
public WinGLContext(IWindowInfo window)
|
|
|
|
|
{
|
|
|
|
|
if (window == null) throw new ArgumentNullException("window");
|
|
|
|
|
|
|
|
|
|
renderContext = Wgl.GetCurrentContext();
|
|
|
|
|
if (renderContext == IntPtr.Zero)
|
|
|
|
|
throw new InvalidOperationException("No OpenGL context is current in the calling thread.");
|
|
|
|
|
|
|
|
|
|
currentWindow = (WinWindowInfo)window;
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-09 17:10:21 +02:00
|
|
|
|
#endregion
|
2007-12-09 19:15:51 +01:00
|
|
|
|
|
2008-01-31 14:17:42 +01:00
|
|
|
|
#region --- IGraphicsContext Members ---
|
2007-09-09 17:10:21 +02:00
|
|
|
|
|
2007-08-20 14:25:48 +02:00
|
|
|
|
#region public void CreateContext()
|
|
|
|
|
|
|
|
|
|
public void CreateContext()
|
2007-09-09 17:10:21 +02:00
|
|
|
|
{
|
2008-02-28 14:57:07 +01:00
|
|
|
|
throw new NotSupportedException();
|
2007-09-09 17:10:21 +02:00
|
|
|
|
this.CreateContext(true, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public void CreateContext(bool direct)
|
|
|
|
|
|
|
|
|
|
public void CreateContext(bool direct)
|
|
|
|
|
{
|
2008-02-28 14:57:07 +01:00
|
|
|
|
throw new NotSupportedException();
|
2007-09-09 17:10:21 +02:00
|
|
|
|
this.CreateContext(direct, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2008-01-31 14:17:42 +01:00
|
|
|
|
#region public void CreateContext(bool direct, IGraphicsContext source)
|
2007-09-09 17:10:21 +02:00
|
|
|
|
|
2008-01-31 14:17:42 +01:00
|
|
|
|
public void CreateContext(bool direct, IGraphicsContext source)
|
2007-08-20 14:25:48 +02:00
|
|
|
|
{
|
2008-02-28 14:57:07 +01:00
|
|
|
|
throw new NotSupportedException();
|
2007-07-23 02:15:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-20 14:25:48 +02:00
|
|
|
|
#endregion
|
|
|
|
|
|
2007-07-23 02:15:18 +02:00
|
|
|
|
#region public void SwapBuffers()
|
|
|
|
|
|
|
|
|
|
public void SwapBuffers()
|
|
|
|
|
{
|
2008-03-03 13:44:56 +01:00
|
|
|
|
|
|
|
|
|
Functions.SwapBuffers(currentWindow.DeviceContext);
|
2007-07-23 02:15:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
#region public void MakeCurrent(IWindowInfo window)
|
|
|
|
|
|
|
|
|
|
public void MakeCurrent(IWindowInfo window)
|
2007-07-23 02:15:18 +02:00
|
|
|
|
{
|
2008-03-03 13:44:56 +01:00
|
|
|
|
bool success;
|
|
|
|
|
|
|
|
|
|
if (window != null)
|
2007-09-03 23:47:34 +02:00
|
|
|
|
{
|
2008-03-03 13:44:56 +01:00
|
|
|
|
if (((WinWindowInfo)window).WindowHandle == IntPtr.Zero)
|
|
|
|
|
throw new ArgumentException("window", "Must point to a valid window.");
|
|
|
|
|
|
|
|
|
|
currentWindow = (WinWindowInfo)window;
|
|
|
|
|
success = Wgl.Imports.MakeCurrent(((WinWindowInfo)window).DeviceContext, this.renderContext);
|
2007-09-03 23:47:34 +02:00
|
|
|
|
}
|
2008-03-03 13:44:56 +01:00
|
|
|
|
else
|
|
|
|
|
success = Wgl.Imports.MakeCurrent(IntPtr.Zero, IntPtr.Zero);
|
|
|
|
|
|
|
|
|
|
if (!success)
|
|
|
|
|
throw new GraphicsContextException(String.Format(
|
|
|
|
|
"Failed to make context {0} current. Error: {1}", this, Marshal.GetLastWin32Error()));
|
|
|
|
|
|
2007-07-23 02:15:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-12-09 19:15:51 +01:00
|
|
|
|
#region public bool IsCurrent
|
|
|
|
|
|
|
|
|
|
public bool IsCurrent
|
|
|
|
|
{
|
|
|
|
|
get { return Wgl.GetCurrentContext() == this.renderContext; }
|
2008-03-03 13:44:56 +01:00
|
|
|
|
/*
|
2008-01-31 14:15:17 +01:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value)
|
|
|
|
|
Wgl.MakeCurrent(this.deviceContext, this.renderContext);
|
|
|
|
|
else
|
|
|
|
|
Wgl.MakeCurrent(IntPtr.Zero, IntPtr.Zero);
|
|
|
|
|
}
|
2008-03-03 13:44:56 +01:00
|
|
|
|
*/
|
2007-12-09 19:15:51 +01:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2008-01-11 21:24:48 +01:00
|
|
|
|
#region public bool VSync
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets a System.Boolean indicating whether SwapBuffer calls are synced to the screen refresh rate.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool VSync
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return vsync_supported && Wgl.Ext.GetSwapInterval() != 0;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (vsync_supported)
|
|
|
|
|
Wgl.Ext.SwapInterval(value ? 1 : 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2008-01-31 14:17:42 +01:00
|
|
|
|
public event DestroyEvent<IGraphicsContext> Destroy;
|
2007-12-09 19:15:51 +01:00
|
|
|
|
|
2008-01-11 21:24:48 +01:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region --- IGLContextInternal Members ---
|
|
|
|
|
|
2008-03-01 14:15:31 +01:00
|
|
|
|
#region void LoadAll()
|
|
|
|
|
|
|
|
|
|
void IGraphicsContextInternal.LoadAll()
|
|
|
|
|
{
|
|
|
|
|
Wgl.LoadAll();
|
|
|
|
|
GL.LoadAll();
|
|
|
|
|
Glu.LoadAll();
|
|
|
|
|
|
|
|
|
|
vsync_supported = Wgl.Arb.SupportsExtension(this, "WGL_EXT_swap_control") &&
|
|
|
|
|
Wgl.Load("wglGetSwapIntervalEXT") && Wgl.Load("wglSwapIntervalEXT");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2008-02-28 14:57:07 +01:00
|
|
|
|
#region ContextHandle IGLContextInternal.Context
|
2008-01-11 21:24:48 +01:00
|
|
|
|
|
2008-03-01 14:15:31 +01:00
|
|
|
|
ContextHandle IGraphicsContextInternal.Context
|
2007-12-09 19:15:51 +01:00
|
|
|
|
{
|
2008-01-11 21:24:48 +01:00
|
|
|
|
get { return renderContext; }
|
2007-12-09 19:15:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-11 21:24:48 +01:00
|
|
|
|
#endregion
|
|
|
|
|
|
2008-02-28 14:57:07 +01:00
|
|
|
|
#region IWindowInfo IGLContextInternal.Info
|
2008-03-03 13:44:56 +01:00
|
|
|
|
/*
|
2008-03-01 14:15:31 +01:00
|
|
|
|
IWindowInfo IGraphicsContextInternal.Info
|
2007-12-09 19:15:51 +01:00
|
|
|
|
{
|
2008-02-28 14:57:07 +01:00
|
|
|
|
get { return (IWindowInfo)windowInfo; }
|
2008-01-11 21:24:48 +01:00
|
|
|
|
}
|
2008-03-03 13:44:56 +01:00
|
|
|
|
*/
|
2008-01-11 21:24:48 +01:00
|
|
|
|
#endregion
|
|
|
|
|
|
2008-02-28 16:28:40 +01:00
|
|
|
|
#region GraphicsMode IGLContextInternal.GraphicsMode
|
2008-01-11 21:24:48 +01:00
|
|
|
|
|
2008-03-01 14:15:31 +01:00
|
|
|
|
GraphicsMode IGraphicsContextInternal.GraphicsMode
|
2008-01-11 21:24:48 +01:00
|
|
|
|
{
|
2008-02-28 14:57:07 +01:00
|
|
|
|
get { return format; }
|
2008-01-11 21:24:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public IntPtr GetAddress(string function_string)
|
|
|
|
|
|
|
|
|
|
public IntPtr GetAddress(string function_string)
|
|
|
|
|
{
|
|
|
|
|
return Wgl.Imports.GetProcAddress(function_string);
|
2007-12-09 19:15:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-11 21:24:48 +01:00
|
|
|
|
#endregion
|
|
|
|
|
|
2008-01-20 20:29:42 +01:00
|
|
|
|
#region void IGLContextInternal.RegisterForDisposal(IDisposable resource)
|
|
|
|
|
|
2008-03-01 14:15:31 +01:00
|
|
|
|
void IGraphicsContextInternal.RegisterForDisposal(IDisposable resource)
|
2007-09-29 17:24:55 +02:00
|
|
|
|
{
|
2008-01-31 15:39:54 +01:00
|
|
|
|
throw new NotSupportedException("Use OpenTK.GraphicsContext instead.");
|
2008-01-11 21:24:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-20 20:29:42 +01:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region void IGLContextInternal.DisposeResources()
|
|
|
|
|
|
2008-03-01 14:15:31 +01:00
|
|
|
|
void IGraphicsContextInternal.DisposeResources()
|
2008-01-11 21:24:48 +01:00
|
|
|
|
{
|
2008-01-31 15:39:54 +01:00
|
|
|
|
throw new NotSupportedException("Use OpenTK.GraphicsContext instead.");
|
2008-01-11 21:24:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-20 20:29:42 +01:00
|
|
|
|
#endregion
|
2008-01-11 21:24:48 +01:00
|
|
|
|
|
2008-02-28 14:57:07 +01:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region --- Private Methods ---
|
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
#region void SetGraphicsModePFD(GraphicsMode format, WinWindowInfo window)
|
2008-02-28 14:57:07 +01:00
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
void SetGraphicsModePFD(GraphicsMode mode, WinWindowInfo window)
|
2008-02-28 14:57:07 +01:00
|
|
|
|
{
|
2008-03-03 13:44:56 +01:00
|
|
|
|
if (mode.Index == IntPtr.Zero) throw new ArgumentException(
|
|
|
|
|
"mode", "The Index (pixel format) of the GraphicsMode is not set.");
|
|
|
|
|
if (window == null) throw new ArgumentNullException("window", "Must point to a valid window.");
|
2008-02-28 14:57:07 +01:00
|
|
|
|
|
|
|
|
|
PixelFormatDescriptor pfd = new PixelFormatDescriptor();
|
2008-03-03 13:44:56 +01:00
|
|
|
|
Functions.DescribePixelFormat(window.DeviceContext, (int)mode.Index,
|
|
|
|
|
API.PixelFormatDescriptorSize, ref pfd);
|
|
|
|
|
Debug.WriteLine(mode.Index.ToString());
|
|
|
|
|
if (!Functions.SetPixelFormat(window.DeviceContext, (int)mode.Index, ref pfd))
|
|
|
|
|
throw new GraphicsContextException(String.Format(
|
|
|
|
|
"Requested GraphicsMode not available. SetPixelFormat error: {0}", Marshal.GetLastWin32Error()));
|
2008-02-28 14:57:07 +01:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
#region void SetGraphicsModeARB(GraphicsMode format, IWindowInfo window)
|
2008-02-28 14:57:07 +01:00
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
void SetGraphicsModeARB(GraphicsMode format, IWindowInfo window)
|
2008-02-28 14:57:07 +01:00
|
|
|
|
{
|
2008-03-03 13:44:56 +01:00
|
|
|
|
throw new NotImplementedException();
|
2008-02-28 14:57:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2008-01-11 21:24:48 +01:00
|
|
|
|
#endregion
|
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
#region --- Internal Methods ---
|
2008-01-11 21:24:48 +01:00
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
#region internal IntPtr DeviceContext
|
2008-01-11 21:24:48 +01:00
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
internal IntPtr DeviceContext
|
2008-01-11 21:24:48 +01:00
|
|
|
|
{
|
2008-03-03 13:44:56 +01:00
|
|
|
|
get
|
2008-01-11 21:24:48 +01:00
|
|
|
|
{
|
2008-03-03 13:44:56 +01:00
|
|
|
|
if (currentWindow != null)
|
|
|
|
|
return currentWindow.DeviceContext;
|
|
|
|
|
return IntPtr.Zero;
|
2008-01-11 21:24:48 +01:00
|
|
|
|
}
|
2007-09-29 17:24:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-23 01:19:22 +01:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2008-01-31 14:15:17 +01:00
|
|
|
|
#region static ContextHandle GetCurrentContext()
|
|
|
|
|
|
|
|
|
|
static ContextHandle GetCurrentContext()
|
|
|
|
|
{
|
|
|
|
|
return Wgl.GetCurrentContext();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2008-01-23 01:19:22 +01:00
|
|
|
|
#endregion
|
|
|
|
|
|
2008-02-28 14:57:07 +01:00
|
|
|
|
#region --- Overrides ---
|
|
|
|
|
|
|
|
|
|
/// <summary>Returns a System.String describing this OpenGL context.</summary>
|
|
|
|
|
/// <returns>A System.String describing this OpenGL context.</returns>
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
2008-03-01 14:15:31 +01:00
|
|
|
|
return (this as IGraphicsContextInternal).Context.ToString();
|
2008-02-28 14:57:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-07-23 02:15:18 +02:00
|
|
|
|
#region --- IDisposable Members ---
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
2007-08-10 18:55:24 +02:00
|
|
|
|
Dispose(true);
|
2007-07-23 02:15:18 +02:00
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Dispose(bool calledManually)
|
|
|
|
|
{
|
|
|
|
|
if (!disposed)
|
|
|
|
|
{
|
2007-12-09 19:15:51 +01:00
|
|
|
|
DestroyContext();
|
2007-07-23 02:15:18 +02:00
|
|
|
|
|
|
|
|
|
if (calledManually)
|
|
|
|
|
{
|
|
|
|
|
// Safe to clean managed resources
|
|
|
|
|
}
|
|
|
|
|
disposed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~WinGLContext()
|
|
|
|
|
{
|
|
|
|
|
Dispose(false);
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-09 19:15:51 +01:00
|
|
|
|
#region private void DestroyContext()
|
2007-07-23 02:15:18 +02:00
|
|
|
|
|
2007-12-09 19:15:51 +01:00
|
|
|
|
private void DestroyContext()
|
2007-07-23 02:15:18 +02:00
|
|
|
|
{
|
2007-12-09 19:15:51 +01:00
|
|
|
|
if (Destroy != null)
|
|
|
|
|
Destroy(this, EventArgs.Empty);
|
|
|
|
|
|
2007-07-23 02:15:18 +02:00
|
|
|
|
if (renderContext != IntPtr.Zero)
|
|
|
|
|
{
|
2008-04-20 19:52:27 +02:00
|
|
|
|
try
|
2007-07-23 02:15:18 +02:00
|
|
|
|
{
|
2008-04-20 19:52:27 +02:00
|
|
|
|
if (!Wgl.Imports.MakeCurrent(IntPtr.Zero, IntPtr.Zero))
|
|
|
|
|
Debug.Print("Failed to make OpenGL context {0} non current. Error: {1}",
|
|
|
|
|
renderContext.ToString(), Marshal.GetLastWin32Error());
|
|
|
|
|
|
|
|
|
|
if (!Wgl.Imports.DeleteContext(renderContext))
|
|
|
|
|
Debug.Print("Failed to destroy OpenGL context {0}. Error: {1}",
|
|
|
|
|
renderContext.ToString(), Marshal.GetLastWin32Error());
|
|
|
|
|
}
|
|
|
|
|
catch (AccessViolationException e)
|
|
|
|
|
{
|
|
|
|
|
Debug.WriteLine("An access violation occured while destroying the OpenGL context. Please report at http://www.opentk.com.");
|
|
|
|
|
Debug.Indent();
|
|
|
|
|
Debug.Print("Marshal.GetLastWin32Error(): {0}", Marshal.GetLastWin32Error().ToString());
|
|
|
|
|
Debug.WriteLine(e.ToString());
|
|
|
|
|
Debug.Unindent();
|
2007-07-23 02:15:18 +02:00
|
|
|
|
}
|
2008-01-11 21:24:48 +01:00
|
|
|
|
renderContext = null;
|
2007-07-23 02:15:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
//if (deviceContext != IntPtr.Zero)
|
|
|
|
|
//{
|
|
|
|
|
// if (!Functions.ReleaseDC(this.windowInfo.Handle, deviceContext))
|
|
|
|
|
// {
|
|
|
|
|
// //throw new ApplicationException("Could not release device context. Error: " + Marshal.GetLastWin32Error());
|
|
|
|
|
// //Debug.Print("Could not destroy the device context. Error: {0}", Marshal.GetLastWin32Error());
|
|
|
|
|
// }
|
|
|
|
|
//}
|
2007-08-20 14:25:48 +02:00
|
|
|
|
|
2007-12-09 19:15:51 +01:00
|
|
|
|
/*
|
2007-07-23 02:15:18 +02:00
|
|
|
|
if (opengl32Handle != IntPtr.Zero)
|
|
|
|
|
{
|
2007-09-26 13:55:24 +02:00
|
|
|
|
if (!Functions.FreeLibrary(opengl32Handle))
|
2007-07-23 02:15:18 +02:00
|
|
|
|
{
|
2007-09-02 02:16:22 +02:00
|
|
|
|
//throw new ApplicationException("FreeLibray call failed ('opengl32.dll'), Error: " + Marshal.GetLastWin32Error());
|
|
|
|
|
//Debug.Print("Could not release {0}. Error: {1}", opengl32Name, Marshal.GetLastWin32Error());
|
2007-07-23 02:15:18 +02:00
|
|
|
|
}
|
|
|
|
|
opengl32Handle = IntPtr.Zero;
|
|
|
|
|
}
|
2007-12-09 19:15:51 +01:00
|
|
|
|
*/
|
2007-07-23 02:15:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|