]> git.tdb.fi Git - libs/gl.git/blob - source/glsl/generate.h
Split glsl/generate.cpp in two
[libs/gl.git] / source / glsl / generate.h
1 #ifndef MSP_GL_SL_GENERATE_H_
2 #define MSP_GL_SL_GENERATE_H_
3
4 #include <map>
5 #include <set>
6 #include <string>
7 #include <vector>
8 #include "visitor.h"
9
10 namespace Msp {
11 namespace GL {
12 namespace SL {
13
14 /** Manipulates specialization constants.  If values are specified, turns
15 specialization constants into normal constants.  Without values assigns
16 automatic constant_ids to specialization constants. */
17 class ConstantSpecializer: private TraversingVisitor
18 {
19 private:
20         const std::map<std::string, int> *values;
21
22 public:
23         ConstantSpecializer();
24
25         void apply(Stage &, const std::map<std::string, int> *);
26
27 private:
28         virtual void visit(VariableDeclaration &);
29 };
30
31 /** Materializes implicitly declared interfaces.
32
33 Out variable declarations inside functions are moved to the global scope.
34
35 Passthrough statements are processed, generating out variables to match in
36 variables and copying values.
37
38 Unresolved variables are looked up in the previous stage's out variables. */
39 class InterfaceGenerator: private TraversingVisitor
40 {
41 private:
42         Stage *stage;
43         std::string in_prefix;
44         std::string out_prefix;
45         bool function_scope;
46         bool copy_block;
47         std::vector<VariableDeclaration *> declared_inputs;
48         Block *iface_target_block;
49         NodeList<Statement>::iterator iface_insert_point;
50         NodeList<Statement>::iterator assignment_insert_point;
51         std::set<Node *> nodes_to_remove;
52
53 public:
54         InterfaceGenerator();
55
56         void apply(Stage &);
57
58 private:
59         static std::string get_out_prefix(Stage::Type);
60         std::string change_prefix(const std::string &, const std::string &) const;
61         virtual void visit(Block &);
62         VariableDeclaration *generate_interface(VariableDeclaration &, const std::string &, const std::string &);
63         InterfaceBlock *generate_interface(InterfaceBlock &);
64         ExpressionStatement &insert_assignment(const std::string &, Expression *);
65         virtual void visit(VariableReference &);
66         virtual void visit(VariableDeclaration &);
67         virtual void visit(InterfaceBlock &);
68         virtual void visit(FunctionDeclaration &);
69         virtual void visit(Passthrough &);
70 };
71
72 } // namespace SL
73 } // namespace GL
74 } // namespace Msp
75
76 #endif