Opentk/Source/OpenTK/Platform/Windows/WinGLControl.cs

145 lines
3.3 KiB
C#
Raw Normal View History

#region --- License ---
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
* Contributions from Erik Ylvisaker
* See license.txt for license info
*/
#endregion
#region --- Using directives ---
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
2007-08-20 12:25:48 +00:00
using System.Diagnostics;
#endregion
namespace OpenTK.Platform.Windows
{
sealed class WinGLControl : IGLControl, IDisposable
{
private WinGLContext glContext;
private bool fullscreen;
private ResizeEventArgs resizeEventArgs = new ResizeEventArgs();
2007-08-20 12:25:48 +00:00
private DisplayMode mode;
private bool disposed;
private MSG msg; // Used only by the IsIdle event.
#region --- Constructors ---
2007-08-20 10:46:37 +00:00
2007-08-20 12:25:48 +00:00
public WinGLControl(UserControl c, DisplayMode mode)
2007-08-09 12:08:03 +00:00
{
2007-08-20 12:25:48 +00:00
this.mode = mode;
c.HandleCreated += new EventHandler(c_HandleCreated);
c.HandleDestroyed += new EventHandler(c_HandleDestroyed);
2007-08-09 12:08:03 +00:00
}
2007-08-20 10:46:37 +00:00
#endregion
2007-08-20 12:25:48 +00:00
void c_HandleCreated(object sender, EventArgs e)
{
2007-08-20 12:25:48 +00:00
Debug.Print("GLControl handle created, creating WinGLContext.");
Debug.Indent();
2007-08-20 10:46:37 +00:00
2007-08-20 12:25:48 +00:00
try
{
if (glContext != null)
glContext.Dispose();
glContext = new WinGLContext(mode, new WindowInfo(sender as Control));
2007-08-20 12:25:48 +00:00
glContext.CreateContext();
glContext.MakeCurrent();
2007-08-20 12:25:48 +00:00
}
catch (ApplicationException expt)
{
Debug.Print(expt.ToString());
throw;
}
finally
{
Debug.Unindent();
}
}
void c_HandleDestroyed(object sender, EventArgs e)
{
glContext.Dispose();
}
#region --- IGLControl members ---
#region public bool IsIdle
public bool IsIdle
{
get
{
return !API.PeekMessage(ref msg, IntPtr.Zero, 0, 0, 0);
}
}
#endregion
#region public bool Fullscreen
public bool Fullscreen
{
get
{
return fullscreen;
}
set
{
fullscreen = false;
//throw new NotImplementedException();
}
}
#endregion
#region public IGLContext Context
public IGLContext Context
{
get { return glContext; }
}
#endregion
#endregion
#region --- IDisposable Members ---
public void Dispose()
{
this.Dispose(true);
//GC.SuppressFinalize(this);
}
private void Dispose(bool calledManually)
{
if (!disposed)
{
// Clean unmanaged resources here:
if (calledManually)
{
// Safe to clean managed resources
glContext.Dispose();
}
disposed = true;
}
}
/*
~WinGLControl()
{
Dispose(false);
}
*/
#endregion
}
}