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;
71 PASSTHROUGH = INPUT|OUTPUT,
75 struct VariableDefinition
80 const char *expression;
87 const VariableDefinition *variable;
88 const VariableDefinition *type;
89 std::string resolved_name;
90 std::string resolved_block;
92 std::string resolved_space;
94 std::string array_subscript;
96 std::list<ShaderVariable *> referenced_vars;
97 std::list<ShaderVariable *> referenced_by;
102 ShaderVariable(const std::string &);
104 void resolve(const VariableDefinition &);
105 void resolve(ShaderVariable &);
106 void resolve_type(const VariableDefinition &);
107 void resolve_space(const std::string &);
108 void resolve_array(const StandardFeatures &, unsigned = 0);
109 void add_reference(ShaderVariable &);
110 void update_reference(ShaderVariable &, ShaderVariable &);
111 void check_inline(bool, bool);
112 bool is_referenced_from(VariableScope) const;
113 InterfaceFlags get_interface_flags(VariableScope) const;
114 std::string create_type_declaration() const;
115 std::string create_declaration(char = 0, bool = false) const;
116 std::string create_replacement(VariableScope, const char * = 0) const;
117 std::string create_expression(const char * = 0) const;
128 StandardFeatures features;
129 std::list<VariableDefinition> custom_variables;
130 std::string feature_flags;
133 static const VariableDefinition standard_variables[];
134 static const char interfaces[];
137 ProgramBuilder(const StandardFeatures &);
139 void set_optimize(bool);
140 Program *create_program() const;
141 void add_shaders(Program &) const;
143 std::string create_source(const std::list<ShaderVariable *> &, VariableScope) const;
144 bool evaluate_flags(const char *) const;
145 static const char *unqualified_name(const char *);
146 static MatchType name_match(const char *, const char *, const char ** = 0);
147 static bool parse_identifier(const char *, unsigned &, unsigned &);
148 static std::vector<std::string> extract_identifiers(const char *);
149 static std::string replace_identifiers(const char *, const std::map<std::string, std::string> &);