25 #include "eng3d/glsl_trans.hpp"
26 #include "eng3d/log.hpp"
32 const auto start_it = it;
35 while(it !=
buffer.end() && (isalnum(*it) || *it ==
'_' || *it ==
'.'))
38 std::string str =
buffer.substr(std::distance(
buffer.begin(), start_it), std::distance(start_it, it));
43 const auto start_it = it;
45 while(it != buffer.end() && (isdigit(*it) || *it ==
'.'))
49 while(it != buffer.end() && isalpha(*it))
52 std::string str = buffer.substr(std::distance(buffer.begin(), start_it), std::distance(start_it, it));
58 for(
auto it = buffer.begin(); it != buffer.end(); ) {
59 while(it != buffer.end() && isspace(*it) && (*it ==
'\r'))
62 if(it == buffer.end())
break;
67 }
else if((*(it + 0) ==
'/' && *(it + 1) ==
'/')) {
70 while(it != buffer.end() && (*it !=
'\n'))
72 }
else if((*(it + 0) ==
'/' && *(it + 1) ==
'*')) {
75 while((it + 1) != buffer.end()) {
76 if(*(it + 0) ==
'*' && *(it + 1) ==
'/') {
79 }
else if(*it ==
'\n') {
84 }
else if(*it ==
'#') {
87 while(it != buffer.end() && (*it !=
'\n'))
91 tok.
data = buffer.substr(std::distance(buffer.begin(), start_it), std::distance(start_it, it));
92 tokens.push_back(tok);
93 }
else if(*it ==
',') {
96 }
else if(*it ==
';') {
99 }
else if(*it ==
'(') {
102 }
else if(*it ==
')') {
105 }
else if(*it ==
'[') {
108 }
else if(*it ==
']') {
111 }
else if(*it ==
'{') {
114 }
else if(*it ==
'}') {
117 }
else if(*it ==
'+') {
120 }
else if(*it ==
'-') {
123 }
else if(*it ==
'*') {
126 }
else if(*it ==
'/') {
129 }
else if(*it ==
'%') {
132 }
else if(*it ==
'^') {
135 }
else if(*it ==
'<') {
137 if(it != buffer.end() && *it ==
'=') {
143 }
else if(*it ==
'>') {
145 if(it != buffer.end() && *it ==
'=') {
151 }
else if(*it ==
'|') {
153 if(it != buffer.end() && *it ==
'|') {
159 }
else if(*it ==
'&') {
161 if(it != buffer.end() && *it ==
'&') {
167 }
else if(*it ==
'=') {
169 if(it != buffer.end() && *it ==
'=') {
175 }
else if(*it ==
'?') {
178 }
else if(*it ==
':') {
181 }
else if(*it ==
'.') {
184 }
else if(*it ==
'!' && (it + 1) != buffer.end() && *(it + 1) ==
'=') {
188 if(isdigit(*it) || *it ==
'.') {
190 tok.
data = get_literal(it);
191 tokens.push_back(tok);
192 }
else if(isalnum(*it) || *it ==
'_') {
194 tok.
data = get_identifier(it);
195 tokens.push_back(tok);
225 fn.
args.emplace_back(
"float",
"x");
226 fn.
args.emplace_back(
"float",
"y");
232 fn.
args.emplace_back(
"float",
"x");
233 fn.
args.emplace_back(
"float",
"y");
234 fn.
args.emplace_back(
"float",
"z");
240 fn.
args.emplace_back(
"float",
"x");
241 fn.
args.emplace_back(
"float",
"y");
242 fn.
args.emplace_back(
"float",
"z");
243 fn.
args.emplace_back(
"float",
"w");
247 std::vector<std::string> vec_types = {
"vec2",
"vec3",
"vec4",
"sampler2D" };
248 std::vector<std::string> vec_and_sample_types = {
"vec2",
"vec3",
"vec4",
"sampler2D" };
250 for(
const auto& it1 : vec_and_sample_types) {
251 for(
const auto& it2 : vec_and_sample_types) {
255 fn.
args.emplace_back(it1,
"x");
256 fn.
args.emplace_back(it2,
"y");
257 fn.
args.emplace_back(
"float",
"weight");
264 for(
const auto& it1 : vec_types) {
266 fn.
args.emplace_back(it1,
"num");
267 fn.
args.emplace_back(it1,
"min");
268 fn.
args.emplace_back(it1,
"max");
274 for(
const auto& it1 : vec_types) {
276 fn.
args.emplace_back(it1,
"x");
277 fn.
args.emplace_back(it1,
"y");
283 for(
const auto& it1 : vec_types) {
285 fn.
args.emplace_back(it1,
"x");
286 fn.
args.emplace_back(it1,
"y");
290 for(
const auto& tok : tokens) {
298 auto it = tokens.begin();
299 std::string end_buffer;
300 int current_line = 1;
307 end_buffer +=
"#" + it->data +
"\r\n";
308 line_numbers.push_back(current_line++);
310 for(
const auto& define : defines) {
311 end_buffer +=
"#define " + define.name +
" " + define.value +
"\r\n";
312 line_numbers.push_back(current_line);
316 bool had_newline =
false;
317 for(; it != tokens.end(); it++) {
323 end_buffer +=
"#" + it->data;
326 line_numbers.push_back(current_line++);
407 end_buffer += it->data;
410 if(it->data ==
"layout")
411 end_buffer += it->data +
" ";
412 else if(it->data ==
"provided")
413 end_buffer +=
"uniform ";
414 else if(it->data ==
"in")
416 else if(it->data ==
"out")
417 end_buffer +=
"out ";
419 end_buffer += it->data +
" ";
void parser()
Parses the current context's tokens and optimizes them.
std::string get_literal(std::string::iterator &it)
std::string get_identifier(std::string::iterator &it)
std::vector< std::pair< std::string, std::string > > args
void debug(const std::string_view category, const std::string_view msg)