1 #ifndef MSP_GL_SL_COMPILER_H_
2 #define MSP_GL_SL_COMPILER_H_
5 #include <msp/datafile/collection.h>
6 #include <msp/io/base.h>
26 std::vector<std::string> imported_names;
28 std::map<std::string, int> spec_values;
31 /** Creates a compiler using features from the current OpenGL context. */
34 /** Creates a compiler targeting a specific set of features. */
35 Compiler(const Features &);
43 /** Sets the source code to be compiled. Only builtin imports are
45 void set_source(const std::string &, const std::string & = "<string>");
47 /** Loads source code from an I/O object. If a collection is used, imports
48 can be fetched from it. */
49 void load_source(IO::Base &, DataFile::Collection * = 0, const std::string & = "<file>");
51 /** Loads source code from an I/O object. Only builtin imports are
53 void load_source(IO::Base &, const std::string &);
55 /** Specializes the shader. All specialization constants are considered
56 specialized, even if they do not appear in the map. */
57 void specialize(const std::map<std::string, int> &);
59 /** Compiles the shader. */
62 /** Returns combined GLSL source for all shader stages. The result is
63 suitable for feeding back to the compiler. */
64 std::string get_combined_glsl() const;
66 /** Returns a list of compiled stage types. */
67 std::vector<Stage::Type> get_stages() const;
69 /** Returns GLSL source for a single shader stage. The result is standard
70 GLSL suitable for OpenGL or an external GLSL compiler. */
71 std::string get_stage_glsl(Stage::Type) const;
73 /** Returns a map of vertex attribute locations. If the target GLSL version
74 supports interface layouts, the map is empty (locations are included in the
76 const std::map<std::string, unsigned> &get_vertex_attributes() const;
78 /** Returns a map of fragment output locations. If the target GLSL version
79 supports interface layouts, the map is empty (locations are included in the
81 const std::map<std::string, unsigned> &get_fragment_outputs() const;
83 /** Returns the mapping of source indices to filenames. Can be used to
84 translate error messages. */
85 const SourceMap &get_source_map() const;
87 /** Returns a textual representation of the syntax tree for a shader stage.
88 Intended for debugging purposes. */
89 std::string get_stage_debug(Stage::Type) const;
92 /** Appends a module to the target, processing any imports found in it. */
93 void append_module(Module &, DataFile::Collection *);
95 /** Appends a single stage to the matching stage of the target. */
96 void append_stage(Stage &);
98 /// Imports a module by name and appends it to the target. */
99 void import(DataFile::Collection *, const std::string &);
101 /** Generates any implicitly defines syntactic structures and resolves
103 void generate(Stage &, Mode);
105 /** Applies optimizations to a stage. The return value indicates if the
106 preceding stage should be processed again. */
107 bool optimize(Stage &);
109 /** Performs final adjustments on a stage after compilation. */
110 void finalize(Stage &, Mode);
112 static void inject_block(Block &, const Block &);