2022-09-19 20:05:26 +02:00
|
|
|
using OpenTK.Graphics.OpenGL;
|
|
|
|
using Ryujinx.Common.Configuration;
|
2023-01-16 01:14:01 +01:00
|
|
|
using Ryujinx.Graphics.GAL;
|
|
|
|
using Ryujinx.Graphics.OpenGL;
|
|
|
|
using Ryujinx.Ui.Common.Configuration;
|
2022-09-19 20:05:26 +02:00
|
|
|
using SPB.Graphics;
|
|
|
|
using SPB.Graphics.OpenGL;
|
|
|
|
using SPB.Platform;
|
|
|
|
using SPB.Platform.WGL;
|
|
|
|
using SPB.Windowing;
|
|
|
|
using System;
|
|
|
|
|
2023-01-16 01:14:01 +01:00
|
|
|
namespace Ryujinx.Ava.UI.Renderer
|
2022-09-19 20:05:26 +02:00
|
|
|
{
|
2023-01-16 01:14:01 +01:00
|
|
|
public class EmbeddedWindowOpenGL : EmbeddedWindow
|
2022-09-19 20:05:26 +02:00
|
|
|
{
|
|
|
|
private SwappableNativeWindowBase _window;
|
2023-01-16 01:14:01 +01:00
|
|
|
|
2022-09-19 20:05:26 +02:00
|
|
|
public OpenGLContextBase Context { get; set; }
|
|
|
|
|
2023-01-16 01:14:01 +01:00
|
|
|
public EmbeddedWindowOpenGL() { }
|
2022-09-19 20:05:26 +02:00
|
|
|
|
|
|
|
protected override void OnWindowDestroying()
|
|
|
|
{
|
|
|
|
Context.Dispose();
|
2023-01-16 01:14:01 +01:00
|
|
|
|
2022-09-19 20:05:26 +02: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 15:08:27 +01:00
|
|
|
|
2022-09-19 20:05:26 +02:00
|
|
|
var flags = OpenGLContextFlags.Compat;
|
2023-01-16 01:14:01 +01:00
|
|
|
if (ConfigurationState.Instance.Logger.GraphicsDebugLevel != GraphicsDebugLevel.None)
|
2022-09-19 20:05:26 +02:00
|
|
|
{
|
|
|
|
flags |= OpenGLContextFlags.Debug;
|
|
|
|
}
|
|
|
|
|
2023-01-16 01:14:01 +01: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 20:05:26 +02:00
|
|
|
|
|
|
|
Context.Initialize(_window);
|
|
|
|
Context.MakeCurrent(_window);
|
|
|
|
|
2023-01-16 01:14:01 +01:00
|
|
|
GL.LoadBindings(new OpenTKBindingsContext(Context.GetProcAddress));
|
2022-09-19 20:05:26 +02:00
|
|
|
|
|
|
|
Context.MakeCurrent(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void MakeCurrent()
|
|
|
|
{
|
2022-11-24 15:08:27 +01:00
|
|
|
Context?.MakeCurrent(_window);
|
2022-09-19 20:05:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void MakeCurrent(NativeWindowBase window)
|
|
|
|
{
|
2022-11-24 15:08:27 +01:00
|
|
|
Context?.MakeCurrent(window);
|
2022-09-19 20:05:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SwapBuffers()
|
|
|
|
{
|
2023-01-16 01:14:01 +01:00
|
|
|
_window?.SwapBuffers();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void InitializeBackgroundContext(IRenderer renderer)
|
|
|
|
{
|
|
|
|
(renderer as OpenGLRenderer)?.InitializeBackgroundContext(SPBOpenGLContext.CreateBackgroundContext(Context));
|
|
|
|
|
|
|
|
MakeCurrent();
|
2022-09-19 20:05:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|