summaryrefslogtreecommitdiff
path: root/src/gpu/effects/shader_composer.cc
blob: 61da6e6808400a7fcefe45f10704148525551eba (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
31
32
33
// This file is part of the 64k demo project.
// It implements the ShaderComposer class.

#include "gpu/effects/shader_composer.h"
#include <sstream>

ShaderComposer& ShaderComposer::Get() {
    static ShaderComposer instance;
    return instance;
}

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";
        }
    }
    
    ss << "// --- Main Code ---\n";
    ss << main_code;
    
    return ss.str();
}