]> git.tdb.fi Git - libs/gl.git/blob - source/glsl/compiler.h
Support specialization constants in the GLSL compiler
[libs/gl.git] / source / glsl / compiler.h
1 #ifndef MSP_GL_SL_COMPILER_H_
2 #define MSP_GL_SL_COMPILER_H_
3
4 #include <vector>
5 #include <msp/datafile/collection.h>
6 #include <msp/io/base.h>
7 #include "parser.h"
8 #include "syntax.h"
9
10 namespace Msp {
11 namespace GL {
12 namespace SL {
13
14 class Compiler
15 {
16 public:
17         enum Mode
18         {
19                 MODULE,
20                 PROGRAM
21         };
22
23 private:
24         Features features;
25         Module *module;
26         std::vector<std::string> imported_names;
27         bool specialized;
28         std::map<std::string, int> spec_values;
29
30 public:
31         Compiler();
32         Compiler(const Features &);
33         ~Compiler();
34
35 private:
36         void clear();
37 public:
38         void set_source(const std::string &, const std::string & = "<string>");
39         void load_source(IO::Base &, DataFile::Collection * = 0, const std::string & = "<file>");
40         void load_source(IO::Base &, const std::string &);
41         void specialize(const std::map<std::string, int> &);
42         void compile(Mode);
43
44         std::string get_combined_glsl() const;
45         std::vector<Stage::Type> get_stages() const;
46         std::string get_stage_glsl(Stage::Type) const;
47         const std::map<std::string, unsigned> &get_vertex_attributes() const;
48         const std::map<std::string, unsigned> &get_fragment_outputs() const;
49         const SourceMap &get_source_map() const;
50
51         std::string get_stage_debug(Stage::Type) const;
52
53 private:
54         void append_module(Module &, DataFile::Collection *);
55         void append_stage(Stage &);
56         void import(DataFile::Collection *, const std::string &);
57         void generate(Stage &, Mode);
58         bool optimize(Stage &);
59         void finalize(Stage &, Mode);
60         static void inject_block(Block &, const Block &);
61 };
62
63 } // namespace SL
64 } // namespace GL
65 } // namespace Msp
66
67 #endif