|
|
|
@ -1,6 +1,7 @@ |
|
|
|
using System; |
|
|
|
using System.Runtime.InteropServices; |
|
|
|
using Avalonia.OpenGL; |
|
|
|
using Avalonia.Threading; |
|
|
|
using Avalonia.Win32.Interop; |
|
|
|
using static Avalonia.Win32.Interop.UnmanagedMethods; |
|
|
|
using static Avalonia.Win32.OpenGl.WglConsts; |
|
|
|
@ -9,8 +10,6 @@ namespace Avalonia.Win32.OpenGl |
|
|
|
internal class WglDisplay |
|
|
|
{ |
|
|
|
private static bool? _initialized; |
|
|
|
private static ushort _windowClass; |
|
|
|
private static readonly WndProc _wndProcDelegate = WndProc; |
|
|
|
private static readonly DebugCallbackDelegate _debugCallback = DebugCallback; |
|
|
|
|
|
|
|
private static IntPtr _bootstrapContext; |
|
|
|
@ -44,17 +43,8 @@ namespace Avalonia.Win32.OpenGl |
|
|
|
} |
|
|
|
static bool InitializeCore() |
|
|
|
{ |
|
|
|
var wndClassEx = new WNDCLASSEX |
|
|
|
{ |
|
|
|
cbSize = Marshal.SizeOf<WNDCLASSEX>(), |
|
|
|
hInstance = GetModuleHandle(null), |
|
|
|
lpfnWndProc = _wndProcDelegate, |
|
|
|
lpszClassName = "AvaloniaGlWindow-" + Guid.NewGuid(), |
|
|
|
style = (int)ClassStyles.CS_OWNDC |
|
|
|
}; |
|
|
|
|
|
|
|
_windowClass = RegisterClassEx(ref wndClassEx); |
|
|
|
_bootstrapWindow = CreateOffscreenWindow(); |
|
|
|
Dispatcher.UIThread.VerifyAccess(); |
|
|
|
_bootstrapWindow = WglDCManager.CreateOffscreenWindow(); |
|
|
|
_bootstrapDc = WglDCManager.GetDC(_bootstrapWindow); |
|
|
|
_defaultPfd = new PixelFormatDescriptor |
|
|
|
{ |
|
|
|
@ -105,17 +95,11 @@ namespace Avalonia.Win32.OpenGl |
|
|
|
DescribePixelFormat(_bootstrapDc, formats[0], Marshal.SizeOf<PixelFormatDescriptor>(), ref _defaultPfd); |
|
|
|
_defaultPixelFormat = formats[0]; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wglMakeCurrent(IntPtr.Zero, IntPtr.Zero); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
static IntPtr WndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) |
|
|
|
{ |
|
|
|
return DefWindowProc(hWnd, msg, wParam, lParam); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static void DebugCallback(int source, int type, int id, int severity, int len, IntPtr message, IntPtr userparam) |
|
|
|
{ |
|
|
|
var err = Marshal.PtrToStringAnsi(message, len); |
|
|
|
@ -131,7 +115,7 @@ namespace Avalonia.Win32.OpenGl |
|
|
|
|
|
|
|
using (new WglRestoreContext(_bootstrapDc, _bootstrapContext, null)) |
|
|
|
{ |
|
|
|
var window = CreateOffscreenWindow(); |
|
|
|
var window = WglDCManager.CreateOffscreenWindow(); |
|
|
|
var dc = WglDCManager.GetDC(window); |
|
|
|
SetPixelFormat(dc, _defaultPixelFormat, ref _defaultPfd); |
|
|
|
foreach (var version in versions) |
|
|
|
@ -165,25 +149,12 @@ namespace Avalonia.Win32.OpenGl |
|
|
|
} |
|
|
|
|
|
|
|
WglDCManager.ReleaseDC(window, dc); |
|
|
|
DestroyWindow(window); |
|
|
|
WglDCManager.DestroyWindow(window); |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static IntPtr CreateOffscreenWindow() => |
|
|
|
CreateWindowEx( |
|
|
|
0, |
|
|
|
_windowClass, |
|
|
|
null, |
|
|
|
(int)WindowStyles.WS_OVERLAPPEDWINDOW, |
|
|
|
0, |
|
|
|
0, |
|
|
|
640, |
|
|
|
480, |
|
|
|
IntPtr.Zero, |
|
|
|
IntPtr.Zero, |
|
|
|
IntPtr.Zero, |
|
|
|
IntPtr.Zero); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|