summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/test_mesh.cc24
1 files changed, 9 insertions, 15 deletions
diff --git a/src/tests/test_mesh.cc b/src/tests/test_mesh.cc
index 949aa63..0294d9b 100644
--- a/src/tests/test_mesh.cc
+++ b/src/tests/test_mesh.cc
@@ -11,14 +11,11 @@
#include <webgpu.h>
#include "procedural/generator.h"
#include <algorithm>
-#include <atomic>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <map>
-#include <mutex>
-#include <thread> // For std::this_thread::sleep_for
#include <vector>
// Global State
@@ -35,10 +32,6 @@ static WGPUTextureFormat g_format = WGPUTextureFormat_Undefined;
// Test-specific storage for mesh buffers
static Renderer3D::MeshGpuData g_mesh_gpu_data;
-// For asynchronous WGPU initialization
-static std::atomic<bool> s_adapter_ready(false);
-static std::atomic<bool> s_device_ready(false);
-
// Callbacks for asynchronous WGPU initialization (matches test_3d_render.cc)
void on_adapter_request_ended(WGPURequestAdapterStatus status,
WGPUAdapter adapter, WGPUStringView message,
@@ -49,7 +42,6 @@ void on_adapter_request_ended(WGPURequestAdapterStatus status,
} else {
fprintf(stderr, "Failed to request adapter.\n"); // Avoid WGPUStringView::s issues
}
- s_adapter_ready.store(true);
}
void on_device_request_ended(WGPURequestDeviceStatus status,
@@ -61,11 +53,15 @@ void on_device_request_ended(WGPURequestDeviceStatus status,
} else {
fprintf(stderr, "Failed to request device.\n"); // Avoid WGPUStringView::s issues
}
- s_device_ready.store(true);
}
// --- WGPU Boilerplate ---
void init_wgpu(WGPUInstance instance, PlatformState* platform_state) {
+ if (!instance) {
+ fprintf(stderr, "Failed to create WGPU instance.\n");
+ exit(1);
+ }
+
g_surface = platform_create_wgpu_surface(instance, platform_state);
if (!g_surface) {
fprintf(stderr, "Failed to create WGPU surface.\n");
@@ -82,11 +78,10 @@ void init_wgpu(WGPUInstance instance, PlatformState* platform_state) {
adapter_callback_info.callback = on_adapter_request_ended;
adapter_callback_info.userdata1 = &g_adapter; // Corrected to userdata1
- s_adapter_ready.store(false);
wgpuInstanceRequestAdapter(instance, &adapter_opts, adapter_callback_info);
// Busy-wait for adapter
- while (!s_adapter_ready.load()) {
+ while (!g_adapter) {
platform_wgpu_wait_any(instance);
}
@@ -97,11 +92,10 @@ void init_wgpu(WGPUInstance instance, PlatformState* platform_state) {
device_callback_info.callback = on_device_request_ended;
device_callback_info.userdata1 = &g_device; // Corrected to userdata1
- s_device_ready.store(false);
wgpuAdapterRequestDevice(g_adapter, &device_desc, device_callback_info);
// Busy-wait for device
- while (!s_device_ready.load()) {
+ while (!g_device) {
platform_wgpu_wait_any(instance);
}
@@ -298,7 +292,7 @@ int main(int argc, char** argv) {
WGPUSurfaceTexture surface_tex;
wgpuSurfaceGetCurrentTexture(g_surface, &surface_tex);
- if (surface_tex.status == 0) { // WGPUSurfaceGetCurrentTextureStatus_Success is 0
+ if (surface_tex.status == WGPUSurfaceGetCurrentTextureStatus_SuccessOptimal) { // WGPUSurfaceGetCurrentTextureStatus_Success is 0
WGPUTextureView view = wgpuTextureCreateView(surface_tex.texture, nullptr);
g_renderer.render(g_scene, g_camera, time, view);
wgpuTextureViewRelease(view);
@@ -319,4 +313,4 @@ int main(int argc, char** argv) {
g_textures.shutdown();
platform_shutdown(&platform_state);
return 0;
-}
+} \ No newline at end of file