summaryrefslogtreecommitdiff
path: root/src/platform
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform')
-rw-r--r--src/platform/headless_platform.cc6
-rw-r--r--src/platform/platform.cc21
-rw-r--r--src/platform/platform.h38
-rw-r--r--src/platform/stub_platform.cc3
-rw-r--r--src/platform/stub_types.h6
5 files changed, 10 insertions, 64 deletions
diff --git a/src/platform/headless_platform.cc b/src/platform/headless_platform.cc
index 4ec8c5d..32e16fe 100644
--- a/src/platform/headless_platform.cc
+++ b/src/platform/headless_platform.cc
@@ -8,13 +8,11 @@
#include <stdio.h>
static double g_virtual_time = 0.0;
-static bool g_should_close = false;
static const double FRAME_TIME = 1.0 / 60.0;
PlatformState platform_init(bool fullscreen, int width, int height) {
(void)fullscreen;
g_virtual_time = 0.0;
- g_should_close = false;
printf("[headless] Platform initialized (simulated %dx%d)\n", width, height);
PlatformState state = {};
@@ -33,13 +31,13 @@ void platform_shutdown(PlatformState* state) {
}
void platform_poll(PlatformState* state) {
- (void)state;
g_virtual_time += FRAME_TIME;
+ state->time = g_virtual_time;
}
bool platform_should_close(PlatformState* state) {
(void)state;
- return g_should_close;
+ return false;
}
void platform_toggle_fullscreen(PlatformState* state) {
diff --git a/src/platform/platform.cc b/src/platform/platform.cc
index 29b3af3..ce9ec41 100644
--- a/src/platform/platform.cc
+++ b/src/platform/platform.cc
@@ -52,16 +52,8 @@ PlatformState platform_init(bool fullscreen, int width, int height) {
state.aspect_ratio = (float)state.width / (float)state.height;
}
- // Store our state in a static pointer or use the window pointer?
- // We'll use a pointer to a persistent state.
- // For this demo, we can assume the PlatformState persists in main().
- // But we return by value. This is a bit tricky with callbacks.
- // We'll fix the callbacks in platform_poll if needed, or just let main pass
- // the pointer back.
-
- glfwSetWindowUserPointer(state.window,
- nullptr); // Will be set in main's state
-
+ // User pointer is set on first platform_poll() when the caller's
+ // PlatformState address is stable.
glfwSetKeyCallback(state.window, glfw_key_callback);
glfwSetFramebufferSizeCallback(state.window, framebuffer_size_callback);
@@ -88,16 +80,9 @@ void platform_shutdown(PlatformState* state) {
}
void platform_poll(PlatformState* state) {
- // Ensure the window has the current state pointer for callbacks
- if (glfwGetWindowUserPointer(state->window) != state) {
- glfwSetWindowUserPointer(state->window, state);
- }
-
+ glfwSetWindowUserPointer(state->window, state);
glfwPollEvents();
state->time = glfwGetTime();
- if (state->height > 0) {
- state->aspect_ratio = (float)state->width / (float)state->height;
- }
}
bool platform_should_close(PlatformState* state) {
diff --git a/src/platform/platform.h b/src/platform/platform.h
index 4b31ac3..26f11a5 100644
--- a/src/platform/platform.h
+++ b/src/platform/platform.h
@@ -9,39 +9,14 @@
// WebGPU specific headers and shims
#if defined(STRIP_EXTERNAL_LIBS)
#include "stub_types.h"
-
-#elif defined(DEMO_CROSS_COMPILE_WIN32)
+#else
+#if defined(DEMO_CROSS_COMPILE_WIN32)
#include <webgpu/webgpu.h>
#include <webgpu/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) {
-}
-
#else
#include <webgpu.h>
#include <wgpu.h>
+#endif
static inline WGPUStringView str_view(const char* str) {
if (!str)
@@ -63,12 +38,6 @@ static inline WGPUStringView label_view(const char* str) {
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.
@@ -85,7 +54,6 @@ struct PlatformState {
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);
diff --git a/src/platform/stub_platform.cc b/src/platform/stub_platform.cc
index 61473a0..a177ab3 100644
--- a/src/platform/stub_platform.cc
+++ b/src/platform/stub_platform.cc
@@ -11,14 +11,13 @@
struct GLFWwindow {};
PlatformState platform_init(bool fullscreen, int width, int height) {
- (void)fullscreen;
PlatformState state = {};
state.width = width;
state.height = height;
state.aspect_ratio = (float)width / (float)height;
state.window = nullptr;
state.time = 0.0;
- state.is_fullscreen = false;
+ state.is_fullscreen = fullscreen;
return state;
}
diff --git a/src/platform/stub_types.h b/src/platform/stub_types.h
index f2810ea..6cef8c7 100644
--- a/src/platform/stub_types.h
+++ b/src/platform/stub_types.h
@@ -103,6 +103,7 @@ struct WGPUPrimitiveState {};
struct WGPUMultisampleState {};
struct WGPUDepthStencilState {};
struct WGPURenderPassDescriptor {};
+// Non-empty: gpu_init_color_attachment writes these fields directly.
struct WGPURenderPassColorAttachment {
WGPUTextureView view;
WGPULoadOp loadOp;
@@ -156,16 +157,11 @@ static inline WGPUStringView label_view(const char* str) {
// Platform shims (no-ops)
static inline void platform_wgpu_wait_any(WGPUInstance) {
}
-static inline void platform_wgpu_set_error_callback(WGPUDevice, void*) {
-}
// Constants
#define WGPU_DEPTH_SLICE_UNDEFINED 0xffffffff
#define WGPUOptionalBool_True true
#define WGPUOptionalBool_False false
-// Callback types (empty)
-typedef void (*WGPUErrorCallback)(void*, void*, const char*);
-typedef void (*WGPUUncapturedErrorCallback)(void*, void*, const char*);
#endif // STRIP_EXTERNAL_LIBS