diff options
Diffstat (limited to 'src/gpu')
| -rw-r--r-- | src/gpu/effects/shader_composer.cc | 42 | ||||
| -rw-r--r-- | src/gpu/effects/shader_composer.h | 21 | ||||
| -rw-r--r-- | src/gpu/effects/shaders.cc | 10 | ||||
| -rw-r--r-- | src/gpu/gpu.h | 4 |
4 files changed, 40 insertions, 37 deletions
diff --git a/src/gpu/effects/shader_composer.cc b/src/gpu/effects/shader_composer.cc index 61da6e6..3e08df9 100644 --- a/src/gpu/effects/shader_composer.cc +++ b/src/gpu/effects/shader_composer.cc @@ -5,29 +5,31 @@ #include <sstream> ShaderComposer& ShaderComposer::Get() { - static ShaderComposer instance; - return instance; + static ShaderComposer instance; + return instance; } -void ShaderComposer::RegisterSnippet(const std::string& name, const std::string& code) { - snippets_[name] = code; +void ShaderComposer::RegisterSnippet(const std::string& name, + const std::string& code) { + snippets_[name] = code; } -std::string ShaderComposer::Compose(const std::vector<std::string>& dependencies, const std::string& main_code) { - std::stringstream ss; - ss << "// Generated by ShaderComposer\n\n"; - - for (const auto& dep : dependencies) { - auto it = snippets_.find(dep); - if (it != snippets_.end()) { - ss << "// --- Snippet: " << dep << " ---\n"; - ss << it->second << "\n"; - } +std::string +ShaderComposer::Compose(const std::vector<std::string>& dependencies, + const std::string& main_code) { + std::stringstream ss; + ss << "// Generated by ShaderComposer\n\n"; + + for (const auto& dep : dependencies) { + auto it = snippets_.find(dep); + if (it != snippets_.end()) { + ss << "// --- Snippet: " << dep << " ---\n"; + ss << it->second << "\n"; } - - ss << "// --- Main Code ---\n"; - ss << main_code; - - return ss.str(); -} + } + ss << "// --- Main Code ---\n"; + ss << main_code; + + return ss.str(); +} diff --git a/src/gpu/effects/shader_composer.h b/src/gpu/effects/shader_composer.h index 7d918a9..49bf00c 100644 --- a/src/gpu/effects/shader_composer.h +++ b/src/gpu/effects/shader_composer.h @@ -3,21 +3,22 @@ #pragma once -#include <string> #include <map> +#include <string> #include <vector> class ShaderComposer { -public: - static ShaderComposer& Get(); + public: + static ShaderComposer& Get(); - // Register a snippet (e.g. "common_math", "sdf_primitives") - void RegisterSnippet(const std::string& name, const std::string& code); + // Register a snippet (e.g. "common_math", "sdf_primitives") + void RegisterSnippet(const std::string& name, const std::string& code); - // Assemble a final shader string by prepending required snippets - std::string Compose(const std::vector<std::string>& dependencies, const std::string& main_code); + // Assemble a final shader string by prepending required snippets + std::string Compose(const std::vector<std::string>& dependencies, + const std::string& main_code); -private: - ShaderComposer() = default; - std::map<std::string, std::string> snippets_; + private: + ShaderComposer() = default; + std::map<std::string, std::string> snippets_; }; diff --git a/src/gpu/effects/shaders.cc b/src/gpu/effects/shaders.cc index 746392a..579160c 100644 --- a/src/gpu/effects/shaders.cc +++ b/src/gpu/effects/shaders.cc @@ -6,9 +6,9 @@ #include "gpu/effects/shader_composer.h" void InitShaderComposer() { - auto& sc = ShaderComposer::Get(); + auto& sc = ShaderComposer::Get(); - sc.RegisterSnippet("common_uniforms", R"( + sc.RegisterSnippet("common_uniforms", R"( struct GlobalUniforms { view_proj: mat4x4<f32>, camera_pos_time: vec4<f32>, @@ -25,7 +25,7 @@ struct ObjectsBuffer { }; )"); - sc.RegisterSnippet("sdf_primitives", R"( + sc.RegisterSnippet("sdf_primitives", R"( fn sdSphere(p: vec3<f32>, r: f32) -> f32 { return length(p) - r; } @@ -42,7 +42,7 @@ fn sdPlane(p: vec3<f32>, n: vec3<f32>, h: f32) -> f32 { } )"); - sc.RegisterSnippet("lighting", R"( + sc.RegisterSnippet("lighting", R"( fn get_normal_basic(p: vec3<f32>, obj_type: f32) -> vec3<f32> { if (obj_type == 1.0) { return normalize(p); } let e = vec2<f32>(0.001, 0.0); @@ -68,7 +68,7 @@ fn calc_shadow(ro: vec3<f32>, rd: vec3<f32>, tmin: f32, tmax: f32, skip_idx: u32 } )"); - sc.RegisterSnippet("ray_box", R"( + sc.RegisterSnippet("ray_box", R"( struct RayBounds { t_entry: f32, t_exit: f32, diff --git a/src/gpu/gpu.h b/src/gpu/gpu.h index f25d242..45c6413 100644 --- a/src/gpu/gpu.h +++ b/src/gpu/gpu.h @@ -107,8 +107,8 @@ void gpu_simulate_until(float time); void gpu_shutdown(); // Placeholder for GPU performance capture. -// This define can be controlled via CMake to conditionally enable profiling code. -// #define ENABLE_GPU_PERF_CAPTURE +// This define can be controlled via CMake to conditionally enable profiling +// code. #define ENABLE_GPU_PERF_CAPTURE // Helper functions (exposed for internal/future use) struct ResourceBinding { |
