diff options
Diffstat (limited to 'src/platform.h')
| -rw-r--r-- | src/platform.h | 53 |
1 files changed, 37 insertions, 16 deletions
diff --git a/src/platform.h b/src/platform.h index 38a0568..2d2fc9e 100644 --- a/src/platform.h +++ b/src/platform.h @@ -1,25 +1,46 @@ -// This file is part of the 64k demo project. -// It defines the platform abstraction layer for windowing and input. -// Provides a consistent interface for GLFW-based operations. +// Handles windowing, input, and native surface creation. #pragma once -#include <webgpu.h> - // Forward declare GLFWwindow to avoid including the full header here. struct GLFWwindow; -void platform_init_window(bool fullscreen, int* width_ptr, int* height_ptr); -void platform_shutdown(); -void platform_poll(); -bool platform_should_close(); +struct PlatformState { + GLFWwindow* window = nullptr; + int width = 1280; + int height = 720; + bool is_fullscreen = false; + // Store windowed geometry for fullscreen toggle + int windowed_x = 0, windowed_y = 0, windowed_w = 0, windowed_h = 0; +}; + +void platform_init(PlatformState* state, bool fullscreen, int* width_ptr, int* height_ptr); +void platform_shutdown(PlatformState* state); +void platform_poll(PlatformState* state); +bool platform_should_close(PlatformState* state); +void platform_toggle_fullscreen(PlatformState* state); + +// Inline getters for direct access +inline GLFWwindow* platform_get_window(PlatformState* state) { return state->window; } +inline int platform_get_width(PlatformState* state) { return state->width; } +inline int platform_get_height(PlatformState* state) { return state->height; } +inline float platform_get_aspect_ratio(PlatformState* state) { + if (state->height == 0) return 1.0f; + return (float)state->width / (float)state->height; +} -GLFWwindow* platform_get_window(); -double platform_get_time(); +// glfwGetTime is a simple global query, so it doesn't need the state struct. +// Include the header directly to get the proper linkage. +#include <GLFW/glfw3.h> +inline double platform_get_time() { + return glfwGetTime(); +} -// Add dimension getters -int platform_get_width(); -int platform_get_height(); -float platform_get_aspect_ratio(); -WGPUSurface platform_create_wgpu_surface(WGPUInstance instance); +// WebGPU specific surface creation +#if defined(DEMO_CROSS_COMPILE_WIN32) +#include <webgpu/webgpu.h> +#else +#include <wgpu.h> +#endif +WGPUSurface platform_create_wgpu_surface(WGPUInstance instance, PlatformState* state); |
