]> git.tdb.fi Git - libs/gl.git/blob - source/glsl/generate.h
eb7d488ae6071faa619f3e374c61084686e028b9
[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 /** Assigns IDs to specialization constants with an automatic ID. */
15 class ConstantIdAssigner: private TraversingVisitor
16 {
17 private:
18         std::set<unsigned> used_ids;
19         std::vector<VariableDeclaration *> auto_constants;
20
21 public:
22         void apply(Module &, const Features &);
23
24 private:
25         virtual void visit(VariableDeclaration &);
26 };
27
28 /** Materializes implicitly declared interfaces.
29
30 Out variable declarations inside functions are moved to the global scope.
31
32 Passthrough statements are processed, generating out variables to match in
33 variables and copying values.
34
35 Unresolved variables are looked up in the previous stage's out variables. */
36 class InterfaceGenerator: private TraversingVisitor
37 {
38 private:
39         Stage *stage;
40         std::string in_prefix;
41         std::string out_prefix;
42         bool function_scope;
43         bool copy_block;
44         std::vector<VariableDeclaration *> declared_inputs;
45         Block *iface_target_block;
46         NodeList<Statement>::iterator iface_insert_point;
47         NodeList<Statement>::iterator assignment_insert_point;
48         std::set<Node *> nodes_to_remove;
49
50 public:
51         InterfaceGenerator();
52
53         void apply(Stage &);
54
55 private:
56         static std::string get_out_prefix(Stage::Type);
57         std::string change_prefix(const std::string &, const std::string &) const;
58         virtual void visit(Block &);
59         VariableDeclaration *generate_interface(VariableDeclaration &, const std::string &, const std::string &);
60         InterfaceBlock *generate_interface(InterfaceBlock &);
61         ExpressionStatement &insert_assignment(const std::string &, Expression *);
62         virtual void visit(VariableReference &);
63         virtual void visit(VariableDeclaration &);
64         virtual void visit(InterfaceBlock &);
65         virtual void visit(FunctionDeclaration &);
66         virtual void visit(Passthrough &);
67 };
68
69 } // namespace SL
70 } // namespace GL
71 } // namespace Msp
72
73 #endif