51{
52 size_t offset = ShaderText.find(shader_preprocessor::LexemBlockStart, 0);
53 if (offset == std::string::npos)
54 {
55 SCL_CORE_ERROR(
"Error while preprocessing shader \"{}\".\nNo shader blcoks was found in text.", ShaderDebugName);
56 return;
57 }
58 std::string global_block(ShaderText.begin(), ShaderText.begin() + offset);
59
60 while (offset != std::string::npos)
61 {
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);
65
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);
69
70 if (block_end_offset != std::string::npos && block_start_offset != std::string::npos)
71 {
72 int spaces_count;
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);
75
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); });
80
81 switch (
StringId(block_shader_type_string.c_str()))
82 {
84 case "vert"_id:
86 case "geom"_id:
88 case "pixel"_id:
89 case "frag"_id:
91 default:
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;
94 }
95
96 if (block_shader_type_ok)
97 Out.push_back({
98 block_shader_type,
99 global_block + std::string(block_text.begin() + spaces_count + block_shader_type_string.size(), block_text.end())
100 });
101 }
102 offset = ShaderText.find(shader_preprocessor::LexemBlockStart, block_end_offset);
103 }
104}
#define SCL_CORE_ERROR(...)
constexpr string_id StringId(const char *Str)