2007-07-23 00:15:18 +00:00
|
|
|
|
#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;
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
namespace OpenTK.Platform.Windows
|
|
|
|
|
{
|
2007-09-02 00:16:22 +00:00
|
|
|
|
sealed class WinGLControl : IGLControl, IDisposable
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
|
|
|
|
private WinGLContext glContext;
|
|
|
|
|
private bool fullscreen;
|
|
|
|
|
private ResizeEventArgs resizeEventArgs = new ResizeEventArgs();
|
2007-08-20 12:25:48 +00:00
|
|
|
|
private DisplayMode mode;
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
|
|
|
|
private bool disposed;
|
2007-09-02 00:16:22 +00:00
|
|
|
|
private MSG msg; // Used only by the IsIdle event.
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
2007-09-02 00:16:22 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2007-08-20 12:25:48 +00:00
|
|
|
|
void c_HandleCreated(object sender, EventArgs e)
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
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
|
|
|
|
|
{
|
2007-09-09 11:52:09 +00:00
|
|
|
|
if (glContext != null)
|
|
|
|
|
glContext.Dispose();
|
|
|
|
|
|
|
|
|
|
glContext = new WinGLContext(mode, new WindowInfo(sender as Control));
|
2007-08-20 12:25:48 +00:00
|
|
|
|
glContext.CreateContext();
|
2007-08-21 12:04:01 +00:00
|
|
|
|
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();
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-02 00:16:22 +00:00
|
|
|
|
#region --- IGLControl members ---
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
|
|
|
|
#region public bool IsIdle
|
|
|
|
|
|
|
|
|
|
public bool IsIdle
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2007-09-26 11:55:24 +00:00
|
|
|
|
return !Functions.PeekMessage(ref msg, IntPtr.Zero, 0, 0, 0);
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public bool Fullscreen
|
|
|
|
|
|
|
|
|
|
public bool Fullscreen
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return fullscreen;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2007-08-05 13:51:07 +00:00
|
|
|
|
fullscreen = false;
|
|
|
|
|
//throw new NotImplementedException();
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-08-04 12:09:58 +00:00
|
|
|
|
#region public IGLContext Context
|
|
|
|
|
|
|
|
|
|
public IGLContext Context
|
|
|
|
|
{
|
|
|
|
|
get { return glContext; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-07-23 00:15:18 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region --- IDisposable Members ---
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
this.Dispose(true);
|
2007-09-02 00:16:22 +00:00
|
|
|
|
//GC.SuppressFinalize(this);
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Dispose(bool calledManually)
|
|
|
|
|
{
|
|
|
|
|
if (!disposed)
|
|
|
|
|
{
|
|
|
|
|
// Clean unmanaged resources here:
|
|
|
|
|
|
|
|
|
|
if (calledManually)
|
|
|
|
|
{
|
|
|
|
|
// Safe to clean managed resources
|
|
|
|
|
glContext.Dispose();
|
|
|
|
|
}
|
|
|
|
|
disposed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-09-02 00:16:22 +00:00
|
|
|
|
/*
|
2007-07-23 00:15:18 +00:00
|
|
|
|
~WinGLControl()
|
|
|
|
|
{
|
|
|
|
|
Dispose(false);
|
|
|
|
|
}
|
2007-09-02 00:16:22 +00:00
|
|
|
|
*/
|
2007-07-23 00:15:18 +00:00
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|