cgv
Loading...
Searching...
No Matches
shader_code.cxx
1#include <cgv/base/base.h>
2#include "shader_code.h"
3#include <cgv/base/register.h>
4#include <cgv/base/import.h>
6#include <cgv/utils/tokenizer.h>
7#include <cgv/ppp/ph_processor.h>
8#include <cgv/utils/dir.h>
9#include <cgv/utils/file.h>
10#include <cgv/type/variant.h>
11
12#ifdef WIN32
13#pragma warning(disable:4996)
14#endif
15
16using namespace cgv::base;
17using namespace cgv::type;
18using namespace cgv::utils;
19
20namespace cgv {
21 namespace render {
22
23std::map<std::string, std::string> shader_code::code_cache;
24
25std::map<std::string, std::string> shader_code::shader_file_name_map;
26
28
34
36{
37 return "shader_config";
38}
39
42{
43 return
44 rh.reflect_member("shader_path", shader_path) &&
45 rh.reflect_member("show_file_paths", show_file_paths);
46}
47
50{
52 if (!config) {
54 if (getenv("CGV_SHADER_PATH"))
55 config->shader_path = getenv("CGV_SHADER_PATH");
56 else if (getenv("CGV_DIR"))
57 config->shader_path =
58 std::string(getenv("CGV_DIR"))+"/libs/cgv_gl/glsl;"+
59 std::string(getenv("CGV_DIR"))+"/libs/plot/glsl;"+
60 std::string(getenv("CGV_DIR")) + "/libs/cgv_app/glsl;" +
61 std::string(getenv("CGV_DIR")) + "/libs/cgv_g2d/glsl;" +
62 std::string(getenv("CGV_DIR")) + "/libs/cgv_gpgpu/glsl;" +
63 std::string(getenv("CGV_DIR")) + "/libs/holo_disp;" +
64 std::string(getenv("CGV_DIR")) + "/plugins/examples";
65 }
66 return config;
67}
68
69void shader_code::decode_if_base64(std::string& content) {
70//#ifdef _WIN32
71 if (!content.empty()) {
72 // test if the first character is equal to the base64 prefix (ANSI 'paragraph' char with hexcode A7)
73 if(content[0] == char(0xA7))
74 content = decode_base64(content.substr(1));
75 }
76/*#else
77 if (content.size() > 1) {
78 if ((uint8_t&)content[0]==0xC2 && (uint8_t&)content[1]==0xA7) // UTF-8 for 'ยง'
79 content = decode_base64(content.substr(2));
80 else if (
81 content.size() > 2 &&
82 (int)content[0] == -17 &&
83 (int)content[1] == -65 &&
84 (int)content[2] == -67) {
85 content = decode_base64(content.substr(3));
86 }
87 }
88#endif*/
89}
90
93std::string shader_code::get_last_error(const std::string& file_name, const std::string& last_error)
94{
95 std::string fn = shader_code::find_file(file_name);
96 std::vector<line> lines;
98 std::string formated_error;
99 for (unsigned int i = 0; i<lines.size(); ++i) {
100 std::string l = to_string((const token&)(lines[i]));
101 if (to_upper(l.substr(0, 5)) == "ERROR") {
102 std::vector<token> toks;
103 tokenizer(l).set_sep(":").set_ws("").bite_all(toks);
104 formated_error += fn + "(";
105 if (toks.size() > 4) {
106 formated_error += to_string(toks[4])+") : error G0001: ";
107 if (toks.size() > 6)
108 formated_error += l.substr(toks[6].begin-&l[0]);
109 }
110 else {
111 formated_error += "1) : error G0000: ";
112 if (toks.size() > 2)
113 formated_error += l.substr(toks[2].begin-&l[0]);
114 }
115 formated_error += "\n";
116 }
117 else {
118 std::vector<token> toks;
119 tokenizer(l).set_sep(":()").set_ws("").bite_all(toks);
120 unsigned int i, j, k; int n;
121 for (i=0; i<toks.size(); ++i) {
122 if (to_string(toks[i]) == "(")
123 break;
124 }
125 for (j=0; j<toks.size(); ++j) {
126 if (to_string(toks[j]) == ")")
127 break;
128 }
129 for (k=0; k<toks.size(); ++k) {
130 if (to_string(toks[k]) == ":")
131 break;
132 }
133 if (k < toks.size() && i < j && j < k && is_integer(toks[i].end, toks[j].begin, n)) {
134 std::string _fn = fn;
135 int shader_id;
136 if (i > 0 && is_integer(toks[i-1].begin, toks[i-1].end, shader_id)) {
137 if (shader_id >= 1000) {
138 unsigned si = shader_id-1000;
139 if (si < get_shader_config()->inserted_shader_file_names.size())
140 _fn = get_shader_config()->inserted_shader_file_names[si];
141 }
142 else {
143 if ((unsigned)shader_id < get_shader_config()->shader_file_names.size())
144 _fn = get_shader_config()->shader_file_names[shader_id];
145 }
146 }
147 formated_error += _fn + l.substr(toks[i].begin - &l[0])+"\n";
148 }
149 else
150 formated_error += l+"\n";
151 }
152 }
153 return formated_error;
154}
155
158{
159 st = ST_DETECT;
160}
163{
164 if (ctx_ptr && ctx_ptr->make_current())
166 else
167 if (handle)
168 std::cerr << "shader code not destructed correctly" << std::endl;
169}
170
173{
174 if (!handle)
175 return;
176 ctx.shader_code_destruct(*this);
177 handle = 0;
178}
179
180std::string shader_code::find_file(const std::string& file_name, bool search_exhaustive)
181{
182 if (file_name.substr(0, 6) == "str://" || file_name.substr(0, 6) == "res://") {
183 std::map<std::string, resource_file_info>::const_iterator it = ref_resource_file_map().find(file_name.substr(6));
184 if (it != ref_resource_file_map().end())
185 return file_name;
186 else
187 return "";
188 }
189 if (file::exists(file_name))
190 return file_name;
191
192 std::string try_name = file::get_path(ref_prog_name()) + "/" + file_name;
193 if (file::exists(try_name))
194 return try_name;
195
196 std::map<std::string, resource_file_info>::const_iterator it =
197 ref_resource_file_map().find(file_name);
198 if (it != ref_resource_file_map().end()) {
199 if (it->second.file_offset == -1)
200 return std::string("str://") + file_name;
201 else
202 return std::string("res://") + file_name;
203 }
204 if (get_shader_config()->shader_path.empty()) {
205 try_name = std::string("glsl/") + file_name;
206 if (file::exists(try_name))
207 return try_name;
208 try_name = file::get_path(ref_prog_name()) + "/glsl/" + file_name;
209 if (file::exists(try_name))
210 return try_name;
211 return "";
212 }
213
215 std::string path_list = get_shader_config()->shader_path;
216
217 size_t pos = 0;
218 do {
219 size_t end_pos = path_list.find_first_of(';', pos);
220 std::string path;
221 if(end_pos == std::string::npos) {
222 path = path_list.substr(pos);
223 pos = path_list.length();
224 } else {
225 path = path_list.substr(pos, end_pos - pos);
226 pos = end_pos + 1;
227 }
228
229 std::vector<std::string> file_names;
230 dir::glob(path, file_names, "*gl*", true);
231
232 for(const auto& file_name : file_names) {
233 std::string ext = file::get_extension(file_name);
234 if(ext.length() > 2) {
235 if(ext[0] == 'g' && ext[1] == 'l' ||
236 ext[0] == 'p' && ext[1] == 'g' && ext[2] == 'l')
237 shader_file_name_map.emplace(file::get_file_name(file_name), file_name);
238 }
239 }
240 } while(pos < path_list.length());
241
243 }
244
245 std::map<std::string, std::string>::const_iterator file_name_map_it = shader_file_name_map.find(file_name);
247 try_name = file_name_map_it->second;
248 if(file::exists(try_name))
249 return try_name;
250 } else if(!search_exhaustive) {
251 return "";
252 }
253
254 return file::find_in_paths(file_name, get_shader_config()->shader_path, true);
255}
256
257std::string shader_code::retrieve_code(const std::string& file_name, bool use_cache, std::string* _last_error) {
258
259 std::string source = "";
260
261 if(use_cache) {
262 auto it = code_cache.find(file_name);
263 if(it != code_cache.end()) {
264 source = it->second;
265 }
266 } else {
267 code_cache.clear();
268 }
269
270 if(source.empty())
271 source = read_code_file(file_name, _last_error);
272
273 if(use_cache)
274 code_cache.emplace(file_name, source);
275
276 return source;
277}
278
279ShaderType shader_code::detect_shader_type(const std::string& file_name)
280{
281 std::string ext = to_lower(file::get_extension(file_name));
282 ShaderType st = ST_VERTEX;
283 if (ext == "glfs" || ext == "pglfs")
284 st = ST_FRAGMENT;
285 else if (ext == "glgs" || ext == "pglgs")
286 st = ST_GEOMETRY;
287 else if (ext == "glcs" || ext == "pglcs")
288 st = ST_COMPUTE;
289 else if (ext == "gltc" || ext == "pgltc")
290 st = ST_TESS_CONTROL;
291 else if (ext == "glte" || ext == "pglte")
292 st = ST_TESS_EVALUATION;
293 return st;
294}
295
296std::string shader_code::resolve_includes(const std::string& source, bool use_cache, std::set<std::string>& included_file_names, std::string* _last_error)
297{
298 const std::string identifier = "#include ";
299
300 std::string resolved_source = "";
301
302 std::vector<line> lines;
303 split_to_lines(source, lines);
304
305 for(size_t i = 0; i < lines.size(); ++i) {
306 std::string current_line = to_string(lines[i]);
307
308 // search for the include identifier
310 if(identifier_pos != std::string::npos) {
311 // remove identifier and all content before; an include directive must be the first and only statement on a line
312 current_line.erase(0, identifier_pos + identifier.length());
313
314 // trim whitespace
316
317 if(current_line.length() > 0) {
318 // remove quotation marks, leaving only the include path
319 std::string include_file_name = current_line.substr(1, current_line.length() - 2);
321
322 // check whether this file was already included and skip if this is the case
326 } else {
327 current_line = "";
328 }
329 }
330
331 // skip this line if nothing needs to be included (removes the include statement from the code)
332 if(current_line == "")
333 continue;
334 }
335
337 }
338
339 return resolved_source;
340}
341
344{
345 return st;
346}
347
349std::string shader_code::read_code_file(const std::string &file_name, std::string* last_error)
350{
351 std::string source;
352 std::string fn = find_file(file_name);
353 if (fn.empty()) {
354 if (last_error) {
355 *last_error = "could not find shader file ";
356 *last_error += file_name;
357 }
358 return "";
359 }
360 if (!cgv::base::read_data_file(fn, source, true)) {
361 if (last_error) {
362 *last_error = "could not read shader file ";
363 *last_error += fn;
364 }
365 return "";
366 }
367 if (get_shader_config()->show_file_paths)
368 std::cout << "read shader code <" << fn << ">" << std::endl;
369
370 decode_if_base64(source);
371
372 if (file::get_extension(file_name)[0] == 'p') {
373 std::string code;
374 get_shader_config()->inserted_shader_file_names.clear();
375 std::string paths = file::get_path(fn);
376 if (!get_shader_config()->shader_path.empty())
377 paths = paths+";"+get_shader_config()->shader_path;
378
380 php.configure_insert_to_shader(&get_shader_config()->inserted_shader_file_names);
381 if (!php.parse_string(source))
382 return "";
383 if (!php.process_to_string(code))
384 return "";
385 cgv::ppp::clear_variables();
386 source = code;
387 }
388 return source;
389}
390
392bool shader_code::read_code(const context& ctx, const std::string &file_name, ShaderType st, const shader_define_map& defines)
393{
394 if (st == ST_DETECT)
395 st = detect_shader_type(file_name);
396
397 // get source code from cache or read file
398 std::string source = retrieve_code(file_name, ctx.is_shader_file_cache_enabled(), &last_error);
399
400 source = resolve_includes(source, ctx.is_shader_file_cache_enabled());
401
402 if(!defines.empty())
403 set_defines(source, defines);
404
405 if (st == ST_VERTEX && ctx.get_gpu_vendor_id() == GPUVendorID::GPU_VENDOR_AMD)
407
408 if (source.empty())
409 return false;
410
411 return set_code(ctx, source, st);
412}
413
415bool shader_code::set_code(const context& ctx, const std::string &source, ShaderType _st)
416{
417 st = _st;
418 destruct(ctx);
419 ctx_ptr = &ctx;
420 return ctx.shader_code_create(*this, st, source);
421}
422
424void shader_code::set_defines(std::string& source, const shader_define_map& defines)
425{
426 for (const auto &entry : defines) {
427 std::string name = entry.first;
428 std::string value = entry.second;
429
430 if(name.empty())
431 continue;
432
433 size_t define_pos = source.find("#define " + name);
434 if(define_pos == std::string::npos)
435 continue;
436
437 size_t offset = 1;
438 if(source[define_pos + 8 + name.length()] == '\n')
439 offset = 0; // set search offset to zero if define has empty string as default value
440
441 size_t overwrite_pos = define_pos + 8 + name.length() + offset; // length of: #define <NAME><SINGLE_SPACE/NO-SPACE0>
442 std::string first_part = source.substr(0, overwrite_pos);
443 size_t new_line_pos = source.find_first_of('\n', overwrite_pos);
444 if(new_line_pos != std::string::npos) {
445 std::string second_part = source.substr(new_line_pos);
446 source = first_part + (offset == 0 ? " " : "") + value + second_part;
447 source += "";
448 }
449 }
450}
451
454{
455 struct vertex_attribute {
456 token tok;
457 int location = -1;
458 std::string type = "";
459 std::string name = "";
460
461 vertex_attribute(const token& tok) : tok(tok) {}
462
463 std::string to_string() {
464 std::string str = "layout (location = ";
465 str += std::to_string(location);
466 str += ") in ";
467 str += type + " ";
468 str += name + ";";
469 return str;
470 }
471 };
472
473 std::vector<token> parts;
474 std::vector<token> tokens;
475 std::vector<vertex_attribute> attribs;
476 std::vector<bool> attrib_flags;
477 size_t version_idx = 0;
478 int version_number = 0;
479 bool is_core = false;
480 bool no_upgrade = false;
481
482 source = strip_cpp_comments(source);
483
484 split_to_tokens(source, parts, "", true, "", "", ";\n");
485
486 attrib_flags.resize(parts.size(), false);
487
488 size_t part_idx = 0;
489
490 // First read the version. The only thing allowed before the version statement is comments and empty lines.
491 // Both get removed bevore splitting the source into parts, so the first part must be the version.
492 split_to_tokens(parts[part_idx], tokens, "", true, "", "", " \t");
493
494 if(tokens.size() > 1 && tokens[0] == "#version") {
496
497 std::string number_str = to_string(tokens[1]);
498 char* p_end;
499 const long num = std::strtol(number_str.c_str(), &p_end, 10);
500 if(number_str.c_str() != p_end)
501 version_number = static_cast<int>(num);
502
503 if(tokens.size() == 3 && tokens[2] == "core")
504 is_core = true;
505 }
506
507 ++part_idx;
508
509 // Search for the optional NO_UPGRADE define, which must come directly after the version statement.
510 tokens.clear();
511 split_to_tokens(parts[part_idx], tokens, "", true, "", "", " \t");
512
513 if(tokens.size() > 1 && tokens[0] == "#define") {
514 if(tokens[1] == "NO_UPGRADE") {
515 no_upgrade = true;
516 ++part_idx;
517 }
518 }
519
520 // return if the shader should not be upgraded
521 if(no_upgrade)
522 return;
523
524 // now get all vertex attributes
525 for(; part_idx < parts.size(); ++part_idx) {
526 auto& tok = parts[part_idx];
527
528 while(tok.begin < tok.end && is_space(*tok.begin))
529 ++tok.begin;
530
531 if(tok.size() > 2) {
532 int parentheses_count = 0;
533 bool is_new_word = true;
534 bool was_new_word = true;
535
536 for(unsigned i = 0; i < tok.size() - 2; ++i) {
537 char c = tok[i];
538
539 if(c == '(')
541
542 if(c == ')')
544
545 is_new_word = is_space(c) || c == ')';
546
547 if(c == 'i' && tok[i + 1] == 'n' && tok[i + 2] == ' ') {
548 if(was_new_word && parentheses_count == 0) {
549 attribs.push_back(vertex_attribute(tok));
550 attrib_flags[part_idx] = true;
551 break;
552 }
553 }
554
556 }
557 }
558 }
559
560 // return if no vertex attributes were found
561 if(attribs.size() == 0)
562 return;
563
564 int max_location = -1;
565 for(size_t i = 0; i < attribs.size(); ++i) {
566 auto& attrib = attribs[i];
567
568 tokens.clear();
569 split_to_tokens(attrib.tok, tokens, "", true, "", "", " \t()");
570
571 size_t size = tokens.size();
572
573 if(tokens.size() > 2) {
574 // last two entries must be type and name
575 attrib.type = to_string(tokens[size - 2]);
576 attrib.name = to_string(tokens[size - 1]);
577
578 // find location if present
579 size_t equals_idx = -1;
580 for(size_t j = 0; j < size; ++j) {
581 auto& tok = tokens[j];
582 if(tok.size() == 1 && tok[0] == '=')
583 equals_idx = j;
584 }
585
586 if(equals_idx != -1 && equals_idx > 0 && equals_idx < size - 1) {
587 if(to_string(tokens[equals_idx - 1]) == "location") {
588 std::string val_str = to_string(tokens[equals_idx + 1]);
589 char* p_end;
590 const long num = std::strtol(val_str.c_str(), &p_end, 10);
591 if(val_str.c_str() != p_end) {
592 attrib.location = static_cast<int>(num);
593 max_location = std::max(max_location, attrib.location);
594 }
595 }
596 }
597 }
598 }
599
600 for(size_t i = 0; i < attribs.size(); ++i) {
601 auto& attrib = attribs[i];
602 if(attrib.location < 0)
603 attrib.location = ++max_location;
604 }
605
606 size_t attrib_idx = 0;
607 size_t accumulate_offset = 0;
608 size_t content_offset = reinterpret_cast<size_t>(source.data());
609
610 for(size_t i = 0; i < parts.size(); ++i) {
611 auto& tok = parts[i];
612
613 if(i == version_idx || attrib_flags[i]) {
614 size_t token_begin = reinterpret_cast<size_t>(tok.begin);
615 size_t token_end = reinterpret_cast<size_t>(tok.end);
616
617 size_t offset = token_begin - content_offset;
618 size_t length = token_end - token_begin;
619
620 std::string str = "";
621
622 if(attrib_flags[i]) {
623 auto& attrib = attribs[attrib_idx];
624 ++attrib_idx;
625 str = attrib.to_string() + "\n";
626 } else {
627 version_number = std::max(version_number, 330);
628 str = "#version " + std::to_string(version_number) + (is_core ? " core" : "");
629 }
630
631 offset += accumulate_offset;
632 accumulate_offset += str.length() - length - 1;
633
634 std::string first_part = source.substr(0, offset);
635 std::string second_part = source.substr(offset + length + 1);
636
637 source = first_part + str + second_part;
638 }
639 }
640}
641
644{
645 if (!ctx.shader_code_compile(*this)) {
646 user_data = 0;
647 return false;
648 }
649 int id = 1;
650 user_data = (void*&) id;
651 return true;
652}
653
655bool shader_code::read_and_compile(const context& ctx, const std::string &file_name, ShaderType st, bool show_error, const shader_define_map& defines)
656{
657 if (!read_code(ctx,file_name,st,defines))
658 return false;
659
660 if (!compile(ctx)) {
661 if (show_error)
662 std::cerr << get_last_error(file_name, last_error).c_str() << std::endl;
663 return false;
664 }
665
666 return true;
667}
668
671{
672 return user_data != 0;
673}
674
675
676 }
677}
678
680{
682 {
683 register_object(cgv::render::get_shader_config(), "register global shader config");
684 }
685};
686
687shader_config_registration shader_config_registration_instance;
More advanced text processing for splitting text into lines or tokens.
virtual bool end()
perform the leave part of the action on the current object
Definition action.cxx:48
complete implementation of method actions that only call one method when entering a node
Definition action.h:113
bool begin()
uses call_method of base class method_action to call the method refered to by the stored method point...
Definition action.h:122
reference counted pointer, which can work together with types that are derived from ref_counted,...
Definition ref_ptr.h:160
bool empty() const
check if pointer is not yet set
Definition ref_ptr.h:230
the pre header processor parses a pre header file and converts it to a header file or uses the inform...
the self reflection handler is passed to the virtual self_reflect() method of cgv::base::base.
bool reflect_member(const std::string &member_name, T &member_ref, bool hard_cast=false)
call this to reflect a member by member name and reference to the member.
base class for all drawables, which is independent of the used rendering API.
Definition context.h:621
virtual GPUVendorID get_gpu_vendor_id() const
device information
Definition context.cxx:230
bool is_shader_file_cache_enabled() const
whether the shader file caches are enabled
Definition context.cxx:463
const context * ctx_ptr
keep pointer to my context
Definition context.h:307
std::string last_error
a string that contains the last error
Definition context.h:309
static bool shader_file_name_map_initialized
whether the shader file name map is initialized
Definition shader_code.h:94
static std::string find_file(const std::string &file_name, bool search_exhaustive=false)
Find the full path to a shader by its file name.
shader_code()
create shader a shader code object
static std::string read_code_file(const std::string &file_name, std::string *_last_error=0)
read shader code from file and return string with content or empty string if read failed
static std::map< std::string, std::string > code_cache
map that caches shader file contents indexed by their file name
Definition shader_code.h:96
bool read_code(const context &ctx, const std::string &file_name, ShaderType st=ST_DETECT, const shader_define_map &defines=shader_define_map())
read shader code from file that is searched for with find_file.
ShaderType get_shader_type() const
return the shader type of this code
void set_defines(std::string &source, const shader_define_map &defines)
set shader code defines
static std::string resolve_includes(const std::string &source, bool use_cache, std::set< std::string > &included_file_names, std::string *_last_error=0)
search for include directives in the given source code, replace them by the included file contents an...
bool is_compiled() const
return whether shader has been compiled successfully
void destruct(const context &ctx)
destruct shader code
~shader_code()
calls the destruct method
static void decode_if_base64(std::string &content)
decode a string if it is base64 encoded
static std::string retrieve_code(const std::string &file_name, bool use_cache, std::string *_last_error)
retreive shader code either by reading the file from disk or from the cache if enabled
ShaderType st
store the shader type
Definition shader_code.h:99
static std::string get_last_error(const std::string &file_name, const std::string &last_error)
format given last error in a way that developer environments can locate errors in the source file
static std::map< std::string, std::string > shader_file_name_map
map that caches full shader file paths indexed by the shader file name
Definition shader_code.h:92
bool compile(const context &ctx)
compile attached source; returns true if successful
bool set_code(const context &ctx, const std::string &source, ShaderType st)
set shader code from string
void set_vertex_attrib_locations(std::string &source)
set shader code vertex attribute locations (a hotfix for AMD driver behaviour on vertex shaders)
bool read_and_compile(const context &ctx, const std::string &file_name, ShaderType st=ST_DETECT, bool show_error=true, const shader_define_map &defines=shader_define_map())
read shader code with read_code and compile.
static ShaderType detect_shader_type(const std::string &file_name)
detect the shader type from the extension of the given file_name, i.e.
the tokenizer allows to split text into tokens in a convenient way.
Definition tokenizer.h:68
tokenizer & set_sep(const std::string &sep, bool merge)
set the list of separators and specify whether succeeding separators are merged into single tokens
Definition tokenizer.cxx:59
tokenizer & set_ws(const std::string &ws)
set the list of white spaces, that separate tokens and are skipped
Definition tokenizer.cxx:38
the base namespace holds the base hierarchy, support for plugin registration and signals
Definition action.cxx:4
bool read_data_file(const std::string &file_name, std::string &content, bool ascii)
read ascii file into a string
Definition import.cxx:388
std::map< std::string, resource_file_info > & ref_resource_file_map()
return a reference to a mapping of resource file names to resource file infos
Definition register.cxx:143
void register_object(base_ptr object, const std::string &options)
register an object and send event to all current registration ref_listeners()
Definition register.cxx:581
std::string & ref_prog_name()
return a refence to the name of the started executable
Definition register.cxx:125
std::map< std::string, std::string > shader_define_map
typedef for shader define map data structure
Definition shader_code.h:52
shader_config_ptr get_shader_config()
return a reference to the current shader configuration
cgv::data::ref_ptr< shader_config > shader_config_ptr
type of ref counted pointer to shader configuration
Definition shader_code.h:46
ShaderType
different shader types
Definition context.h:485
namespace for compile time type information
namespace that holds tools that dont fit any other namespace
void split_to_tokens(const char *begin, const char *end, std::vector< token > &tokens, const std::string &separators, bool merge_separators, const std::string &open_parenthesis, const std::string &close_parenthesis, const std::string &whitespaces, unsigned int max_nr_tokens)
this function splits a text range into tokens.
std::string to_string(const std::string &v, unsigned int w, unsigned int p, bool)
specialization of conversion from string to strings
bool is_integer(const char *begin, const char *end, int &value)
check if the text range (begin,end( defines an integer value. If yes, store the value in the passed r...
Definition scan.cxx:367
std::string & trim(std::string &str, const std::string &chars)
trim white space or other characters from start and end of string
Definition scan.cxx:709
void split_to_lines(const char *global_begin, const char *global_end, std::vector< line > &lines, bool truncate_trailing_spaces)
this function splits a text range at the newline characters into single lines.
char to_lower(char c)
convert char to lower case
Definition scan.cxx:39
char to_upper(char c)
convert char to upper case
Definition scan.cxx:106
bool is_space(char c)
check if char is a whitespace
Definition scan.cxx:12
std::string decode_base64(std::string const &encoded_string)
decode a base64 encoded string
Definition convert.cxx:105
std::string strip_cpp_comments(const std::string &source, bool correct_new_lines)
remove cpp-style comments from string
the cgv namespace
Definition print.h:11
a globally unique shader config is registered by default when the cgv library is used.
Definition shader_code.h:26
std::string get_type_name() const
return "shader_config"
bool show_file_paths
whether to output full paths of read shaders
Definition shader_code.h:32
shader_config()
construct config without file name tracing
bool trace_file_names
whether to keep track of file names
Definition shader_code.h:30
bool self_reflect(cgv::reflect::reflection_handler &srh)
reflect the shader_path member
std::string shader_path
the path used to find shaders with the cgv::utils::file::find_in_paths function
Definition shader_code.h:28
representation of a token in a text by two pointers begin and end, that point to the first character ...
Definition token.h:18