]> git.tdb.fi Git - libs/gl.git/blob - source/glsl/builtin.cpp
Refactor the way of applying visitors to stages
[libs/gl.git] / source / glsl / builtin.cpp
1 #include "builtin.h"
2 #include "generate.h"
3 #include "parser.h"
4
5 using namespace std;
6
7 namespace {
8
9 const char builtins_src[] =
10         "#pragma MSP stage(vertex)\n"
11         "out gl_PerVertex {\n"
12         "  vec4 gl_Position;\n"
13         "  float gl_ClipDistance[];\n"
14         "};\n"
15         "#pragma MSP stage(geometry)\n"
16         "in gl_PerVertex {\n"
17         "  vec4 gl_Position;\n"
18         "  float gl_ClipDistance[];\n"
19         "} gl_in[];\n"
20         "out gl_PerVertex {\n"
21         "  vec4 gl_Position;\n"
22         "  float gl_ClipDistance[];\n"
23         "};\n";
24
25 }
26
27 namespace Msp {
28 namespace GL {
29 namespace SL {
30
31 Module *create_builtins_module()
32 {
33         Parser parser;
34         Module *module = new Module(parser.parse(builtins_src, "<builtin>"));
35         for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
36         {
37                 VariableResolver().visit(i->content);
38                 for(map<string, VariableDeclaration *>::iterator j=i->content.variables.begin(); j!=i->content.variables.end(); ++j)
39                         j->second->linked_declaration = j->second;
40         }
41         return module;
42 }
43
44 Module &get_builtins_module()
45 {
46         static RefPtr<Module> builtins_module = create_builtins_module();
47         return *builtins_module;
48 }
49
50 Stage *get_builtins(Stage::Type type)
51 {
52         Module &module = get_builtins_module();
53         for(list<Stage>::iterator i=module.stages.begin(); i!=module.stages.end(); ++i)
54                 if(i->type==type)
55                         return &*i;
56         return 0;
57 }
58
59 } // namespace SL
60 } // namespace GL
61 } // namespace Msp