mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-23 19:55:29 +00:00
* 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:
parent
da8355de48
commit
7be5bc9648
|
@ -48,7 +48,6 @@ namespace OpenTK
|
||||||
IGraphicsContext context;
|
IGraphicsContext context;
|
||||||
IGLControl implementation;
|
IGLControl implementation;
|
||||||
GraphicsMode format;
|
GraphicsMode format;
|
||||||
IWindowInfo window_info;
|
|
||||||
int major, minor;
|
int major, minor;
|
||||||
GraphicsContextFlags flags;
|
GraphicsContextFlags flags;
|
||||||
|
|
||||||
|
@ -90,50 +89,64 @@ namespace OpenTK
|
||||||
this.minor = minor;
|
this.minor = minor;
|
||||||
this.flags = flags;
|
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();
|
this.CreateControl();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region --- Private Methods ---
|
||||||
|
|
||||||
|
IGLControl Implementation
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (implementation == null)
|
||||||
|
CreateControl();
|
||||||
|
|
||||||
|
return implementation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region --- Protected Methods ---
|
#region --- Protected Methods ---
|
||||||
|
|
||||||
/// <summary>Raises the HandleCreated event.</summary>
|
/// <summary>Raises the HandleCreated event.</summary>
|
||||||
/// <param name="e">Not used.</param>
|
/// <param name="e">Not used.</param>
|
||||||
protected override void OnHandleCreated(EventArgs e)
|
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);
|
Context = implementation.CreateContext(major, minor, flags);
|
||||||
|
MakeCurrent();
|
||||||
this.window_info = implementation.WindowInfo;
|
|
||||||
this.MakeCurrent();
|
|
||||||
((IGraphicsContextInternal)this.Context).LoadAll();
|
((IGraphicsContextInternal)this.Context).LoadAll();
|
||||||
|
|
||||||
|
base.OnHandleCreated(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Raises the HandleDestroyed event.</summary>
|
/// <summary>Raises the HandleDestroyed event.</summary>
|
||||||
/// <param name="e">Not used.</param>
|
/// <param name="e">Not used.</param>
|
||||||
protected override void OnHandleDestroyed(EventArgs e)
|
protected override void OnHandleDestroyed(EventArgs e)
|
||||||
{
|
{
|
||||||
base.OnHandleDestroyed(e);
|
if (Context != null)
|
||||||
if (this.Context != null)
|
|
||||||
{
|
{
|
||||||
this.Context.Dispose();
|
Context.Dispose();
|
||||||
this.Context = null;
|
Context = null;
|
||||||
}
|
}
|
||||||
this.window_info.Dispose();
|
|
||||||
this.window_info = null;
|
if (implementation != null)
|
||||||
|
{
|
||||||
|
implementation.WindowInfo.Dispose();
|
||||||
|
implementation = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
base.OnHandleDestroyed(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -155,7 +168,7 @@ namespace OpenTK
|
||||||
protected override void OnResize(EventArgs e)
|
protected override void OnResize(EventArgs e)
|
||||||
{
|
{
|
||||||
if (context != null)
|
if (context != null)
|
||||||
context.Update(window_info);
|
context.Update(Implementation.WindowInfo);
|
||||||
|
|
||||||
base.OnResize(e);
|
base.OnResize(e);
|
||||||
}
|
}
|
||||||
|
@ -167,7 +180,7 @@ namespace OpenTK
|
||||||
protected override void OnParentChanged(EventArgs e)
|
protected override void OnParentChanged(EventArgs e)
|
||||||
{
|
{
|
||||||
if (context != null)
|
if (context != null)
|
||||||
context.Update(window_info);
|
context.Update(Implementation.WindowInfo);
|
||||||
|
|
||||||
base.OnParentChanged(e);
|
base.OnParentChanged(e);
|
||||||
}
|
}
|
||||||
|
@ -196,7 +209,7 @@ namespace OpenTK
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void MakeCurrent()
|
public void MakeCurrent()
|
||||||
{
|
{
|
||||||
this.Context.MakeCurrent(this.window_info);
|
Context.MakeCurrent(Implementation.WindowInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -209,7 +222,7 @@ namespace OpenTK
|
||||||
[Browsable(false)]
|
[Browsable(false)]
|
||||||
public bool IsIdle
|
public bool IsIdle
|
||||||
{
|
{
|
||||||
get { return implementation.IsIdle; }
|
get { return Implementation.IsIdle; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
@ -29,15 +29,18 @@ namespace OpenTK
|
||||||
#region Fields
|
#region Fields
|
||||||
|
|
||||||
GraphicsMode mode;
|
GraphicsMode mode;
|
||||||
Control control;
|
|
||||||
IWindowInfo window_info;
|
IWindowInfo window_info;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
internal X11GLControl(GraphicsMode mode, Control control)
|
internal X11GLControl(GraphicsMode mode, Control control)
|
||||||
{
|
{
|
||||||
|
if (mode == null)
|
||||||
|
throw new ArgumentNullException("mode");
|
||||||
|
if (control == null)
|
||||||
|
throw new ArgumentNullException("control");
|
||||||
|
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
this.control = control;
|
|
||||||
|
|
||||||
window_info = Utilities.CreateWindowInfo(mode, control.Handle, true);
|
window_info = Utilities.CreateWindowInfo(mode, control.Handle, true);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue