diff --git a/Source/GLControl/GLControl.cs b/Source/GLControl/GLControl.cs
index 5fb77262..b9de5cde 100644
--- a/Source/GLControl/GLControl.cs
+++ b/Source/GLControl/GLControl.cs
@@ -48,7 +48,6 @@ namespace OpenTK
IGraphicsContext context;
IGLControl implementation;
GraphicsMode format;
- IWindowInfo window_info;
int major, minor;
GraphicsContextFlags flags;
@@ -90,50 +89,64 @@ namespace OpenTK
this.minor = minor;
this.flags = flags;
- // On Windows, you first need to create the window, then set the pixel format.
- // On X11, you first need to select the visual, then create the window.
- // On OSX, the pixel format needs to be selected before the GL context.
- // Right now, pixel formats/visuals are selected during context creation. In the future,
- // it would be better to decouple selection from context creation, which will allow us
- // to clean up this hacky code. The best option is to do this along with multisampling
- // support.
- if (DesignMode)
- implementation = new DummyGLControl();
- else
- implementation = new GLControlFactory().CreateGLControl(mode, this);
-
this.CreateControl();
}
#endregion
+ #region --- Private Methods ---
+
+ IGLControl Implementation
+ {
+ get
+ {
+ if (implementation == null)
+ CreateControl();
+
+ return implementation;
+ }
+ }
+
+ #endregion
+
#region --- Protected Methods ---
/// Raises the HandleCreated event.
/// Not used.
protected override void OnHandleCreated(EventArgs e)
{
- base.OnHandleCreated(e);
-
- this.Context = implementation.CreateContext(major, minor, flags);
-
- this.window_info = implementation.WindowInfo;
- this.MakeCurrent();
+ if (implementation == null)
+ {
+ if (DesignMode)
+ implementation = new DummyGLControl();
+ else
+ implementation = new GLControlFactory().CreateGLControl(format, this);
+ }
+
+ Context = implementation.CreateContext(major, minor, flags);
+ MakeCurrent();
((IGraphicsContextInternal)this.Context).LoadAll();
+
+ base.OnHandleCreated(e);
}
/// Raises the HandleDestroyed event.
/// Not used.
protected override void OnHandleDestroyed(EventArgs e)
{
- base.OnHandleDestroyed(e);
- if (this.Context != null)
+ if (Context != null)
{
- this.Context.Dispose();
- this.Context = null;
+ Context.Dispose();
+ Context = null;
}
- this.window_info.Dispose();
- this.window_info = null;
+
+ if (implementation != null)
+ {
+ implementation.WindowInfo.Dispose();
+ implementation = null;
+ }
+
+ base.OnHandleDestroyed(e);
}
///
@@ -155,7 +168,7 @@ namespace OpenTK
protected override void OnResize(EventArgs e)
{
if (context != null)
- context.Update(window_info);
+ context.Update(Implementation.WindowInfo);
base.OnResize(e);
}
@@ -167,7 +180,7 @@ namespace OpenTK
protected override void OnParentChanged(EventArgs e)
{
if (context != null)
- context.Update(window_info);
+ context.Update(Implementation.WindowInfo);
base.OnParentChanged(e);
}
@@ -196,7 +209,7 @@ namespace OpenTK
///
public void MakeCurrent()
{
- this.Context.MakeCurrent(this.window_info);
+ Context.MakeCurrent(Implementation.WindowInfo);
}
#endregion
@@ -209,7 +222,7 @@ namespace OpenTK
[Browsable(false)]
public bool IsIdle
{
- get { return implementation.IsIdle; }
+ get { return Implementation.IsIdle; }
}
#endregion
diff --git a/Source/GLControl/X11GLControl.cs b/Source/GLControl/X11GLControl.cs
index cbf75c73..dc811721 100644
--- a/Source/GLControl/X11GLControl.cs
+++ b/Source/GLControl/X11GLControl.cs
@@ -29,15 +29,18 @@ namespace OpenTK
#region Fields
GraphicsMode mode;
- Control control;
IWindowInfo window_info;
#endregion
internal X11GLControl(GraphicsMode mode, Control control)
{
+ if (mode == null)
+ throw new ArgumentNullException("mode");
+ if (control == null)
+ throw new ArgumentNullException("control");
+
this.mode = mode;
- this.control = control;
window_info = Utilities.CreateWindowInfo(mode, control.Handle, true);
}