2022-09-19 11:05:26 -07:00
|
|
|
using OpenTK.Graphics.OpenGL;
|
|
|
|
using Ryujinx.Common.Configuration;
|
2023-01-15 16:14:01 -08:00
|
|
|
using Ryujinx.Graphics.GAL;
|
|
|
|
using Ryujinx.Graphics.OpenGL;
|
|
|
|
using Ryujinx.Ui.Common.Configuration;
|
2022-09-19 11:05:26 -07:00
|
|
|
using SPB.Graphics;
|
|
|
|
using SPB.Graphics.OpenGL;
|
|
|
|
using SPB.Platform;
|
|
|
|
using SPB.Platform.WGL;
|
|
|
|
using SPB.Windowing;
|
|
|
|
using System;
|
|
|
|
|
2023-01-15 16:14:01 -08:00
|
|
|
namespace Ryujinx.Ava.UI.Renderer
|
2022-09-19 11:05:26 -07:00
|
|
|
{
|
2023-01-15 16:14:01 -08:00
|
|
|
public class EmbeddedWindowOpenGL : EmbeddedWindow
|
2022-09-19 11:05:26 -07:00
|
|
|
{
|
|
|
|
private SwappableNativeWindowBase _window;
|
2023-01-15 16:14:01 -08:00
|
|
|
|
2022-09-19 11:05:26 -07:00
|
|
|
public OpenGLContextBase Context { get; set; }
|
|
|
|
|
2023-01-15 16:14:01 -08:00
|
|
|
public EmbeddedWindowOpenGL() { }
|
2022-09-19 11:05:26 -07:00
|
|
|
|
|
|
|
protected override void OnWindowDestroying()
|
|
|
|
{
|
|
|
|
Context.Dispose();
|
2023-01-15 16:14:01 -08:00
|
|
|
|
2022-09-19 11:05:26 -07:00
|
|
|
base.OnWindowDestroying();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnWindowCreated()
|
|
|
|
{
|
|
|
|
base.OnWindowCreated();
|
|
|
|
|
|
|
|
if (OperatingSystem.IsWindows())
|
|
|
|
{
|
|
|
|
_window = new WGLWindow(new NativeHandle(WindowHandle));
|
|
|
|
}
|
|
|
|
else if (OperatingSystem.IsLinux())
|
|
|
|
{
|
|
|
|
_window = X11Window;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new PlatformNotSupportedException();
|
|
|
|
}
|
2022-11-24 06:08:27 -08:00
|
|
|
|
2022-09-19 11:05:26 -07:00
|
|
|
var flags = OpenGLContextFlags.Compat;
|
2023-01-15 16:14:01 -08:00
|
|
|
if (ConfigurationState.Instance.Logger.GraphicsDebugLevel != GraphicsDebugLevel.None)
|
2022-09-19 11:05:26 -07:00
|
|
|
{
|
|
|
|
flags |= OpenGLContextFlags.Debug;
|
|
|
|
}
|
|
|
|
|
2023-01-15 16:14:01 -08:00
|
|
|
var graphicsMode = Environment.OSVersion.Platform == PlatformID.Unix ? new FramebufferFormat(new ColorFormat(8, 8, 8, 0), 16, 0, ColorFormat.Zero, 0, 2, false) : FramebufferFormat.Default;
|
|
|
|
|
|
|
|
Context = PlatformHelper.CreateOpenGLContext(graphicsMode, 3, 3, flags);
|
2022-09-19 11:05:26 -07:00
|
|
|
|
|
|
|
Context.Initialize(_window);
|
|
|
|
Context.MakeCurrent(_window);
|
|
|
|
|
2023-01-15 16:14:01 -08:00
|
|
|
GL.LoadBindings(new OpenTKBindingsContext(Context.GetProcAddress));
|
2022-09-19 11:05:26 -07:00
|
|
|
|
|
|
|
Context.MakeCurrent(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void MakeCurrent()
|
|
|
|
{
|
2022-11-24 06:08:27 -08:00
|
|
|
Context?.MakeCurrent(_window);
|
2022-09-19 11:05:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public void MakeCurrent(NativeWindowBase window)
|
|
|
|
{
|
2022-11-24 06:08:27 -08:00
|
|
|
Context?.MakeCurrent(window);
|
2022-09-19 11:05:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SwapBuffers()
|
|
|
|
{
|
2023-01-15 16:14:01 -08:00
|
|
|
_window?.SwapBuffers();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void InitializeBackgroundContext(IRenderer renderer)
|
|
|
|
{
|
|
|
|
(renderer as OpenGLRenderer)?.InitializeBackgroundContext(SPBOpenGLContext.CreateBackgroundContext(Context));
|
|
|
|
|
|
|
|
MakeCurrent();
|
2022-09-19 11:05:26 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|