diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.cc | 21 | ||||
| -rw-r--r-- | src/platform.cc | 44 | ||||
| -rw-r--r-- | src/platform.h | 10 | ||||
| -rw-r--r-- | src/tests/test_3d_render.cc | 9 |
4 files changed, 69 insertions, 15 deletions
diff --git a/src/main.cc b/src/main.cc index 8cedfce..f7136ef 100644 --- a/src/main.cc +++ b/src/main.cc @@ -130,7 +130,10 @@ float* generate_tone(float* buffer, float freq) { int main(int argc, char** argv) { bool fullscreen_enabled = false; - double seek_time = 0.0; + float seek_time = 0.0f; + int* width_ptr = nullptr; + int* height_ptr = nullptr; + int custom_width, custom_height; #if !defined(STRIP_ALL) for (int i = 1; i < argc; ++i) { @@ -139,6 +142,12 @@ int main(int argc, char** argv) { } else if (strcmp(argv[i], "--seek") == 0 && i + 1 < argc) { seek_time = atof(argv[i + 1]); ++i; + } else if (strcmp(argv[i], "--resolution") == 0 && i + 1 < argc) { + const char* res_str = argv[++i]; + if (sscanf(res_str, "%dx%d", &custom_width, &custom_height) == 2) { + width_ptr = &custom_width; + height_ptr = &custom_height; + } } } #else @@ -147,10 +156,8 @@ int main(int argc, char** argv) { fullscreen_enabled = true; #endif /* STRIP_ALL */ - platform_init_window(fullscreen_enabled); - int width, height; - glfwGetFramebufferSize(platform_get_window(), &width, &height); - gpu_init(platform_get_window(), width, height); + platform_init_window(fullscreen_enabled, width_ptr, height_ptr); + gpu_init(platform_get_window(), platform_get_width(), platform_get_height()); audio_init(); // Register drum assets @@ -234,9 +241,7 @@ int main(int argc, char** argv) { update_game_logic(current_time); - int width, height; - glfwGetFramebufferSize(platform_get_window(), &width, &height); - float aspect_ratio = (float)width / (float)height; + float aspect_ratio = platform_get_aspect_ratio(); // Adjusted multiplier for visuals (preventing constant 1.0 saturation) float raw_peak = synth_get_output_peak(); 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); } diff --git a/src/platform.h b/src/platform.h index 9cfaf00..38a0568 100644 --- a/src/platform.h +++ b/src/platform.h @@ -6,16 +6,20 @@ #include <webgpu.h> +// Forward declare GLFWwindow to avoid including the full header here. struct GLFWwindow; -void platform_init_window(bool fullscreen); +void platform_init_window(bool fullscreen, int* width_ptr, int* height_ptr); void platform_shutdown(); void platform_poll(); bool platform_should_close(); -void platform_toggle_fullscreen(); - GLFWwindow* platform_get_window(); double platform_get_time(); +// Add dimension getters +int platform_get_width(); +int platform_get_height(); +float platform_get_aspect_ratio(); + WGPUSurface platform_create_wgpu_surface(WGPUInstance instance); diff --git a/src/tests/test_3d_render.cc b/src/tests/test_3d_render.cc index e4477a0..0a809c4 100644 --- a/src/tests/test_3d_render.cc +++ b/src/tests/test_3d_render.cc @@ -174,8 +174,13 @@ void gen_periodic_noise(uint8_t* buffer, int w, int h, const float* params, } int main() { - platform_init_window(false); - init_wgpu(); + printf("Running 3D Renderer Test...\n"); + + platform_init_window(false, nullptr, nullptr); + gpu_init(platform_get_window(), platform_get_width(), platform_get_height()); + + // Create Renderer and Scene + Renderer3D renderer; g_renderer.init(g_device, g_queue, g_format); g_renderer.resize(g_width, g_height); |
