22#include < types/type_mapper.h>
33#include < array>
44#include < stdexcept>
5+ #include < shaders/embedded_shaders.h>
56
67string get_source (const string& filename) {
8+ static std::map<string, string&> known_files = {
9+ {" shaders/plotter.frag" ,SRC_PLOTTER_FRAG },
10+ {" shaders/plotter.vert" ,SRC_PLOTTER_VERT },
11+ {" shaders/plotter3d.frag" ,SRC_PLOTTER3D_FRAG },
12+ {" shaders/plotter3d.vert" ,SRC_PLOTTER3D_VERT }
13+ };
14+ const auto it = known_files.find (filename);
15+ if (it != known_files.end ()) {
16+ return it->second ;
17+ }
18+
19+
720 std::ifstream file (filename);
821 if (!file.is_open ()) {
922 throw std::runtime_error (" Could not open source file '" + filename + " '" );
@@ -14,7 +27,28 @@ string get_source(const string& filename) {
1427}
1528
1629
17- void preprocess (const string& filename, const vector<TokenOperator>& operators) {
30+ void preprocess_string (const string& filename, const vector<TokenOperator>& operators) {
31+ string preprocessed_string = get_preprocessor_string (operators);
32+ string raw_source = get_source (filename);
33+ initialize_map_id ();
34+ const string marker = " START_WRITING_HERE HERE" ;
35+ size_t start_pos = raw_source.find (marker) + marker.length ();
36+ if (start_pos == string::npos) {
37+ std::cerr << " Marker does not exist" ;
38+ return ;
39+ }
40+ raw_source.insert (start_pos, " \n " + preprocessed_string + " \n " );
41+ if (filename == " shaders/plotter.frag" ) {
42+ SRC_PLOTTER_FRAG = raw_source;
43+ }
44+ if (filename == " shaders/plotter.vert" ) SRC_PLOTTER_VERT = raw_source;
45+ if (filename == " shaders/plotter3d.vert" ) SRC_PLOTTER3D_VERT = raw_source;
46+ if (filename == " shaders/plotter3d.frag" ) SRC_PLOTTER3D_FRAG = raw_source;
47+ std::cout << raw_source;
48+ return ;
49+ }
50+
51+ void preprocess_file (const string& filename, const vector<TokenOperator>& operators) {
1852 string preprocessed_string = get_preprocessor_string (operators);
1953 initialize_map_id ();
2054 string raw_source = get_source (filename);
0 commit comments