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