]> git.tdb.fi Git - libs/gl.git/blob - source/glsl/finalize.h
fd29737a713b3ed331e9ba4b0bddb2e13b9f72a6
[libs/gl.git] / source / glsl / finalize.h
1 #ifndef MSP_GL_SL_FINALIZE_H_
2 #define MSP_GL_SL_FINALIZE_H_
3
4 #include <string>
5 #include "visitor.h"
6
7 namespace Msp {
8 namespace GL {
9 namespace SL {
10
11 /** Assigns offset layout qualifiers to struct members. */
12 class StructOrganizer: private TraversingVisitor
13 {
14 private:
15         int offset;
16
17 public:
18         StructOrganizer();
19
20         void apply(Stage &s) { s.content.visit(*this); }
21
22 private:
23         virtual void visit(StructDeclaration &);
24         virtual void visit(VariableDeclaration &);
25 };
26
27 /** Assigns location and binding layout qualifiers to interface variables and
28 blocks. */
29 class LocationAllocator: private TraversingVisitor
30 {
31 private:
32         struct Uniform
33         {
34                 int location;
35                 int desc_set;
36                 int bind_point;
37
38                 Uniform(): location(-1), desc_set(-1), bind_point(-1) { }
39         };
40
41         std::map<std::string, std::set<unsigned> > used_locations;
42         std::map<std::string, Uniform> uniforms;
43         std::map<unsigned, std::set<unsigned> > used_bindings;
44         std::vector<VariableDeclaration *> unplaced_variables;
45         std::vector<VariableDeclaration *> unbound_textures;
46         std::vector<InterfaceBlock *> unbound_blocks;
47
48 public:
49         void apply(Module &, const Features &);
50 private:
51         void apply(Stage &);
52
53         void allocate_locations(const std::string &);
54         void bind_uniform(RefPtr<Layout> &, const std::string &, unsigned);
55         void add_layout_value(RefPtr<Layout> &, const std::string &, unsigned);
56
57         virtual void visit(VariableDeclaration &);
58         virtual void visit(InterfaceBlock &);
59         virtual void visit(FunctionDeclaration &) { }
60 };
61
62 /** Generates default precision declarations or removes precision declarations
63 according to the requirements of the target API. */
64 class PrecisionConverter: private TraversingVisitor
65 {
66 private:
67         Stage *stage;
68         std::set<std::string> have_default;
69         NodeList<Statement>::iterator insert_point;
70         std::set<Node *> nodes_to_remove;
71
72 public:
73         PrecisionConverter();
74
75         void apply(Stage &);
76
77 private:
78         virtual void visit(Block &);
79         virtual void visit(Precision &);
80         virtual void visit(VariableDeclaration &);
81 };
82
83 /** Converts structures of the syntax tree to match a particular set of
84 features. */
85 class LegacyConverter: private TraversingVisitor
86 {
87 private:
88         Stage *stage;
89         Features features;
90         VariableDeclaration *frag_out;
91         NodeList<Statement>::iterator uniform_insert_point;
92         std::set<Node *> nodes_to_remove;
93
94 public:
95         LegacyConverter();
96
97         virtual void apply(Stage &, const Features &);
98
99 private:
100         void unsupported(const std::string &);
101
102         virtual void visit(Block &);
103         bool check_version(const Version &) const;
104         bool check_extension(bool Features::*) const;
105         bool supports_stage(Stage::Type) const;
106         bool supports_unified_interface_syntax() const;
107         virtual void visit(VariableReference &);
108         virtual void visit(Assignment &);
109         bool supports_unified_sampling_functions() const;
110         virtual void visit(FunctionCall &);
111         bool supports_interface_layouts() const;
112         bool supports_stage_interface_layouts() const;
113         bool supports_centroid_sampling() const;
114         bool supports_sample_sampling() const;
115         bool supports_uniform_location() const;
116         bool supports_binding() const;
117         virtual void visit(VariableDeclaration &);
118         bool supports_interface_blocks(const std::string &) const;
119         bool supports_interface_block_location() const;
120         virtual void visit(InterfaceBlock &);
121 };
122
123 } // namespace SL
124 } // namespace GL
125 } // namespace Msp
126
127 #endif