13std::string scl::assets_manager::shader_preprocessor::ReadWord(std::string::const_iterator Begin,
14 std::string::const_iterator End,
18 if (SpacesCount) *SpacesCount = 0;
19 while (Begin != End && ((*Begin) ==
' ' || (*Begin) ==
'\n'))
22 if (SpacesCount) ++(*SpacesCount);
26 return std::string(Begin, Begin + std::min(std::string(Begin, End).find(
' '), std::string(Begin, End).find(
'\n')));
29scl::shader_type scl::assets_manager::shader_preprocessor::ShaderTypeFromString(
const std::string &ShaderTypeString)
31 std::string shader_string_prepared(ShaderTypeString);
32 std::transform(shader_string_prepared.begin(), shader_string_prepared.end(), shader_string_prepared.begin(),
33 [](
unsigned char c) { return std::tolower(c); });
35 switch (
StringId(shader_string_prepared.c_str()))
49 const std::string &ShaderText,
50 std::vector<shader_props> &Out)
52 size_t offset = ShaderText.find(shader_preprocessor::LexemBlockStart, 0);
53 if (offset == std::string::npos)
55 SCL_CORE_ERROR(
"Error while preprocessing shader \"{}\".\nNo shader blcoks was found in text.", ShaderDebugName);
58 std::string global_block(ShaderText.begin(), ShaderText.begin() + offset);
60 while (offset != std::string::npos)
62 size_t block_start_offset = ShaderText.find(
' ', offset);
63 if (block_start_offset == std::string::npos)
64 SCL_CORE_ERROR(
"Error while preprocessing shader \"{}\".\nNo block text found, block skiped.", ShaderDebugName);
66 size_t block_end_offset = ShaderText.find(shader_preprocessor::LexemBlockEnd, offset);
67 if (block_end_offset == std::string::npos)
68 SCL_CORE_ERROR(
"Error while preprocessing shader \"{}\".\nNo block end lexem found. Block skiped.", ShaderDebugName);
70 if (block_end_offset != std::string::npos && block_start_offset != std::string::npos)
73 std::string block_text(ShaderText.begin() + block_start_offset, ShaderText.begin() + block_end_offset);
74 std::string block_shader_type_string = ReadWord(block_text.begin(), block_text.end(), &spaces_count);
77 bool block_shader_type_ok =
true;
78 std::transform(block_shader_type_string.begin(), block_shader_type_string.end(), block_shader_type_string.begin(),
79 [](
unsigned char c) { return std::tolower(c); });
81 switch (
StringId(block_shader_type_string.c_str()))
92 SCL_CORE_ERROR(
"Error while preprocessing shader \"{}\".\nShader type \"{}\" is unknown. Block skipped.", ShaderDebugName, block_shader_type_string);
93 block_shader_type_ok =
false;
96 if (block_shader_type_ok)
99 global_block + std::string(block_text.begin() + spaces_count + block_shader_type_string.size(), block_text.end())
102 offset = ShaderText.find(shader_preprocessor::LexemBlockStart, block_end_offset);
107 const std::string &ShaderFolderPath,
108 std::string &ShaderText)
111 while ((offset = ShaderText.find(shader_preprocessor::LexemInclude, 0)) != std::string::npos)
113 ShaderText.erase(offset, strlen(shader_preprocessor::LexemInclude));
115 int spaces_count = 0;
116 std::string include_path = ReadWord(ShaderText.begin() + offset, ShaderText.end(), &spaces_count);
117 ShaderText.erase(offset, spaces_count + include_path.size());
119 std::string file_name = std::string(include_path.begin() + 1, include_path.end() - 1);
120 std::filesystem::path file_path = ShaderFolderPath / std::filesystem::path(file_name);
121 ShaderText.insert(offset,
LoadFile(file_path));
#define SCL_CORE_ASSERT(expr,...)
static void ProcessIncludes(const std::string &ShaderDebugName, const std::string &ShaderFolderPath, std::string &ShaderText)
static void SeparateShaders(const std::string &ShaderDebugName, const std::string &ShaderText, std::vector< shader_props > &Out)
#define SCL_CORE_ERROR(...)
std::string LoadFile(const std::filesystem::path &FilePath)
constexpr string_id StringId(const char *Str)
Sculpto library prehompiled header. Defines common definitions, includes commonly used modules.
Assets manager shaders preprocessor class definition module.