From 960be3f2aa0c7722105b30d7a74199b840d3886e Mon Sep 17 00:00:00 2001 From: Beyley Thomas Date: Wed, 2 Nov 2022 23:02:28 -0700 Subject: [PATCH] Make WebGPU surface creation an extension method on IView --- src/Lab/Experiments/WebGPUTriangle/Program.cs | 4 +-- .../PublicAPI/net5.0/PublicAPI.Unshipped.txt | 2 +- .../netcoreapp3.1/PublicAPI.Unshipped.txt | 2 +- .../netstandard2.0/PublicAPI.Unshipped.txt | 2 +- .../netstandard2.1/PublicAPI.Unshipped.txt | 2 +- .../WebGPUWindow.cs | 32 +++++++++---------- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Lab/Experiments/WebGPUTriangle/Program.cs b/src/Lab/Experiments/WebGPUTriangle/Program.cs index fcb0617f1d..2a8c44900c 100644 --- a/src/Lab/Experiments/WebGPUTriangle/Program.cs +++ b/src/Lab/Experiments/WebGPUTriangle/Program.cs @@ -16,7 +16,7 @@ public static unsafe class Program { // ReSharper disable once InconsistentNaming private static WebGPU wgpu = null!; - private static WebGPUDisposal? webGpuDisposal; + private static WebGPUDisposal? webGpuDisposal = null!; private static IWindow? _Window; private static Surface* _Surface; @@ -73,7 +73,7 @@ private static void WindowOnLoad() webGpuDisposal = new WebGPUDisposal(wgpu); - _Surface = WebGPUWindow.CreateSurface(wgpu, _Window); + _Surface = _Window.CreateWebGPUSurface(wgpu); { //Get adapter var requestAdapterOptions = new RequestAdapterOptions diff --git a/src/Windowing/Extensions/Silk.NET.Windowing.Extensions.WebGPU/PublicAPI/net5.0/PublicAPI.Unshipped.txt b/src/Windowing/Extensions/Silk.NET.Windowing.Extensions.WebGPU/PublicAPI/net5.0/PublicAPI.Unshipped.txt index d52de80c6c..f88098635c 100644 --- a/src/Windowing/Extensions/Silk.NET.Windowing.Extensions.WebGPU/PublicAPI/net5.0/PublicAPI.Unshipped.txt +++ b/src/Windowing/Extensions/Silk.NET.Windowing.Extensions.WebGPU/PublicAPI/net5.0/PublicAPI.Unshipped.txt @@ -1,3 +1,3 @@ #nullable enable Silk.NET.Windowing.Extensions.WebGPU.WebGPUWindow -~static Silk.NET.Windowing.Extensions.WebGPU.WebGPUWindow.CreateSurface(Silk.NET.WebGPU.WebGPU wgpu, Silk.NET.Windowing.IView window, Silk.NET.WebGPU.Instance* instance = null) -> Silk.NET.WebGPU.Surface* +~static Silk.NET.Windowing.Extensions.WebGPU.WebGPUWindow.CreateWebGPUSurface(this Silk.NET.Windowing.IView view, Silk.NET.WebGPU.WebGPU wgpu, Silk.NET.WebGPU.Instance* instance = null) -> Silk.NET.WebGPU.Surface* diff --git a/src/Windowing/Extensions/Silk.NET.Windowing.Extensions.WebGPU/PublicAPI/netcoreapp3.1/PublicAPI.Unshipped.txt b/src/Windowing/Extensions/Silk.NET.Windowing.Extensions.WebGPU/PublicAPI/netcoreapp3.1/PublicAPI.Unshipped.txt index d52de80c6c..f88098635c 100644 --- a/src/Windowing/Extensions/Silk.NET.Windowing.Extensions.WebGPU/PublicAPI/netcoreapp3.1/PublicAPI.Unshipped.txt +++ b/src/Windowing/Extensions/Silk.NET.Windowing.Extensions.WebGPU/PublicAPI/netcoreapp3.1/PublicAPI.Unshipped.txt @@ -1,3 +1,3 @@ #nullable enable Silk.NET.Windowing.Extensions.WebGPU.WebGPUWindow -~static Silk.NET.Windowing.Extensions.WebGPU.WebGPUWindow.CreateSurface(Silk.NET.WebGPU.WebGPU wgpu, Silk.NET.Windowing.IView window, Silk.NET.WebGPU.Instance* instance = null) -> Silk.NET.WebGPU.Surface* +~static Silk.NET.Windowing.Extensions.WebGPU.WebGPUWindow.CreateWebGPUSurface(this Silk.NET.Windowing.IView view, Silk.NET.WebGPU.WebGPU wgpu, Silk.NET.WebGPU.Instance* instance = null) -> Silk.NET.WebGPU.Surface* diff --git a/src/Windowing/Extensions/Silk.NET.Windowing.Extensions.WebGPU/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt b/src/Windowing/Extensions/Silk.NET.Windowing.Extensions.WebGPU/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt index 9cfd335702..4d0b9d1e9f 100644 --- a/src/Windowing/Extensions/Silk.NET.Windowing.Extensions.WebGPU/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/Windowing/Extensions/Silk.NET.Windowing.Extensions.WebGPU/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt @@ -1,4 +1,4 @@ #nullable enable Silk.NET.WIndowing.Extensions.WebGPU.WebGPUWindow Silk.NET.Windowing.Extensions.WebGPU.WebGPUWindow -~static Silk.NET.Windowing.Extensions.WebGPU.WebGPUWindow.CreateSurface(Silk.NET.WebGPU.WebGPU wgpu, Silk.NET.Windowing.IView window, Silk.NET.WebGPU.Instance* instance = null) -> Silk.NET.WebGPU.Surface* +~static Silk.NET.Windowing.Extensions.WebGPU.WebGPUWindow.CreateWebGPUSurface(this Silk.NET.Windowing.IView view, Silk.NET.WebGPU.WebGPU wgpu, Silk.NET.WebGPU.Instance* instance = null) -> Silk.NET.WebGPU.Surface* diff --git a/src/Windowing/Extensions/Silk.NET.Windowing.Extensions.WebGPU/PublicAPI/netstandard2.1/PublicAPI.Unshipped.txt b/src/Windowing/Extensions/Silk.NET.Windowing.Extensions.WebGPU/PublicAPI/netstandard2.1/PublicAPI.Unshipped.txt index d52de80c6c..f88098635c 100644 --- a/src/Windowing/Extensions/Silk.NET.Windowing.Extensions.WebGPU/PublicAPI/netstandard2.1/PublicAPI.Unshipped.txt +++ b/src/Windowing/Extensions/Silk.NET.Windowing.Extensions.WebGPU/PublicAPI/netstandard2.1/PublicAPI.Unshipped.txt @@ -1,3 +1,3 @@ #nullable enable Silk.NET.Windowing.Extensions.WebGPU.WebGPUWindow -~static Silk.NET.Windowing.Extensions.WebGPU.WebGPUWindow.CreateSurface(Silk.NET.WebGPU.WebGPU wgpu, Silk.NET.Windowing.IView window, Silk.NET.WebGPU.Instance* instance = null) -> Silk.NET.WebGPU.Surface* +~static Silk.NET.Windowing.Extensions.WebGPU.WebGPUWindow.CreateWebGPUSurface(this Silk.NET.Windowing.IView view, Silk.NET.WebGPU.WebGPU wgpu, Silk.NET.WebGPU.Instance* instance = null) -> Silk.NET.WebGPU.Surface* diff --git a/src/Windowing/Extensions/Silk.NET.Windowing.Extensions.WebGPU/WebGPUWindow.cs b/src/Windowing/Extensions/Silk.NET.Windowing.Extensions.WebGPU/WebGPUWindow.cs index 6bd9c0d7e1..6c90d84fc6 100644 --- a/src/Windowing/Extensions/Silk.NET.Windowing.Extensions.WebGPU/WebGPUWindow.cs +++ b/src/Windowing/Extensions/Silk.NET.Windowing.Extensions.WebGPU/WebGPUWindow.cs @@ -15,14 +15,14 @@ public static class WebGPUWindow /// Creates a WebGPU surface from a window. /// /// A WebGPU instance - /// The window to get the surface from + /// The window to get the surface from /// A newly created Surface*/ /// Throws when an unsupported platform is detected. - public static unsafe Surface* CreateSurface(NET.WebGPU.WebGPU wgpu, IView window, Instance* instance = null) + public static unsafe Surface* CreateWebGPUSurface(this IView view, NET.WebGPU.WebGPU wgpu, Instance* instance = null) { var descriptor = new SurfaceDescriptor(); - if (window.Native.X11 != null) + if (view.Native.X11 != null) { var xlibDescriptor = new SurfaceDescriptorFromXlibWindow { @@ -31,17 +31,17 @@ public static class WebGPUWindow Next = null, SType = SType.SurfaceDescriptorFromXlibWindow }, - Display = (void*) window.Native.X11.Value.Display, - Window = (uint) window.Native.X11.Value.Window + Display = (void*) view.Native.X11.Value.Display, + Window = (uint) view.Native.X11.Value.Window }; descriptor.NextInChain = (ChainedStruct*) (&xlibDescriptor); } - else if (window.Native.Cocoa != null) + else if (view.Native.Cocoa != null) { throw new NotSupportedException("WebGPU on MacOS is not supported at this time!)"); - var cocoa = window.Native.Cocoa.Value; + var cocoa = view.Native.Cocoa.Value; var cocoaDescriptor = new SurfaceDescriptorFromMetalLayer { @@ -53,7 +53,7 @@ public static class WebGPUWindow Layer = null //TODO: Get the layer from the window }; } - else if (window.Native.Wayland != null) + else if (view.Native.Wayland != null) { var waylandDescriptor = new SurfaceDescriptorFromWaylandSurface { @@ -62,13 +62,13 @@ public static class WebGPUWindow Next = null, SType = SType.SurfaceDescriptorFromWaylandSurface }, - Display = (void*) window.Native.Wayland.Value.Display, - Surface = (void*) window.Native.Wayland.Value.Surface + Display = (void*) view.Native.Wayland.Value.Display, + Surface = (void*) view.Native.Wayland.Value.Surface }; descriptor.NextInChain = (ChainedStruct*) (&waylandDescriptor); } - else if (window.Native.Win32 != null) + else if (view.Native.Win32 != null) { var win32Descriptor = new SurfaceDescriptorFromWindowsHWND { @@ -77,13 +77,13 @@ public static class WebGPUWindow Next = null, SType = SType.SurfaceDescriptorFromWindowsHwnd }, - Hwnd = (void*) window.Native.Win32.Value.Hwnd, - Hinstance = (void*) window.Native.Win32.Value.HInstance + Hwnd = (void*) view.Native.Win32.Value.Hwnd, + Hinstance = (void*) view.Native.Win32.Value.HInstance }; descriptor.NextInChain = (ChainedStruct*) (&win32Descriptor); } - else if (window.Native.Android != null) + else if (view.Native.Android != null) { var androidDescriptor = new SurfaceDescriptorFromAndroidNativeWindow { @@ -92,14 +92,14 @@ public static class WebGPUWindow Next = null, SType = SType.SurfaceDescriptorFromAndroidNativeWindow }, - Window = (void*) window.Native.Android.Value.Window + Window = (void*) view.Native.Android.Value.Window }; descriptor.NextInChain = (ChainedStruct*) (&androidDescriptor); } else { - throw new NotSupportedException($"Your platform is not supported! {window.Native.Kind}"); + throw new NotSupportedException($"Your platform is not supported! {view.Native.Kind}"); } return wgpu.InstanceCreateSurface(instance, ref descriptor);