summaryrefslogtreecommitdiff
path: root/src/platform.h
blob: 726787310ba1577082bb47eefef4b18dfe99afb3 (plain)
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
// Handles windowing, input, and native surface creation.

#pragma once

// Forward declare GLFWwindow to avoid including the full header here.
struct GLFWwindow;

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;
}

// 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();
}

// 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);