2022-09-19 11:05:26 -07:00
|
|
|
using OpenTK.Graphics.OpenGL;
|
|
|
|
using Ryujinx.Common.Configuration;
|
|
|
|
using SPB.Graphics;
|
|
|
|
using SPB.Graphics.OpenGL;
|
|
|
|
using SPB.Platform;
|
|
|
|
using SPB.Platform.WGL;
|
|
|
|
using SPB.Windowing;
|
|
|
|
using System;
|
|
|
|
|
2022-12-29 06:24:05 -08:00
|
|
|
namespace Ryujinx.Ava.UI.Helpers
|
2022-09-19 11:05:26 -07:00
|
|
|
{
|
|
|
|
public class OpenGLEmbeddedWindow : EmbeddedWindow
|
|
|
|
{
|
|
|
|
private readonly int _major;
|
|
|
|
private readonly int _minor;
|
|
|
|
private readonly GraphicsDebugLevel _graphicsDebugLevel;
|
|
|
|
private SwappableNativeWindowBase _window;
|
|
|
|
public OpenGLContextBase Context { get; set; }
|
|
|
|
|
|
|
|
public OpenGLEmbeddedWindow(int major, int minor, GraphicsDebugLevel graphicsDebugLevel)
|
|
|
|
{
|
|
|
|
_major = major;
|
|
|
|
_minor = minor;
|
|
|
|
_graphicsDebugLevel = graphicsDebugLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnWindowDestroying()
|
|
|
|
{
|
|
|
|
Context.Dispose();
|
|
|
|
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;
|
|
|
|
if (_graphicsDebugLevel != GraphicsDebugLevel.None)
|
|
|
|
{
|
|
|
|
flags |= OpenGLContextFlags.Debug;
|
|
|
|
}
|
|
|
|
|
|
|
|
Context = PlatformHelper.CreateOpenGLContext(FramebufferFormat.Default, _major, _minor, flags);
|
|
|
|
|
|
|
|
Context.Initialize(_window);
|
|
|
|
Context.MakeCurrent(_window);
|
|
|
|
|
|
|
|
var bindingsContext = new OpenToolkitBindingsContext(Context.GetProcAddress);
|
|
|
|
|
|
|
|
GL.LoadBindings(bindingsContext);
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
_window.SwapBuffers();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|