]> git.tdb.fi Git - libs/gl.git/blob - source/glsl/builtin.cpp
Mostly cosmetic tweaks
[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 *get_builtins_module()
32 {
33         static RefPtr<Module> builtins_module;
34         static bool initialized = false;
35         if(!initialized)
36         {
37                 initialized = true;
38
39                 Parser parser;
40                 Module *module = new Module(parser.parse(builtins_src, "<builtin>"));
41                 for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
42                 {
43                         VariableResolver().apply(*i);
44                         for(map<string, VariableDeclaration *>::iterator j=i->content.variables.begin(); j!=i->content.variables.end(); ++j)
45                                 j->second->linked_declaration = j->second;
46                 }
47
48                 builtins_module = module;
49         }
50         return builtins_module.get();
51 }
52
53 Stage *get_builtins(Stage::Type type)
54 {
55         Module *module = get_builtins_module();
56         if(!module)
57                 return 0;
58
59         for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
60                 if(i->type==type)
61                         return &*i;
62         return 0;
63 }
64
65 } // namespace SL
66 } // namespace GL
67 } // namespace Msp