* GLControl.cs: Delayed creation of IGLControl implementation until

the OnHandleCreated event.

* X11GLControl.cs: Removed unused Control field.
Added checks for null parameters.
This commit is contained in:
the_fiddler 2009-09-02 12:00:44 +00:00
parent da8355de48
commit 7be5bc9648
2 changed files with 47 additions and 31 deletions

View file

@ -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 ---
/// <summary>Raises the HandleCreated event.</summary>
/// <param name="e">Not used.</param>
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
if (implementation == null)
{
if (DesignMode)
implementation = new DummyGLControl();
else
implementation = new GLControlFactory().CreateGLControl(format, this);
}
this.Context = implementation.CreateContext(major, minor, flags);
this.window_info = implementation.WindowInfo;
this.MakeCurrent();
Context = implementation.CreateContext(major, minor, flags);
MakeCurrent();
((IGraphicsContextInternal)this.Context).LoadAll();
base.OnHandleCreated(e);
}
/// <summary>Raises the HandleDestroyed event.</summary>
/// <param name="e">Not used.</param>
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);
}
/// <summary>
@ -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
/// </summary>
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

View file

@ -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);
}