summaryrefslogtreecommitdiff
path: root/src/3d/visual_debug.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/3d/visual_debug.cc')
-rw-r--r--src/3d/visual_debug.cc41
1 files changed, 8 insertions, 33 deletions
diff --git a/src/3d/visual_debug.cc b/src/3d/visual_debug.cc
index 51ccc39..f8d9bed 100644
--- a/src/3d/visual_debug.cc
+++ b/src/3d/visual_debug.cc
@@ -5,40 +5,11 @@
#if !defined(STRIP_ALL)
+#include "generated/assets.h"
+#include "util/asset_manager.h"
#include <cstdio>
#include <cstring>
-// Simple shader for drawing colored lines
-static const char* kDebugShaderCode = R"(
-struct Uniforms {
- viewProj : mat4x4<f32>,
-}
-@group(0) @binding(0) var<uniform> uniforms : Uniforms;
-
-struct VertexInput {
- @location(0) position : vec3<f32>,
- @location(1) color : vec3<f32>,
-}
-
-struct VertexOutput {
- @builtin(position) position : vec4<f32>,
- @location(0) color : vec3<f32>,
-}
-
-@vertex
-fn vs_main(in : VertexInput) -> VertexOutput {
- var out : VertexOutput;
- out.position = uniforms.viewProj * vec4<f32>(in.position, 1.0);
- out.color = in.color;
- return out;
-}
-
-@fragment
-fn fs_main(in : VertexOutput) -> @location(0) vec4<f32> {
- return vec4<f32>(in.color, 1.0);
-}
-)";
-
void VisualDebug::init(WGPUDevice device, WGPUTextureFormat format) {
device_ = device;
create_pipeline(format);
@@ -92,16 +63,20 @@ void VisualDebug::create_pipeline(WGPUTextureFormat format) {
wgpuDeviceCreatePipelineLayout(device_, &pl_desc);
// Shader
+ size_t shader_len = 0;
+ const char* shader_code =
+ (const char*)GetAsset(AssetId::ASSET_SHADER_VISUAL_DEBUG, &shader_len);
+
#if defined(DEMO_CROSS_COMPILE_WIN32)
WGPUShaderModuleWGSLDescriptor wgsl_desc = {};
wgsl_desc.chain.sType = WGPUSType_ShaderModuleWGSLDescriptor;
- wgsl_desc.code = kDebugShaderCode;
+ wgsl_desc.code = shader_code;
WGPUShaderModuleDescriptor shader_desc = {};
shader_desc.nextInChain = (const WGPUChainedStruct*)&wgsl_desc.chain;
#else
WGPUShaderSourceWGSL wgsl_desc = {};
wgsl_desc.chain.sType = WGPUSType_ShaderSourceWGSL;
- wgsl_desc.code = {kDebugShaderCode, strlen(kDebugShaderCode)};
+ wgsl_desc.code = {shader_code, shader_len};
WGPUShaderModuleDescriptor shader_desc = {};
shader_desc.nextInChain = (const WGPUChainedStruct*)&wgsl_desc.chain;
#endif