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