aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Ava/Ui/Controls/OpenGLEmbeddedWindow.cs
diff options
context:
space:
mode:
authorEmmanuel Hansen <emmausssss@gmail.com>2022-09-19 18:05:26 +0000
committerGitHub <noreply@github.com>2022-09-19 15:05:26 -0300
commit6f0395538b8e8af3bba7536b44780d57e51e8697 (patch)
tree4d3f4f620dd287fc1ca38ea9ea722b6e022301dd /Ryujinx.Ava/Ui/Controls/OpenGLEmbeddedWindow.cs
parentb9f1ff3c7748c6a2665e76d17e86c3b7228f44fe (diff)
Avalonia - Use embedded window for avalonia (#3674)
* wip * use embedded window * fix race condition on opengl Windows * fix glx issues on prime nvidia * fix mouse support win32 * clean up * addressed review * addressed review * fix warnings * fix sotware keyboard dialog * Update Ryujinx.Ava/Ui/Applet/SwkbdAppletDialog.axaml.cs Co-authored-by: gdkchan <gab.dark.100@gmail.com> * remove double semi Co-authored-by: gdkchan <gab.dark.100@gmail.com>
Diffstat (limited to 'Ryujinx.Ava/Ui/Controls/OpenGLEmbeddedWindow.cs')
-rw-r--r--Ryujinx.Ava/Ui/Controls/OpenGLEmbeddedWindow.cs85
1 files changed, 85 insertions, 0 deletions
diff --git a/Ryujinx.Ava/Ui/Controls/OpenGLEmbeddedWindow.cs b/Ryujinx.Ava/Ui/Controls/OpenGLEmbeddedWindow.cs
new file mode 100644
index 00000000..ce579fdf
--- /dev/null
+++ b/Ryujinx.Ava/Ui/Controls/OpenGLEmbeddedWindow.cs
@@ -0,0 +1,85 @@
+using Avalonia;
+using Avalonia.OpenGL;
+using OpenTK.Graphics.OpenGL;
+using Ryujinx.Common.Configuration;
+using SPB.Graphics;
+using SPB.Graphics.OpenGL;
+using SPB.Platform;
+using SPB.Platform.GLX;
+using SPB.Platform.WGL;
+using SPB.Windowing;
+using System;
+
+namespace Ryujinx.Ava.Ui.Controls
+{
+ 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();
+ }
+
+ 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()
+ {
+ Context.MakeCurrent(_window);
+ }
+
+ public void MakeCurrent(NativeWindowBase window)
+ {
+ Context.MakeCurrent(window);
+ }
+
+ public void SwapBuffers()
+ {
+ _window.SwapBuffers();
+ }
+ }
+} \ No newline at end of file