]> git.tdb.fi Git - libs/gl.git/blob - source/glsl/builtin.cpp
Move the StageType enum inside the Stage struct
[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 resolver;
38                 i->content.visit(resolver);
39                 for(map<string, VariableDeclaration *>::iterator j=i->content.variables.begin(); j!=i->content.variables.end(); ++j)
40                         j->second->linked_declaration = j->second;
41         }
42         return module;
43 }
44
45 Module &get_builtins_module()
46 {
47         static RefPtr<Module> builtins_module = create_builtins_module();
48         return *builtins_module;
49 }
50
51 Stage *get_builtins(Stage::Type type)
52 {
53         Module &module = get_builtins_module();
54         for(list<Stage>::iterator i=module.stages.begin(); i!=module.stages.end(); ++i)
55                 if(i->type==type)
56                         return &*i;
57         return 0;
58 }
59
60 } // namespace SL
61 } // namespace GL
62 } // namespace Msp