summaryrefslogtreecommitdiff
path: root/src/platform.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform.cc')
-rw-r--r--src/platform.cc44
1 files changed, 42 insertions, 2 deletions
diff --git a/src/platform.cc b/src/platform.cc
index ff45964..464003f 100644
--- a/src/platform.cc
+++ b/src/platform.cc
@@ -11,6 +11,22 @@ static GLFWwindow* window = nullptr;
static int windowed_x, windowed_y, windowed_w, windowed_h;
static bool g_is_fullscreen = false;
+// --- New state for framebuffer size ---
+static int g_width = 1280;
+static int g_height = 720;
+
+// Forward declaration for callback
+void platform_toggle_fullscreen();
+
+// --- Callbacks ---
+
+static void framebuffer_size_callback(GLFWwindow* cb_window, int width, int height) {
+ (void)cb_window; // Unused
+ g_width = width;
+ g_height = height;
+ // Note: We would trigger a swap chain resize here, but our demo handles it implicitly.
+}
+
static void glfw_key_callback(GLFWwindow* cb_window, int key, int scancode,
int action, int mods) {
if (action == GLFW_PRESS) {
@@ -22,11 +38,21 @@ static void glfw_key_callback(GLFWwindow* cb_window, int key, int scancode,
}
}
-void platform_init_window(bool fullscreen) {
+void platform_init_window(bool fullscreen, int* width_ptr, int* height_ptr) {
+ if (width_ptr && height_ptr) {
+ g_width = *width_ptr;
+ g_height = *height_ptr;
+ }
+
glfwInit();
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
- window = glfwCreateWindow(1280, 720, "demo64k", nullptr, nullptr);
+ window = glfwCreateWindow(g_width, g_height, "demo64k", nullptr, nullptr);
+
+ // Immediately query the actual framebuffer size for high-DPI displays
+ glfwGetFramebufferSize(window, &g_width, &g_height);
+
glfwSetKeyCallback(window, glfw_key_callback);
+ glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
g_is_fullscreen = fullscreen;
if (fullscreen) {
@@ -78,6 +104,20 @@ double platform_get_time() {
return glfwGetTime();
}
+// --- New dimension getters ---
+int platform_get_width() {
+ return g_width;
+}
+
+int platform_get_height() {
+ return g_height;
+}
+
+float platform_get_aspect_ratio() {
+ if (g_height == 0) return 1.0f;
+ return (float)g_width / (float)g_height;
+}
+
WGPUSurface platform_create_wgpu_surface(WGPUInstance instance) {
return glfwCreateWindowWGPUSurface(instance, window);
}