#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; using System.Diagnostics; #endregion namespace OpenTK.Platform.Windows { sealed class WinGLControl : IGLControl, IDisposable { private WinGLContext glContext; private bool fullscreen; private ResizeEventArgs resizeEventArgs = new ResizeEventArgs(); private DisplayMode mode; private bool disposed; private MSG msg; // Used only by the IsIdle event. #region --- Constructors --- public WinGLControl(UserControl c, DisplayMode mode) { this.mode = mode; c.HandleCreated += new EventHandler(c_HandleCreated); c.HandleDestroyed += new EventHandler(c_HandleDestroyed); } #endregion void c_HandleCreated(object sender, EventArgs e) { Debug.Print("GLControl handle created, creating WinGLContext."); Debug.Indent(); try { if (glContext != null) glContext.Dispose(); glContext = new WinGLContext(mode, new WindowInfo(sender as Control)); glContext.CreateContext(); glContext.MakeCurrent(); } 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 } }