1 #ifndef MSP_GL_PROGRAMBUILDER_H_
2 #define MSP_GL_PROGRAMBUILDER_H_
7 #include <msp/datafile/objectloader.h>
14 class invalid_variable_definition: public std::invalid_argument
17 invalid_variable_definition(const std::string &w): std::invalid_argument(w) { }
18 virtual ~invalid_variable_definition() throw() { }
22 Generates shaders with common features.
28 Describes the features of a standard shader program.
30 struct StandardFeatures
32 class Loader: public DataFile::ObjectLoader<StandardFeatures>
35 Loader(StandardFeatures &);
52 std::string create_flags() const;
70 PASSTHROUGH = INPUT|OUTPUT,
74 struct VariableDefinition
79 const char *expression;
86 const VariableDefinition *variable;
87 std::string resolved_name;
89 std::string resolved_space;
91 std::string array_subscript;
93 std::list<ShaderVariable *> referenced_vars;
94 std::list<ShaderVariable *> referenced_by;
99 ShaderVariable(const std::string &);
101 void resolve(const VariableDefinition &);
102 void resolve(ShaderVariable &);
103 void resolve_space(const std::string &);
104 void resolve_array(const StandardFeatures &, unsigned = 0);
105 void add_reference(ShaderVariable &);
106 void update_reference(ShaderVariable &, ShaderVariable &);
107 void check_inline(bool, bool);
108 bool is_referenced_from(VariableScope) const;
109 InterfaceFlags get_interface_flags(VariableScope) const;
110 std::string create_declaration(char = 0, bool = false) const;
111 std::string create_replacement(VariableScope, const char * = 0) const;
112 std::string create_expression(const char * = 0) const;
123 StandardFeatures features;
124 std::list<VariableDefinition> custom_variables;
125 std::string feature_flags;
128 static const VariableDefinition standard_variables[];
129 static const char interfaces[];
132 ProgramBuilder(const StandardFeatures &);
134 void set_optimize(bool);
135 Program *create_program() const;
136 void add_shaders(Program &) const;
138 std::string create_source(const std::list<ShaderVariable *> &, VariableScope) const;
139 bool evaluate_flags(const char *) const;
140 static MatchType name_match(const char *, const char *, const char ** = 0);
141 static bool parse_identifier(const char *, unsigned &, unsigned &);
142 static std::vector<std::string> extract_identifiers(const char *);
143 static std::string replace_identifiers(const char *, const std::map<std::string, std::string> &);