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>
35 RESOLVE_VARIABLES = 4,
36 RESOLVE_EXPRESSIONS = 8,
37 RESOLVE_FUNCTIONS = 16,
43 std::vector<std::string> imported_names;
46 std::map<std::string, int> spec_values;
49 /** Creates a compiler using features from the current OpenGL context. */
52 /** Creates a compiler targeting a specific set of features. */
53 Compiler(const Features &);
61 /** Sets the source code to be compiled. Only builtin imports are
63 void set_source(const std::string &, const std::string & = "<string>");
65 /** Loads source code from an I/O object. If a collection is used, imports
66 can be fetched from it. */
67 void load_source(IO::Base &, DataFile::Collection * = 0, const std::string & = "<file>");
69 /** Loads source code from an I/O object. Only builtin imports are
71 void load_source(IO::Base &, const std::string &);
73 /** Specializes the shader. All specialization constants are considered
74 specialized, even if they do not appear in the map. */
75 void specialize(const std::map<std::string, int> &);
77 /** Compiles the shader. */
80 /** Returns combined GLSL source for all shader stages. The result is
81 suitable for feeding back to the compiler. */
82 std::string get_combined_glsl() const;
84 /** Returns a list of compiled stage types. */
85 std::vector<Stage::Type> get_stages() const;
87 /** Returns GLSL source for a single shader stage. The result is standard
88 GLSL suitable for OpenGL or an external GLSL compiler. */
89 std::string get_stage_glsl(Stage::Type) const;
91 /** Returns a map of vertex attribute locations. If the target GLSL version
92 supports interface layouts, the map is empty (locations are included in the
94 const std::map<std::string, unsigned> &get_vertex_attributes() const;
96 /** Returns a map of fragment output locations. If the target GLSL version
97 supports interface layouts, the map is empty (locations are included in the
99 const std::map<std::string, unsigned> &get_fragment_outputs() const;
101 /** Returns the mapping of source indices to filenames. Can be used to
102 translate error messages. */
103 const SourceMap &get_source_map() const;
105 /** Returns a textual representation of the syntax tree for a shader stage.
106 Intended for debugging purposes. */
107 std::string get_stage_debug(Stage::Type) const;
109 /** Returns diagnostics from compilation. The output is intended to be
111 std::string get_diagnostics() const;
114 /** Appends a module to the target, processing any imports found in it. */
115 void append_module(Module &, DataFile::Collection *);
117 /** Appends a single stage to the matching stage of the target. */
118 void append_stage(Stage &);
120 /// Imports a module by name and appends it to the target. */
121 void import(DataFile::Collection *, const std::string &);
123 /** Generates any implicitly defines syntactic structures and resolves
125 void generate(Stage &);
128 bool resolve(Stage &, unsigned &, unsigned);
130 /** Resolves various references between nodes. Flags can be specified to
131 request resolving particular aspects. Resolving may ripple into other
132 aspects as necessary. */
133 void resolve(Stage &, unsigned = RESOLVE_ALL);
135 /** Checks the validity of the module. If the return value is false, the
136 module's diagnostics list will contain additional information of errors. */
137 bool validate(Stage &);
139 static bool diagnostic_line_order(const Diagnostic &, const Diagnostic &);
141 /** Applies optimizations to a stage. The return value indicates which
142 stage should be optimized next. */
143 OptimizeResult optimize(Stage &);
145 /** Performs final adjustments on a stage after compilation. */
146 void finalize(Stage &, Mode);
148 static void inject_block(Block &, const Block &);