blob: a63a6a478315064a5402e3ab185f2b949552c7cc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
// 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);
// Assemble a final shader string by prepending required snippets
// and recursively resolving #include "snippet_name" directives.
std::string Compose(const std::vector<std::string>& dependencies,
const std::string& main_code);
private:
ShaderComposer() = default;
void ResolveRecursive(const std::string& source, std::stringstream& ss,
std::set<std::string>& included);
std::map<std::string, std::string> snippets_;
};
|