2018-10-07 02:53:57 +00:00
|
|
|
#pragma once
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
2018-12-08 05:18:42 +00:00
|
|
|
namespace hecl::shaderc {
|
2018-10-07 02:53:57 +00:00
|
|
|
|
2018-12-08 05:18:42 +00:00
|
|
|
class Compiler {
|
|
|
|
enum class StageType { Vertex, Fragment, Geometry, Control, Evaluation };
|
|
|
|
|
2021-06-30 18:20:45 +00:00
|
|
|
std::vector<std::string> m_inputFiles;
|
|
|
|
std::unordered_map<std::string, std::string> m_fileContents;
|
|
|
|
const std::string* getFileContents(std::string_view path);
|
2018-12-08 05:18:42 +00:00
|
|
|
std::unordered_map<std::string, std::string> m_defines;
|
|
|
|
template <typename Action, typename P>
|
|
|
|
static bool StageAction(StageType type, const std::string& name, const std::string& basename,
|
2019-07-20 04:22:58 +00:00
|
|
|
const std::string& stage, std::stringstream& implOut);
|
2018-12-08 05:18:42 +00:00
|
|
|
template <typename Action>
|
|
|
|
static bool StageAction(const std::string& platforms, StageType type, const std::string& name,
|
2019-07-20 04:22:58 +00:00
|
|
|
const std::string& basename, const std::string& stage, std::stringstream& implOut);
|
2021-06-30 18:20:45 +00:00
|
|
|
bool includeFile(std::string_view file, std::string& out, int depth = 0);
|
|
|
|
bool compileFile(std::string_view file, std::string_view baseName,
|
2019-07-20 04:22:58 +00:00
|
|
|
std::pair<std::stringstream, std::stringstream>& out);
|
2018-10-07 02:53:57 +00:00
|
|
|
|
|
|
|
public:
|
2021-06-30 18:20:45 +00:00
|
|
|
void addInputFile(std::string_view file);
|
2018-12-08 05:18:42 +00:00
|
|
|
void addDefine(std::string_view var, std::string_view val);
|
2019-07-20 04:22:58 +00:00
|
|
|
bool compile(std::string_view baseName, std::pair<std::stringstream, std::stringstream>& out);
|
2018-10-07 02:53:57 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 05:18:42 +00:00
|
|
|
} // namespace hecl::shaderc
|