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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
// Handles windowing, input, and native surface creation.
// Consolidates platform-specific shims for WebGPU.
#pragma once
#include <cstdint>
#include <cstring>
// WebGPU specific headers and shims
#if defined(STRIP_EXTERNAL_LIBS)
#include "stub_types.h"
#else
#if defined(DEMO_CROSS_COMPILE_WIN32)
#include <webgpu/webgpu.h>
#include <webgpu/wgpu.h>
#else
#include <webgpu.h>
#include <wgpu.h>
#endif
static inline WGPUStringView str_view(const char* str) {
if (!str)
return {nullptr, 0};
return {str, strlen(str)};
}
static inline WGPUStringView label_view(const char* str) {
#if !defined(STRIP_ALL)
if (!str)
return {nullptr, 0};
return {str, strlen(str)};
#else
(void)str;
return {nullptr, 0};
#endif
}
static inline void platform_wgpu_wait_any(WGPUInstance instance) {
wgpuInstanceWaitAny(instance, 0, nullptr, 0);
}
#endif
// Forward declare GLFWwindow to avoid including the full header here.
struct GLFWwindow;
struct PlatformState {
GLFWwindow* window = nullptr;
int width = 1280;
int height = 720;
float aspect_ratio = 1.0f;
double time = 0.0;
bool is_fullscreen = false;
// Store windowed geometry for fullscreen toggle
int windowed_x = 0, windowed_y = 0, windowed_w = 0, windowed_h = 0;
};
PlatformState platform_init(bool fullscreen, int width, int height);
void platform_shutdown(PlatformState* state);
void platform_poll(PlatformState* state);
bool platform_should_close(PlatformState* state);
void platform_toggle_fullscreen(PlatformState* state);
// WebGPU specific surface creation
WGPUSurface platform_create_wgpu_surface(WGPUInstance instance,
PlatformState* state);
// Global time query (if needed without state)
double platform_get_time();
|