forked from Mirror/Ryujinx
Remove ScopedGlContext (#933)
As MakeCurrent can be slow to execute, this PR changes GLRenderer to not have to reexecute MakeCurrent when processing frames.
This commit is contained in:
parent
949bb81a9e
commit
dbe3f938c7
2 changed files with 34 additions and 76 deletions
|
@ -84,7 +84,7 @@ namespace Ryujinx.Ui
|
||||||
|
|
||||||
private void GLRenderer_ShuttingDown(object sender, EventArgs args)
|
private void GLRenderer_ShuttingDown(object sender, EventArgs args)
|
||||||
{
|
{
|
||||||
Exit();
|
_device.DisposeGpu();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Parent_FocusOutEvent(object o, Gtk.FocusOutEventArgs args)
|
private void Parent_FocusOutEvent(object o, Gtk.FocusOutEventArgs args)
|
||||||
|
@ -146,7 +146,7 @@ namespace Ryujinx.Ui
|
||||||
|
|
||||||
private void GLRenderer_Initialized(object sender, EventArgs e)
|
private void GLRenderer_Initialized(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
// Release the GL exclusivity that OpenTK gave us.
|
// Release the GL exclusivity that OpenTK gave us as we aren't going to use it in GTK Thread.
|
||||||
GraphicsContext.MakeCurrent(null);
|
GraphicsContext.MakeCurrent(null);
|
||||||
|
|
||||||
WaitEvent.Set();
|
WaitEvent.Set();
|
||||||
|
@ -235,13 +235,6 @@ namespace Ryujinx.Ui
|
||||||
|
|
||||||
IsStopped = true;
|
IsStopped = true;
|
||||||
IsActive = false;
|
IsActive = false;
|
||||||
|
|
||||||
using (ScopedGlContext scopedGLContext = new ScopedGlContext(WindowInfo, GraphicsContext))
|
|
||||||
{
|
|
||||||
_device.DisposeGpu();
|
|
||||||
}
|
|
||||||
|
|
||||||
WaitEvent.Set();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Initialize()
|
public void Initialize()
|
||||||
|
@ -256,12 +249,15 @@ namespace Ryujinx.Ui
|
||||||
|
|
||||||
public void Render()
|
public void Render()
|
||||||
{
|
{
|
||||||
using (ScopedGlContext scopedGLContext = new ScopedGlContext(WindowInfo, GraphicsContext))
|
// First take exclusivity on the OpenGL context.
|
||||||
{
|
GraphicsContext.MakeCurrent(WindowInfo);
|
||||||
|
|
||||||
_renderer.Initialize();
|
_renderer.Initialize();
|
||||||
|
|
||||||
|
// Make sure the first frame is not transparent.
|
||||||
|
GL.ClearColor(OpenTK.Color.Black);
|
||||||
|
GL.Clear(ClearBufferMask.ColorBufferBit);
|
||||||
SwapBuffers();
|
SwapBuffers();
|
||||||
}
|
|
||||||
|
|
||||||
while (IsActive)
|
while (IsActive)
|
||||||
{
|
{
|
||||||
|
@ -270,8 +266,6 @@ namespace Ryujinx.Ui
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
using (ScopedGlContext scopedGLContext = new ScopedGlContext(WindowInfo, GraphicsContext))
|
|
||||||
{
|
|
||||||
_ticks += _chrono.ElapsedTicks;
|
_ticks += _chrono.ElapsedTicks;
|
||||||
|
|
||||||
_chrono.Restart();
|
_chrono.Restart();
|
||||||
|
@ -309,7 +303,6 @@ namespace Ryujinx.Ui
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void SwapBuffers()
|
public void SwapBuffers()
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
using OpenTK.Graphics;
|
|
||||||
using OpenTK.Platform;
|
|
||||||
using System;
|
|
||||||
using System.Threading;
|
|
||||||
|
|
||||||
namespace Ryujinx.Ui
|
|
||||||
{
|
|
||||||
class ScopedGlContext : IDisposable
|
|
||||||
{
|
|
||||||
private IGraphicsContext _graphicsContext;
|
|
||||||
|
|
||||||
private static readonly object _lock = new object();
|
|
||||||
|
|
||||||
public ScopedGlContext(IWindowInfo windowInfo, IGraphicsContext graphicsContext)
|
|
||||||
{
|
|
||||||
_graphicsContext = graphicsContext;
|
|
||||||
|
|
||||||
Monitor.Enter(_lock);
|
|
||||||
|
|
||||||
MakeCurrent(windowInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void MakeCurrent(IWindowInfo windowInfo)
|
|
||||||
{
|
|
||||||
_graphicsContext.MakeCurrent(windowInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
MakeCurrent(null);
|
|
||||||
|
|
||||||
Monitor.Exit(_lock);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue