X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fprogrambuilder.h;h=9ca9c8539b54c1046a2d97b29e7b854506c128d2;hb=2e9d7c9f5741d17f77ce27273590ee16b791fb64;hp=69170e02ef979f543b16f1fc53ef0c9adbc0c2d1;hpb=d542522823423f9ed2a5d412de9250ee8367334b;p=libs%2Fgl.git diff --git a/source/programbuilder.h b/source/programbuilder.h index 69170e02..9ca9c853 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; @@ -48,6 +56,7 @@ private: enum VariableScope { NO_SCOPE, + TYPE, UNIFORM, ATTRIBUTE, VERTEX, @@ -76,39 +85,50 @@ private: { std::string name; const VariableDefinition *variable; + const VariableDefinition *type; std::string resolved_name; + std::string resolved_block; 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_type(const VariableDefinition &); 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; InterfaceFlags get_interface_flags(VariableScope) const; - std::string create_declaration(char = 0) const; - std::string create_replacement(VariableScope) const; - std::string create_expression() const; + std::string create_type_declaration() 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; + std::map aliases; bool optimize; static const VariableDefinition standard_variables[]; @@ -123,10 +143,12 @@ 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 const char *unqualified_name(const char *); + 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 &); + std::string create_expression(const ShaderVariable &, const char * = 0) const; }; } // namespace GL