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