diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-07 09:20:19 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-07 09:20:19 +0100 |
| commit | 17b8ffac48643040cddfb0a51025bab62245326f (patch) | |
| tree | 6b3be53f32acd8ec28c057172f0cc91c1bd62838 /src/platform/platform.h | |
| parent | 5d19168436e64d1b33fecc48e1790f20847078f2 (diff) | |
refactor: Move platform files to src/platform/ subdirectory
Reorganized platform windowing code into dedicated subdirectory for
better organization and consistency with other subsystems (audio/, gpu/, 3d/).
Changes:
- Created src/platform/ directory
- Moved src/platform.{h,cc} → src/platform/platform.{h,cc}
- Updated 11 include paths: "platform.h" → "platform/platform.h"
- src/main.cc, src/test_demo.cc
- src/gpu/gpu.{h,cc}
- src/platform/platform.cc (self-include)
- 6 test files
- Updated CMakeLists.txt PLATFORM_SOURCES variable
Verification:
✓ All targets build successfully (demo64k, test_demo, test_platform)
✓ test_platform passes (70% coverage maintained)
✓ demo64k smoke test passed
This completes the platform code reorganization side quest.
No functional changes, purely organizational.
Diffstat (limited to 'src/platform/platform.h')
| -rw-r--r-- | src/platform/platform.h | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/src/platform/platform.h b/src/platform/platform.h new file mode 100644 index 0000000..0a98850 --- /dev/null +++ b/src/platform/platform.h @@ -0,0 +1,100 @@ +// 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(DEMO_CROSS_COMPILE_WIN32) +#include <webgpu/webgpu.h> +#include <webgpu/wgpu.h> + +#define WGPUOptionalBool_True true +#define WGPUOptionalBool_False false +#define WGPUSType_ShaderSourceWGSL WGPUSType_ShaderModuleWGSLDescriptor +#define WGPU_DEPTH_SLICE_UNDEFINED 0xffffffff +#define WGPUSurfaceGetCurrentTextureStatus_SuccessOptimal \ + WGPUSurfaceGetCurrentTextureStatus_Success +#define WGPUSurfaceGetCurrentTextureStatus_SuccessSuboptimal \ + WGPUSurfaceGetCurrentTextureStatus_Success +#define WGPUCallbackMode_WaitAnyOnly 0 + +typedef WGPUShaderModuleWGSLDescriptor WGPUShaderSourceWGSL; + +static inline const char* str_view(const char* str) { + return str; +} +static inline const char* label_view(const char* str) { + return str; +} + +static inline void platform_wgpu_wait_any(WGPUInstance instance) { + wgpuInstanceProcessEvents(instance); +} +static inline void +platform_wgpu_set_error_callback(WGPUDevice device, + WGPUErrorCallback callback) { + wgpuDeviceSetUncapturedErrorCallback(device, callback, nullptr); +} + +#else +#include <webgpu.h> +#include <wgpu.h> + +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); +} +static inline void +platform_wgpu_set_error_callback(WGPUDevice device, + WGPUUncapturedErrorCallback callback) { + // Handled in descriptor for new API, but provided for compatibility if needed + // elsewhere +} +#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; +}; + +// Refactored platform API +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();
\ No newline at end of file |
