diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/gpu/gpu.cc | 34 | ||||
| -rw-r--r-- | src/main.cc | 7 |
2 files changed, 40 insertions, 1 deletions
diff --git a/src/gpu/gpu.cc b/src/gpu/gpu.cc index a1da2db..9eb2437 100644 --- a/src/gpu/gpu.cc +++ b/src/gpu/gpu.cc @@ -8,9 +8,12 @@ #include <algorithm> #include <cassert> #include <cstring> -#include <iostream> #include <vector> +#ifndef STRIP_ALL +#include <iostream> +#endif + static WGPUInstance g_instance = nullptr; static WGPUAdapter g_adapter = nullptr; static WGPUDevice g_device = nullptr; @@ -23,10 +26,16 @@ static WGPUBuffer g_uniform_buffer = nullptr; static WGPUBindGroup g_bind_group = nullptr; static WGPUStringView str_view(const char *str) { +#ifndef STRIP_ALL if (!str) return {nullptr, 0}; return {str, strlen(str)}; +#else + (void)str; + return {nullptr, 0}; +#endif } +#ifndef STRIP_ALL static void handle_request_adapter(WGPURequestAdapterStatus status, WGPUAdapter adapter, WGPUStringView message, void *userdata1, void *userdata2) { @@ -36,7 +45,17 @@ static void handle_request_adapter(WGPURequestAdapterStatus status, printf("Request adapter failed: %.*s\n", (int)message.length, message.data); } } +#else +static void handle_request_adapter(WGPURequestAdapterStatus status, + WGPUAdapter adapter, WGPUStringView message, + void *userdata1, void *userdata2) { + if (status == WGPURequestAdapterStatus_Success) { + *((WGPUAdapter *)userdata1) = adapter; + } +} +#endif +#ifndef STRIP_ALL static void handle_request_device(WGPURequestDeviceStatus status, WGPUDevice device, WGPUStringView message, void *userdata1, void *userdata2) { @@ -46,12 +65,23 @@ static void handle_request_device(WGPURequestDeviceStatus status, printf("Request device failed: %.*s\n", (int)message.length, message.data); } } +#else +static void handle_request_device(WGPURequestDeviceStatus status, + WGPUDevice device, WGPUStringView message, + void *userdata1, void *userdata2) { + if (status == WGPURequestDeviceStatus_Success) { + *((WGPUDevice *)userdata1) = device; + } +} +#endif +#ifndef STRIP_ALL static void handle_device_error(WGPUDevice const *device, WGPUErrorType type, WGPUStringView message, void *userdata1, void *userdata2) { printf("WebGPU Error: %.*s\n", (int)message.length, message.data); } +#endif const char *shader_wgsl_code = R"( struct Uniforms { @@ -116,7 +146,9 @@ void gpu_init(GLFWwindow *window) { WGPUDeviceDescriptor device_desc = {}; device_desc.label = str_view("Demo Device"); +#ifndef STRIP_ALL device_desc.uncapturedErrorCallbackInfo.callback = handle_device_error; +#endif wgpuAdapterRequestDevice( g_adapter, &device_desc, diff --git a/src/main.cc b/src/main.cc index 315fa10..ef48f21 100644 --- a/src/main.cc +++ b/src/main.cc @@ -28,12 +28,19 @@ void generate_tone(float *buffer, float freq) { int main(int argc, char **argv) { bool fullscreen_enabled = false; + +#ifndef STRIP_ALL for (int i = 1; i < argc; ++i) { if (strcmp(argv[i], "--fullscreen") == 0) { fullscreen_enabled = true; break; } } +#else + (void)argc; + (void)argv; + fullscreen_enabled = true; +#endif platform_init_window(fullscreen_enabled); gpu_init(platform_get_window()); |
