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