X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fprogrambuilder.h;h=0883f6a74fd07a6479dc1b01fa62424882455042;hb=4d7f66ea28c788e12f700216b9c53af9e71b8390;hp=821907d5dba46a281323c3364e1b85095426296e;hpb=cb2281586d0202dfe2c8c181afc9cbf1d250cf25;p=libs%2Fgl.git diff --git a/source/programbuilder.h b/source/programbuilder.h index 821907d5..0883f6a7 100644 --- a/source/programbuilder.h +++ b/source/programbuilder.h @@ -18,9 +18,15 @@ public: 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 @@ -32,6 +38,8 @@ public: bool texture; bool material; bool lighting; + unsigned max_lights; + bool skylight; bool specular; bool normalmap; bool shadow; @@ -54,6 +62,15 @@ private: FRAGMENT }; + enum InterfaceFlags + { + NO_INTERFACE = 0, + INPUT = 1, + OUTPUT = 2, + PASSTHROUGH = INPUT|OUTPUT, + GOAL = 4 + }; + struct VariableDefinition { VariableScope scope; @@ -70,30 +87,37 @@ private: 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 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(bool, bool); bool is_referenced_from(VariableScope) const; - std::string create_declaration(char = 0) const; - std::string create_replacement(VariableScope) const; - std::string create_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; @@ -102,6 +126,7 @@ private: bool optimize; static const VariableDefinition standard_variables[]; + static const char interfaces[]; public: ProgramBuilder(const StandardFeatures &); @@ -112,7 +137,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 &);