diff options
Diffstat (limited to 'src/platform.cc')
| -rw-r--r-- | src/platform.cc | 78 |
1 files changed, 2 insertions, 76 deletions
diff --git a/src/platform.cc b/src/platform.cc index 09cc7ac..fa49b53 100644 --- a/src/platform.cc +++ b/src/platform.cc @@ -1,22 +1,7 @@ #include "platform.h" - -#ifdef _WIN32 -#define GLFW_EXPOSE_NATIVE_WIN32 -#elif defined(__APPLE__) -#define GLFW_EXPOSE_NATIVE_COCOA -#else -#define GLFW_EXPOSE_NATIVE_X11 -#define GLFW_EXPOSE_NATIVE_WAYLAND -#endif +#include "glfw3webgpu.h" #include <GLFW/glfw3.h> -#include <GLFW/glfw3native.h> - -#ifdef __APPLE__ -#import <QuartzCore/CAMetalLayer.h> -#import <AppKit/NSWindow.h> -#import <AppKit/NSView.h> -#endif static GLFWwindow *window = nullptr; static int windowed_x, windowed_y, windowed_w, windowed_h; @@ -82,64 +67,5 @@ GLFWwindow *platform_get_window() { return window; } double platform_get_time() { return glfwGetTime(); } WGPUSurface platform_create_wgpu_surface(WGPUInstance instance) { -#if defined(GLFW_EXPOSE_NATIVE_COCOA) - id metal_layer = NULL; - NSWindow *ns_window = glfwGetCocoaWindow(window); - [ns_window.contentView setWantsLayer:YES]; - metal_layer = [CAMetalLayer layer]; - [ns_window.contentView setLayer:metal_layer]; - - WGPUSurfaceSourceMetalLayer metal_src = {}; - metal_src.chain.sType = WGPUSType_SurfaceSourceMetalLayer; - metal_src.layer = metal_layer; - - WGPUSurfaceDescriptor surface_desc = {}; - surface_desc.nextInChain = (const WGPUChainedStruct *)&metal_src; - - return wgpuInstanceCreateSurface(instance, &surface_desc); - -#elif defined(GLFW_EXPOSE_NATIVE_WIN32) - HWND hwnd = glfwGetWin32Window(window); - HINSTANCE hinstance = GetModuleHandle(NULL); - - WGPUSurfaceSourceWindowsHWND win_src = {}; - win_src.chain.sType = WGPUSType_SurfaceSourceWindowsHWND; - win_src.hinstance = hinstance; - win_src.hwnd = hwnd; - - WGPUSurfaceDescriptor surface_desc = {}; - surface_desc.nextInChain = (const WGPUChainedStruct *)&win_src; - - return wgpuInstanceCreateSurface(instance, &surface_desc); - -#elif defined(GLFW_EXPOSE_NATIVE_X11) || defined(GLFW_EXPOSE_NATIVE_WAYLAND) - if (glfwGetPlatform() == GLFW_PLATFORM_X11) { - Display *x11_display = glfwGetX11Display(); - Window x11_window = glfwGetX11Window(window); - - WGPUSurfaceSourceXlibWindow x11_src = {}; - x11_src.chain.sType = WGPUSType_SurfaceSourceXlibWindow; - x11_src.display = x11_display; - x11_src.window = x11_window; - - WGPUSurfaceDescriptor surface_desc = {}; - surface_desc.nextInChain = (const WGPUChainedStruct *)&x11_src; - - return wgpuInstanceCreateSurface(instance, &surface_desc); - } else if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND) { - struct wl_display *wayland_display = glfwGetWaylandDisplay(); - struct wl_surface *wayland_surface = glfwGetWaylandWindow(window); - - WGPUSurfaceSourceWaylandSurface wl_src = {}; - wl_src.chain.sType = WGPUSType_SurfaceSourceWaylandSurface; - wl_src.display = wayland_display; - wl_src.surface = wayland_surface; - - WGPUSurfaceDescriptor surface_desc = {}; - surface_desc.nextInChain = (const WGPUChainedStruct *)&wl_src; - - return wgpuInstanceCreateSurface(instance, &surface_desc); - } -#endif - return nullptr; + return glfwCreateWindowWGPUSurface(instance, window); } |
