diff options
Diffstat (limited to 'src/renderwindow.c')
-rw-r--r-- | src/renderwindow.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/renderwindow.c b/src/renderwindow.c index d3bea0c..e9b7a80 100644 --- a/src/renderwindow.c +++ b/src/renderwindow.c @@ -2,6 +2,11 @@ #include <dawn/webgpu.h> #include "renderwindow.h" +#if defined(SDL_PLATFORM_LINUX) +#include <X11/Xlib.h> +#include <wayland-client.h> +#endif + RenderWindow InitRenderWindow(int width, int height, const char* title) { RenderWindow renderWindow = {0}; SDL_Init(SDL_INIT_VIDEO); @@ -12,11 +17,58 @@ RenderWindow InitRenderWindow(int width, int height, const char* title) { .requiredFeatures = (WGPUInstanceFeatureName[]) { WGPUInstanceFeatureName_TimedWaitAny } }); + SDL_PropertiesID windowProperties = SDL_GetWindowProperties(renderWindow.window); +#if defined(SDL_PLATFORM_LINUX) + if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0) { + Display* xdisplay = + (Display *)SDL_GetPointerProperty(windowProperties, SDL_PROP_WINDOW_X11_DISPLAY_POINTER, NULL); + Window xwindow = + (Window)SDL_GetNumberProperty(windowProperties, SDL_PROP_WINDOW_X11_WINDOW_NUMBER, 0); + + if (xdisplay && xwindow) { + renderWindow.wgpuSurface = + wgpuInstanceCreateSurface(renderWindow.wgpuInstance, &(const WGPUSurfaceDescriptor){ + .nextInChain = (WGPUChainedStruct*)&(const WGPUSurfaceSourceXlibWindow) { + .chain = (WGPUChainedStruct) { + .next = NULL, + .sType = WGPUSType_SurfaceSourceXlibWindow + }, + + .display = xdisplay, + .window = xwindow + } + }); + } + } else if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0) { + struct wl_display* wl_display = + (struct wl_display*)SDL_GetPointerProperty(windowProperties, SDL_PROP_WINDOW_WAYLAND_DISPLAY_POINTER, NULL); + struct wl_surface* wl_surface = + (struct wl_surface*)SDL_GetPointerProperty(windowProperties, SDL_PROP_WINDOW_WAYLAND_SURFACE_POINTER, NULL); + + if (wl_display && wl_surface) { + renderWindow.wgpuSurface = + wgpuInstanceCreateSurface(renderWindow.wgpuInstance, &(const WGPUSurfaceDescriptor){ + .nextInChain = (WGPUChainedStruct*)&(const WGPUSurfaceSourceWaylandSurface) { + .chain = (WGPUChainedStruct) { + .next = NULL, + .sType = WGPUSType_SurfaceSourceWaylandSurface + }, + + .display = wl_display, + .surface = wl_surface + } + }); + } + } +#endif + return renderWindow; } void QuitRenderWindow(RenderWindow* renderWindow) { + wgpuSurfaceRelease(renderWindow->wgpuSurface); wgpuInstanceRelease(renderWindow->wgpuInstance); SDL_DestroyWindow(renderWindow->window); + SDL_memset(renderWindow, 0, sizeof(RenderWindow)); SDL_Quit(); } |