mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-01-12 15:35:29 +00:00
Added CreateContext and DestroyContext functions. Better handling of DisplayModes. Added Mode property.
This commit is contained in:
parent
9504ea7ad2
commit
73468f8fa3
|
@ -23,15 +23,23 @@ namespace OpenTK
|
||||||
{
|
{
|
||||||
IGLContext context;
|
IGLContext context;
|
||||||
IPlatformIdle idle;
|
IPlatformIdle idle;
|
||||||
|
DisplayMode display_mode;
|
||||||
|
|
||||||
#region --- Constructor ---
|
#region --- Constructor ---
|
||||||
|
|
||||||
public GLControl()
|
public GLControl()
|
||||||
|
: this(null)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public GLControl(DisplayMode mode)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
this.SetStyle(ControlStyles.UserPaint, true);
|
this.SetStyle(ControlStyles.UserPaint, true);
|
||||||
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
||||||
|
|
||||||
|
this.display_mode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -41,28 +49,13 @@ namespace OpenTK
|
||||||
protected override void OnHandleCreated(EventArgs e)
|
protected override void OnHandleCreated(EventArgs e)
|
||||||
{
|
{
|
||||||
base.OnHandleCreated(e);
|
base.OnHandleCreated(e);
|
||||||
|
this.CreateContext();
|
||||||
// For maximum compatibility we do not set a specific depth for the DisplayMode.
|
|
||||||
// The driver is free to find the best match.
|
|
||||||
WindowInfo info = new WindowInfo(this);
|
|
||||||
if (!this.DesignMode)
|
|
||||||
{
|
|
||||||
context = new GLContext(new DisplayMode(), info);
|
|
||||||
context.CreateContext();
|
|
||||||
idle = new PlatformIdle(info);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
context = new DummyGLContext();
|
|
||||||
idle = new DummyPlatformIdle();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnHandleDestroyed(EventArgs e)
|
protected override void OnHandleDestroyed(EventArgs e)
|
||||||
{
|
{
|
||||||
base.OnHandleDestroyed(e);
|
base.OnHandleDestroyed(e);
|
||||||
|
this.DestroyContext();
|
||||||
context.Dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -74,6 +67,7 @@ namespace OpenTK
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a value indicating whether the current thread contains pending system messages.
|
/// Gets a value indicating whether the current thread contains pending system messages.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Browsable(false)]
|
||||||
public bool IsIdle
|
public bool IsIdle
|
||||||
{
|
{
|
||||||
get { return idle.IsIdle; }
|
get { return idle.IsIdle; }
|
||||||
|
@ -86,9 +80,11 @@ namespace OpenTK
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets an interface to the underlying GLContext used by this GLControl.
|
/// Gets an interface to the underlying GLContext used by this GLControl.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Browsable(false)]
|
||||||
public IGLContext Context
|
public IGLContext Context
|
||||||
{
|
{
|
||||||
get { return context; }
|
get { return context; }
|
||||||
|
private set { context = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -98,6 +94,7 @@ namespace OpenTK
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the aspect ratio of this GLControl.
|
/// Gets the aspect ratio of this GLControl.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Description("The aspect ratio of the client area of this GLControl.")]
|
||||||
public float AspectRatio
|
public float AspectRatio
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@ -113,6 +110,7 @@ namespace OpenTK
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating whether vsync is active for this GLControl.
|
/// Gets or sets a value indicating whether vsync is active for this GLControl.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Description("Indicates whether GLControl updates are synced to the monitor's refresh.")]
|
||||||
public bool VSync
|
public bool VSync
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@ -130,6 +128,21 @@ namespace OpenTK
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region public DisplayMode Mode
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the DisplayMode of the GLContext attached to this GLControl.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// You cannot change the DisplayMode of an existing GLContext.
|
||||||
|
/// </remarks>
|
||||||
|
public DisplayMode Mode
|
||||||
|
{
|
||||||
|
get { return Context.Mode; }
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region --- Public Methods ---
|
#region --- Public Methods ---
|
||||||
|
@ -159,6 +172,50 @@ namespace OpenTK
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region public void CreateContext()
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a GLContext and attaches it to this GLControl.
|
||||||
|
/// </summary>
|
||||||
|
public void CreateContext()
|
||||||
|
{
|
||||||
|
if (display_mode == null)
|
||||||
|
display_mode = new DisplayMode();
|
||||||
|
WindowInfo info = new WindowInfo(this);
|
||||||
|
|
||||||
|
if (!this.DesignMode)
|
||||||
|
{
|
||||||
|
// Mono's implementation of Windows.Forms on X11 does not allow the context to
|
||||||
|
// have a different colordepth from the parent. To combat this, we do not set a
|
||||||
|
// specific depth for the DisplayMode - we let the driver select one instead.
|
||||||
|
display_mode.Color = new ColorMode(0);
|
||||||
|
context = new GLContext(display_mode, info);
|
||||||
|
context.CreateContext();
|
||||||
|
idle = new PlatformIdle(info);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context = new DummyGLContext(display_mode);
|
||||||
|
idle = new DummyPlatformIdle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region public void DestroyContext()
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Destroys the GLContext attached to this GLControl.
|
||||||
|
/// </summary>
|
||||||
|
/// <exception cref="NullReferenceException">Occurs when no GLContext is attached.</exception>
|
||||||
|
public void DestroyContext()
|
||||||
|
{
|
||||||
|
Context.Dispose();
|
||||||
|
Context = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue