diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-03 18:44:41 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-03 18:44:41 +0100 |
| commit | bf46e44e1cb6027a072819a2a3aa3be32651f6e1 (patch) | |
| tree | 21267e7ef52fd91e7b99271ed87e275e91b3de3c /src/tests/test_3d_render.cc | |
| parent | 815c428dea14a6a1ea5c421c400985d0c14d473d (diff) | |
refactor: Task #20 - Platform & Code Hygiene
- Consolidated all WebGPU shims and platform-specific logic into src/platform.h.
- Refactored platform_init to return PlatformState by value and platform_poll to automatically refresh time and aspect_ratio.
- Removed STL dependencies (std::map, std::vector, std::string) from AssetManager and Procedural subsystems.
- Fixed Windows cross-compilation by adjusting include paths and linker flags in CMakeLists.txt and updating build_win.sh.
- Removed redundant direct inclusions of GLFW/glfw3.h and WebGPU headers across the project.
- Applied clang-format and updated documentation.
handoff(Gemini): Completed Task #20 and 20.1. Platform abstraction is now unified, and core paths are STL-free. Windows build is stable.
Diffstat (limited to 'src/tests/test_3d_render.cc')
| -rw-r--r-- | src/tests/test_3d_render.cc | 45 |
1 files changed, 13 insertions, 32 deletions
diff --git a/src/tests/test_3d_render.cc b/src/tests/test_3d_render.cc index cc7dce6..6e639cd 100644 --- a/src/tests/test_3d_render.cc +++ b/src/tests/test_3d_render.cc @@ -5,21 +5,15 @@ #include "3d/object.h" #include "3d/renderer.h" #include "3d/scene.h" -#include "gpu/texture_manager.h" #include "gpu/effects/shaders.h" +#include "gpu/texture_manager.h" #include "platform.h" #include "procedural/generator.h" #include <cmath> +#include <cstdio> #include <cstring> -#include <iostream> #include <vector> -#if defined(DEMO_CROSS_COMPILE_WIN32) -#include <webgpu/webgpu.h> -#else -#include <webgpu.h> -#endif - // Global State static Renderer3D g_renderer; static TextureManager g_textures; @@ -35,13 +29,13 @@ static WGPUTextureFormat g_format = WGPUTextureFormat_Undefined; void init_wgpu(PlatformState* platform_state) { WGPUInstance instance = wgpuCreateInstance(nullptr); if (!instance) { - std::cerr << "Failed to create WGPU instance." << std::endl; + fprintf(stderr, "Failed to create WGPU instance.\n"); exit(1); } g_surface = platform_create_wgpu_surface(instance, platform_state); if (!g_surface) { - std::cerr << "Failed to create WGPU surface." << std::endl; + fprintf(stderr, "Failed to create WGPU surface.\n"); exit(1); } @@ -60,6 +54,7 @@ void init_wgpu(PlatformState* platform_state) { #else auto on_adapter = [](WGPURequestAdapterStatus status, WGPUAdapter adapter, WGPUStringView message, void* userdata, void* user2) { + (void)user2; if (status == WGPURequestAdapterStatus_Success) { *(WGPUAdapter*)userdata = adapter; } @@ -71,15 +66,8 @@ void init_wgpu(PlatformState* platform_state) { wgpuInstanceRequestAdapter(instance, &adapter_opts, adapter_cb); #endif -#if !defined(DEMO_CROSS_COMPILE_WIN32) while (!g_adapter) { - wgpuInstanceProcessEvents(instance); - } -#endif - - if (!g_adapter) { - std::cerr << "Failed to get adapter." << std::endl; - exit(1); + platform_wgpu_wait_any(instance); } WGPUDeviceDescriptor device_desc = {}; @@ -95,6 +83,7 @@ void init_wgpu(PlatformState* platform_state) { #else auto on_device = [](WGPURequestDeviceStatus status, WGPUDevice device, WGPUStringView message, void* userdata, void* user2) { + (void)user2; if (status == WGPURequestDeviceStatus_Success) { *(WGPUDevice*)userdata = device; } @@ -106,15 +95,8 @@ void init_wgpu(PlatformState* platform_state) { wgpuAdapterRequestDevice(g_adapter, &device_desc, device_cb); #endif -#if !defined(DEMO_CROSS_COMPILE_WIN32) while (!g_device) { - wgpuInstanceProcessEvents(instance); - } -#endif - - if (!g_device) { - std::cerr << "Failed to get device." << std::endl; - exit(1); + platform_wgpu_wait_any(instance); } g_queue = wgpuDeviceGetQueue(g_device); @@ -206,8 +188,7 @@ int main(int argc, char** argv) { (void)argv; #endif - PlatformState platform_state = {}; - platform_init(&platform_state, false, nullptr, nullptr); + PlatformState platform_state = platform_init(false, 1280, 720); // The test's own WGPU init sequence init_wgpu(&platform_state); @@ -222,7 +203,8 @@ int main(int argc, char** argv) { noise_def.width = 256; noise_def.height = 256; noise_def.gen_func = gen_periodic_noise; - noise_def.params = {1234.0f, 16.0f}; + noise_def.params.push_back(1234.0f); + noise_def.params.push_back(16.0f); g_textures.create_procedural_texture("noise", noise_def); g_renderer.set_noise_texture(g_textures.get_texture_view("noise")); @@ -232,17 +214,16 @@ int main(int argc, char** argv) { g_camera.position = vec3(0, 5, 10); g_camera.target = vec3(0, 0, 0); - float time = 0.0f; while (!platform_should_close(&platform_state)) { platform_poll(&platform_state); - time = (float)platform_get_time(); + float time = (float)platform_state.time; float cam_radius = 10.0f + std::sin(time * 0.3f) * 4.0f; float cam_height = 5.0f + std::cos(time * 0.4f) * 3.0f; g_camera.set_look_at(vec3(std::sin(time * 0.5f) * cam_radius, cam_height, std::cos(time * 0.5f) * cam_radius), vec3(0, 0, 0), vec3(0, 1, 0)); - g_camera.aspect_ratio = platform_get_aspect_ratio(&platform_state); + g_camera.aspect_ratio = platform_state.aspect_ratio; for (size_t i = 1; i < g_scene.objects.size(); ++i) { // Rotation around a random-ish 3D axis |
