This repository has been archived by the owner on Apr 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
SDLWebGPU.cpp
46 lines (38 loc) · 1.3 KB
/
SDLWebGPU.cpp
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
#include "util/SDLWebGPU.h"
#include <webgpu/webgpu_cpp.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_syswm.h>
namespace util
{
wgpu::Surface CreateSurfaceForSDLWindow(const wgpu::Instance& instance, SDL_Window* window)
{
SDL_SysWMinfo windowWMInfo;
SDL_VERSION(&windowWMInfo.version);
SDL_GetWindowWMInfo(window, &windowWMInfo);
#if defined(SDL_VIDEO_DRIVER_X11)
{
Display* x11_display = windowWMInfo.info.x11.display;
Window x11_window = windowWMInfo.info.x11.window;
wgpu::SurfaceDescriptorFromXlibWindow x11SurfDesc;
x11SurfDesc.display = x11_display;
x11SurfDesc.window = x11_window;
wgpu::SurfaceDescriptor surfaceDesc;
surfaceDesc.nextInChain = &x11SurfDesc;
return instance.CreateSurface(&surfaceDesc);
}
#elif defined(SDL_VIDEO_DRIVER_WINDOWS)
{
HWND hwnd = windowWMInfo.info.win.window;
HINSTANCE hinstance = GetModuleHandle(NULL);
wgpu::SurfaceDescriptorFromWindowsHWND windowsSurfDesc;
windowsSurfDesc.hwnd = hwnd;
windowsSurfDesc.hinstance = hinstance;
wgpu::SurfaceDescriptor surfaceDesc;
surfaceDesc.nextInChain = &windowsSurfDesc;
return instance.CreateSurface(&surfaceDesc);
}
#else
#error "Unsupported WGPU_TARGET"
#endif
}
} // end of namespace util