feat: post-processing effects
This commit is contained in:
@@ -27,21 +27,21 @@ void GLSLExtension::loadHeader(const std::string& name) {
|
||||
}
|
||||
io::path file = paths->find("shaders/lib/" + name + ".glsl");
|
||||
std::string source = io::read_string(file);
|
||||
addHeader(name, "");
|
||||
|
||||
auto [code, _] = process(file, source, true);
|
||||
addHeader(name, std::move(code));
|
||||
addHeader(name, {});
|
||||
addHeader(name, process(file, source, true));
|
||||
}
|
||||
|
||||
void GLSLExtension::addHeader(const std::string& name, std::string source) {
|
||||
headers[name] = std::move(source);
|
||||
void GLSLExtension::addHeader(const std::string& name, ProcessingResult header) {
|
||||
headers[name] = std::move(header);
|
||||
}
|
||||
|
||||
void GLSLExtension::define(const std::string& name, std::string value) {
|
||||
defines[name] = std::move(value);
|
||||
}
|
||||
|
||||
const std::string& GLSLExtension::getHeader(const std::string& name) const {
|
||||
const GLSLExtension::ProcessingResult& GLSLExtension::getHeader(
|
||||
const std::string& name
|
||||
) const {
|
||||
auto found = headers.find(name);
|
||||
if (found == headers.end()) {
|
||||
throw std::runtime_error("no header '" + name + "' loaded");
|
||||
@@ -161,7 +161,11 @@ public:
|
||||
if (!glsl.hasHeader(headerName)) {
|
||||
glsl.loadHeader(headerName);
|
||||
}
|
||||
ss << glsl.getHeader(headerName) << '\n';
|
||||
const auto& header = glsl.getHeader(headerName);
|
||||
for (const auto& [name, param] : header.params) {
|
||||
params[name] = param;
|
||||
}
|
||||
ss << header.code << '\n';
|
||||
source_line(ss, line);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -11,13 +11,20 @@ class ResPaths;
|
||||
|
||||
class GLSLExtension {
|
||||
public:
|
||||
using ParamsMap = std::unordered_map<std::string, PostEffect::Param>;
|
||||
|
||||
struct ProcessingResult {
|
||||
std::string code;
|
||||
ParamsMap params;
|
||||
};
|
||||
|
||||
void setPaths(const ResPaths* paths);
|
||||
|
||||
void define(const std::string& name, std::string value);
|
||||
void undefine(const std::string& name);
|
||||
void addHeader(const std::string& name, std::string source);
|
||||
void addHeader(const std::string& name, ProcessingResult header);
|
||||
|
||||
const std::string& getHeader(const std::string& name) const;
|
||||
const ProcessingResult& getHeader(const std::string& name) const;
|
||||
const std::string& getDefine(const std::string& name) const;
|
||||
|
||||
const std::unordered_map<std::string, std::string>& getDefines() const;
|
||||
@@ -25,12 +32,7 @@ public:
|
||||
bool hasHeader(const std::string& name) const;
|
||||
bool hasDefine(const std::string& name) const;
|
||||
void loadHeader(const std::string& name);
|
||||
|
||||
struct ProcessingResult {
|
||||
std::string code;
|
||||
std::unordered_map<std::string, PostEffect::Param> params;
|
||||
};
|
||||
|
||||
|
||||
ProcessingResult process(
|
||||
const io::path& file,
|
||||
const std::string& source,
|
||||
@@ -39,7 +41,7 @@ public:
|
||||
|
||||
static inline std::string VERSION = "330 core";
|
||||
private:
|
||||
std::unordered_map<std::string, std::string> headers;
|
||||
std::unordered_map<std::string, ProcessingResult> headers;
|
||||
std::unordered_map<std::string, std::string> defines;
|
||||
|
||||
const ResPaths* paths = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user