Skip to content

Commit 39a8020

Browse files
authored
Merge pull request #6 from garettbass/garettbass/cpp-support
Support compilation as C or C++ to enable including implementation in C or C++ source
2 parents 45d15f9 + cdcd1a8 commit 39a8020

File tree

1 file changed

+59
-82
lines changed

1 file changed

+59
-82
lines changed

glfw3webgpu.c

+59-82
Original file line numberDiff line numberDiff line change
@@ -75,108 +75,85 @@
7575
WGPUSurface glfwGetWGPUSurface(WGPUInstance instance, GLFWwindow* window) {
7676
#if WGPU_TARGET == WGPU_TARGET_MACOS
7777
{
78-
id metal_layer = NULL;
78+
id metal_layer = [CAMetalLayer layer];
7979
NSWindow* ns_window = glfwGetCocoaWindow(window);
8080
[ns_window.contentView setWantsLayer : YES] ;
81-
metal_layer = [CAMetalLayer layer];
8281
[ns_window.contentView setLayer : metal_layer] ;
83-
return wgpuInstanceCreateSurface(
84-
instance,
85-
&(WGPUSurfaceDescriptor){
86-
.label = NULL,
87-
.nextInChain =
88-
(const WGPUChainedStruct*)&(
89-
WGPUSurfaceDescriptorFromMetalLayer) {
90-
.chain =
91-
(WGPUChainedStruct){
92-
.next = NULL,
93-
.sType = WGPUSType_SurfaceDescriptorFromMetalLayer,
94-
},
95-
.layer = metal_layer,
96-
},
97-
});
82+
83+
WGPUSurfaceDescriptorFromMetalLayer fromMetalLayer;
84+
fromMetalLayer.chain.next = NULL;
85+
fromMetalLayer.chain.sType = WGPUSType_SurfaceDescriptorFromMetalLayer;
86+
fromMetalLayer.layer = metal_layer;
87+
88+
WGPUSurfaceDescriptor surfaceDescriptor;
89+
surfaceDescriptor.nextInChain = &fromMetalLayer.chain;
90+
surfaceDescriptor.label = NULL;
91+
92+
return wgpuInstanceCreateSurface(instance, &surfaceDescriptor);
9893
}
9994
#elif WGPU_TARGET == WGPU_TARGET_LINUX_X11
10095
{
10196
Display* x11_display = glfwGetX11Display();
10297
Window x11_window = glfwGetX11Window(window);
103-
return wgpuInstanceCreateSurface(
104-
instance,
105-
&(WGPUSurfaceDescriptor){
106-
.label = NULL,
107-
.nextInChain =
108-
(const WGPUChainedStruct*)&(
109-
WGPUSurfaceDescriptorFromXlibWindow) {
110-
.chain =
111-
(WGPUChainedStruct){
112-
.next = NULL,
113-
.sType = WGPUSType_SurfaceDescriptorFromXlibWindow,
114-
},
115-
.display = x11_display,
116-
.window = x11_window,
117-
},
118-
});
98+
99+
WGPUSurfaceDescriptorFromXlibWindow fromXlibWindow;
100+
fromXlibWindow.chain.next = NULL;
101+
fromXlibWindow.chain.sType = WGPUSType_SurfaceDescriptorFromXlibWindow;
102+
fromXlibWindow.display = x11_display;
103+
fromXlibWindow.window = x11_window;
104+
105+
WGPUSurfaceDescriptor surfaceDescriptor;
106+
surfaceDescriptor.nextInChain = &fromXlibWindow.chain;
107+
surfaceDescriptor.label = NULL;
108+
109+
return wgpuInstanceCreateSurface(instance, &surfaceDescriptor);
119110
}
120111
#elif WGPU_TARGET == WGPU_TARGET_LINUX_WAYLAND
121112
{
122113
struct wl_display* wayland_display = glfwGetWaylandDisplay();
123114
struct wl_surface* wayland_surface = glfwGetWaylandWindow(window);
124-
return wgpuInstanceCreateSurface(
125-
instance,
126-
&(WGPUSurfaceDescriptor){
127-
.label = NULL,
128-
.nextInChain =
129-
(const WGPUChainedStruct*)&(
130-
WGPUSurfaceDescriptorFromWaylandSurface) {
131-
.chain =
132-
(WGPUChainedStruct){
133-
.next = NULL,
134-
.sType =
135-
WGPUSType_SurfaceDescriptorFromWaylandSurface,
136-
},
137-
.display = wayland_display,
138-
.surface = wayland_surface,
139-
},
140-
});
115+
116+
WGPUSurfaceDescriptorFromWaylandSurface fromWaylandSurface;
117+
fromWaylandSurface.chain.next = NULL;
118+
fromWaylandSurface.chain.sType = WGPUSType_SurfaceDescriptorFromWaylandSurface;
119+
fromWaylandSurface.display = wayland_display;
120+
fromWaylandSurface.surface = wayland_surface;
121+
122+
WGPUSurfaceDescriptor surfaceDescriptor;
123+
surfaceDescriptor.nextInChain = &fromWaylandSurface.chain;
124+
surfaceDescriptor.label = NULL;
125+
126+
return wgpuInstanceCreateSurface(instance, &surfaceDescriptor);
141127
}
142128
#elif WGPU_TARGET == WGPU_TARGET_WINDOWS
143129
{
144130
HWND hwnd = glfwGetWin32Window(window);
145131
HINSTANCE hinstance = GetModuleHandle(NULL);
146-
return wgpuInstanceCreateSurface(
147-
instance,
148-
&(WGPUSurfaceDescriptor){
149-
.label = NULL,
150-
.nextInChain =
151-
(const WGPUChainedStruct*)&(
152-
WGPUSurfaceDescriptorFromWindowsHWND) {
153-
.chain =
154-
(WGPUChainedStruct){
155-
.next = NULL,
156-
.sType = WGPUSType_SurfaceDescriptorFromWindowsHWND,
157-
},
158-
.hinstance = hinstance,
159-
.hwnd = hwnd,
160-
},
161-
});
162-
}
132+
133+
WGPUSurfaceDescriptorFromWindowsHWND fromWindowsHWND;
134+
fromWindowsHWND.chain.next = NULL;
135+
fromWindowsHWND.chain.sType = WGPUSType_SurfaceDescriptorFromWindowsHWND;
136+
fromWindowsHWND.hinstance = hinstance;
137+
fromWindowsHWND.hwnd = hwnd;
138+
139+
WGPUSurfaceDescriptor surfaceDescriptor;
140+
surfaceDescriptor.nextInChain = &fromWindowsHWND.chain;
141+
surfaceDescriptor.label = NULL;
142+
143+
return wgpuInstanceCreateSurface(instance, &surfaceDescriptor);
144+
}
163145
#elif WGPU_TARGET == WGPU_TARGET_EMSCRIPTEN
164146
{
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-
);
147+
WGPUSurfaceDescriptorFromCanvasHTMLSelector fromCanvasHTMLSelector;
148+
fromCanvasHTMLSelector.chain.next = NULL;
149+
fromCanvasHTMLSelector.chain.sType = WGPUSType_SurfaceDescriptorFromCanvasHTMLSelector;
150+
fromCanvasHTMLSelector.selector = "canvas";
151+
152+
WGPUSurfaceDescriptor surfaceDescriptor;
153+
surfaceDescriptor.nextInChain = &fromCanvasHTMLSelector.chain;
154+
surfaceDescriptor.label = NULL;
155+
156+
return wgpuInstanceCreateSurface(instance, &surfaceDescriptor);
180157
}
181158
#else
182159
#error "Unsupported WGPU_TARGET"

0 commit comments

Comments
 (0)