]> git.tdb.fi Git - libs/gl.git/blob - source/glsl/compiler.h
Reduce coupling between the GLSL compiler and the graphics engine
[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
28 public:
29         Compiler();
30         Compiler(const Features &);
31         ~Compiler();
32
33 private:
34         void clear();
35 public:
36         void set_source(const std::string &, const std::string & = "<string>");
37         void load_source(IO::Base &, DataFile::Collection * = 0, const std::string & = "<file>");
38         void load_source(IO::Base &, const std::string &);
39         void compile(Mode);
40
41         std::string get_combined_glsl() const;
42         std::vector<Stage::Type> get_stages() const;
43         std::string get_stage_glsl(Stage::Type) const;
44         const std::map<std::string, unsigned> &get_vertex_attributes() const;
45         const std::map<std::string, unsigned> &get_fragment_outputs() const;
46         const SourceMap &get_source_map() const;
47 private:
48
49         void append_module(Module &, DataFile::Collection *);
50         void append_stage(Stage &);
51         void import(DataFile::Collection *, const std::string &);
52         void generate(Stage &, Mode);
53         bool optimize(Stage &);
54         void finalize(Stage &, Mode);
55         static void inject_block(Block &, const Block &);
56 };
57
58 } // namespace SL
59 } // namespace GL
60 } // namespace Msp
61
62 #endif