Skip to content

Commit 88a7510

Browse files
committed
Add support for emscripten
1 parent d56d9a7 commit 88a7510

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

glfw3webgpu.c

+27-1
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,16 @@
3838
#define WGPU_TARGET_LINUX_X11 2
3939
#define WGPU_TARGET_WINDOWS 3
4040
#define WGPU_TARGET_LINUX_WAYLAND 4
41+
#define WGPU_TARGET_EMSCRIPTEN 5
4142

42-
#if defined(_WIN32)
43+
#if defined(__EMSCRIPTEN__)
44+
#define WGPU_TARGET WGPU_TARGET_EMSCRIPTEN
45+
#elif defined(_WIN32)
4346
#define WGPU_TARGET WGPU_TARGET_WINDOWS
4447
#elif defined(__APPLE__)
4548
#define WGPU_TARGET WGPU_TARGET_MACOS
49+
#elif defined(_GLFW_WAYLAND)
50+
#define WGPU_TARGET WGPU_TARGET_LINUX_WAYLAND
4651
#else
4752
#define WGPU_TARGET WGPU_TARGET_LINUX_X11
4853
#endif
@@ -62,7 +67,10 @@
6267
#elif WGPU_TARGET == WGPU_TARGET_WINDOWS
6368
#define GLFW_EXPOSE_NATIVE_WIN32
6469
#endif
70+
71+
#if !defined(__EMSCRIPTEN__)
6572
#include <GLFW/glfw3native.h>
73+
#endif
6674

6775
WGPUSurface glfwGetWGPUSurface(WGPUInstance instance, GLFWwindow* window) {
6876
#if WGPU_TARGET == WGPU_TARGET_MACOS
@@ -152,6 +160,24 @@ WGPUSurface glfwGetWGPUSurface(WGPUInstance instance, GLFWwindow* window) {
152160
},
153161
});
154162
}
163+
#elif WGPU_TARGET == WGPU_TARGET_EMSCRIPTEN
164+
{
165+
return wgpuInstanceCreateSurface(
166+
instance,
167+
&(WGPUSurfaceDescriptor){
168+
.label = NULL,
169+
.nextInChain =
170+
(const WGPUChainedStruct*)&(
171+
WGPUSurfaceDescriptorFromCanvasHTMLSelector) {
172+
.chain = (WGPUChainedStruct){
173+
.next = NULL,
174+
.sType = WGPUSType_SurfaceDescriptorFromCanvasHTMLSelector,
175+
},
176+
.selector = "canvas",
177+
},
178+
}
179+
);
180+
}
155181
#else
156182
#error "Unsupported WGPU_TARGET"
157183
#endif

0 commit comments

Comments
 (0)