X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fprogrambuilder.h;h=678ee2ca142d9b31e264d2abad9d33ef9fbb31d2;hb=a1eb8711ba225bb4423868c50369ad5592465171;hp=82a954b58b481faf4809cac719baa3aa1c48079a;hpb=83bfb4bc26cf20cada1fcda47064b75d8e49fa08;p=libs%2Fgl.git diff --git a/source/programbuilder.h b/source/programbuilder.h index 82a954b5..678ee2ca 100644 --- a/source/programbuilder.h +++ b/source/programbuilder.h @@ -11,9 +11,22 @@ namespace GL { class Program; +class invalid_variable_definition: public std::invalid_argument +{ +public: + invalid_variable_definition(const std::string &w): std::invalid_argument(w) { } + virtual ~invalid_variable_definition() throw() { } +}; + +/** +Generates shaders with common features. +*/ class ProgramBuilder { public: + /** + Describes the features of a standard shader program. + */ struct StandardFeatures { class Loader: public DataFile::ObjectLoader @@ -25,17 +38,20 @@ public: bool texture; bool material; bool lighting; + unsigned max_lights; bool specular; bool normalmap; bool shadow; bool reflection; - bool transform; + bool legacy; + std::string custom; StandardFeatures(); std::string create_flags() const; }; +private: enum VariableScope { NO_SCOPE, @@ -45,8 +61,16 @@ public: FRAGMENT }; -private: - struct StandardVariable + enum InterfaceFlags + { + NO_INTERFACE = 0, + INPUT = 1, + OUTPUT = 2, + PASSTHROUGH = INPUT|OUTPUT, + GOAL = 4 + }; + + struct VariableDefinition { VariableScope scope; const char *name; @@ -58,39 +82,50 @@ private: struct ShaderVariable { std::string name; - const StandardVariable *variable; + const VariableDefinition *variable; std::string resolved_name; bool fuzzy_space; std::string resolved_space; + bool array_sum; + std::string array_subscript; + unsigned array_size; std::list referenced_vars; std::list referenced_by; bool inlined; bool inline_parens; + bool in_loop; ShaderVariable(const std::string &); - void resolve(const StandardVariable &); + void resolve(const VariableDefinition &); void resolve(ShaderVariable &); void resolve_space(const std::string &); + void resolve_array(const StandardFeatures &, unsigned = 0); void add_reference(ShaderVariable &); void update_reference(ShaderVariable &, ShaderVariable &); - void check_inline(); + void check_inline(bool, bool); bool is_referenced_from(VariableScope) const; - std::string get_expression() const; + InterfaceFlags get_interface_flags(VariableScope) const; + std::string create_declaration(char = 0, bool = false) const; + std::string create_replacement(VariableScope, const char * = 0) const; + std::string create_expression(const char * = 0) const; }; - enum MatchLevel + enum MatchType { NO_MATCH, EXACT, - FUZZY + FUZZY, + ARRAY }; StandardFeatures features; + std::list custom_variables; std::string feature_flags; bool optimize; - static const StandardVariable standard_variables[]; + static const VariableDefinition standard_variables[]; + static const char interfaces[]; public: ProgramBuilder(const StandardFeatures &); @@ -101,7 +136,7 @@ public: private: std::string create_source(const std::list &, VariableScope) const; bool evaluate_flags(const char *) const; - static MatchLevel name_match(const char *, const char *, const char ** = 0); + static MatchType name_match(const char *, const char *, const char ** = 0); static bool parse_identifier(const char *, unsigned &, unsigned &); static std::vector extract_identifiers(const char *); static std::string replace_identifiers(const char *, const std::map &);