blob: db77f66bf01aa7f6f4308aa6b1cc07079f982793 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
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;
namespace Ryujinx.Ava.UI.Helpers
{
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();
}
}
}
|