-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVulkanSurface.cs
100 lines (82 loc) · 2.82 KB
/
VulkanSurface.cs
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using Avalonia.Controls;
using Avalonia.Controls.Platform;
using Avalonia.Platform;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Silk.NET.Vulkan;
using Silk.NET.Vulkan.Extensions.KHR;
using PInvoke;
namespace AvaVulkan
{
public class VulkanSurface : NativeControlHost
{
public event EventHandler<IntPtr> WindowCreated;
public bool IsSecond { get; set; }
private IntPtr win32Window;
public VulkanSurface()
{
}
IPlatformHandle CreateLinux(IPlatformHandle parent)
{
return null;
}
void DestroyLinux(IPlatformHandle handle)
{
base.DestroyNativeControlCore(handle);
}
IPlatformHandle CreateWin32(IPlatformHandle parent)
{
win32Window = parent.Handle;
WindowCreated?.Invoke(this, win32Window);
return new PlatformHandle(win32Window, "HWND");
}
public unsafe SurfaceKHR CreateWin32Surface(Device device, Instance instance, Vk vk)
{
vk.TryGetInstanceExtension(instance, out KhrWin32Surface khrSurface);
var createInfo = new Win32SurfaceCreateInfoKHR()
{
SType = StructureType.Win32SurfaceCreateInfoKhr,
Hinstance = 0,
Hwnd = win32Window
};
khrSurface.CreateWin32Surface(instance, createInfo, null, out var surface);
return surface;
}
void DestroyWin32(IPlatformHandle handle)
{
WinApi.DestroyWindow(handle.Handle);
}
IPlatformHandle CreateOSX(IPlatformHandle parent)
{
return null;
}
void DestroyOSX(IPlatformHandle handle)
{
}
protected override IPlatformHandle CreateNativeControlCore(IPlatformHandle parent)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
return CreateLinux(parent);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return CreateWin32(parent);
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
return CreateOSX(parent);
return base.CreateNativeControlCore(parent);
}
protected override void DestroyNativeControlCore(IPlatformHandle control)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
DestroyLinux(control);
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
DestroyWin32(control);
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
DestroyOSX(control);
else
base.DestroyNativeControlCore(control);
}
}
}