diff options
Diffstat (limited to 'src/gpu/shader_composer.h')
| -rw-r--r-- | src/gpu/shader_composer.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/gpu/shader_composer.h b/src/gpu/shader_composer.h new file mode 100644 index 0000000..d0972f2 --- /dev/null +++ b/src/gpu/shader_composer.h @@ -0,0 +1,38 @@ +// This file is part of the 64k demo project. +// It defines the ShaderComposer class for managing WGSL snippets. + +#pragma once + +#include <map> +#include <set> +#include <string> +#include <vector> + +class ShaderComposer { + public: + static ShaderComposer& Get(); + + // Register a snippet (e.g. "common_math", "sdf_primitives") + void RegisterSnippet(const std::string& name, const std::string& code); + + using CompositionMap = std::map<std::string, std::string>; + + // Assemble a final shader string by prepending required snippets + // and recursively resolving #include "snippet_name" directives. + // Optional substitutions: map "placeholder_name" -> "actual_snippet_name" + std::string Compose(const std::vector<std::string>& dependencies, + const std::string& main_code, + const CompositionMap& substitutions = {}); + + // Verify all #include directives reference registered snippets + void VerifyIncludes() const; + + private: + ShaderComposer() = default; + + void ResolveRecursive(const std::string& source, std::stringstream& ss, + std::set<std::string>& included, + const CompositionMap& substitutions); + + std::map<std::string, std::string> snippets_; +}; |
