/* model/material.h This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2 */ #ifndef __INCLUDED_MODEL_MATERIAL_H__ #define __INCLUDED_MODEL_MATERIAL_H__ #include "model/layer.h" #include #include #include namespace model { /** * @brief fragment material properties * */ class Material { public: /** * @brief function pointer type the image loader hook * */ typedef void(* ImageLoaderFuncPtr)(Layer *); /** * @brief type definition for the material registry * */ typedef std::map Registry; /** * @brief type definition for the material layers list * */ typedef std::list Layers; /** * @brief material surface flags * */ enum SurfaceFlags { FlagNone = 0, FlagIgnore = 1, FlagClip = 2, FlagOrigin = 4, FlagDecal = 8, FlagBounds = 16 }; Material(const std::string &name); ~Material(); void print(); /* ---- inspectors ----------------------------------------- */ /** * @brief returns the name of the material * */ inline const std::string &name() const { return material_name; } /** * @brief returns the size of the material, in pixels */ inline const math::Vector2f & size() const { return material_size; } /** * @brief return the flags for this material * @see Flags * */ inline const int flags() const { return material_flags; } /** * @brief returns true if the material has the requested flag set * */ inline bool has_flag(const SurfaceFlags surfaceflag) const { return ((material_flags & surfaceflag) == surfaceflag); } /** * @brief returns true if the material has the Clip flag set * @see flags() * */ inline bool has_flag_clip() const { return (has_flag(FlagClip)); } /** * @brief returns true if the material has the Ignore flag set * @see flags() * */ inline bool has_flag_ignore() const { return (has_flag(FlagIgnore)); } /** * @brief returns true if the material has the Origin flag set * @see flags() * */ inline bool has_flag_origin() const { return (has_flag(FlagOrigin)); } /** * @brief returns true if the material has the Bounds flag set * @see flags() * */ inline bool has_flag_bounds() const { return (has_flag(FlagBounds)); } /* ---- mutators ------------------------------------------- */ /** * @brief set a specified surface flag * @see flags() * */ inline void set_flags(const SurfaceFlags flags) { material_flags |= flags; } /** * @brief clear a specified surface flag * @see flags() * */ inline void unset_flags(const SurfaceFlags flags) { material_flags &= ~flags; } void set_size(const math::Vector2f & size); /** * @brief layers in this material * */ inline const Layers & layers() const { return material_layers; } /** * @brief layers in this material * */ inline Layers & layers() { return material_layers; } /** * @brief add a new layer to the material * */ Layer *add_layer(); /* ---- static ----------------------------------------------------- */ /** * @brief material registry * */ static inline Registry & registry() { return material_registry; } /** * @brief initialize material registry * reads materials from the shader files listed in shaderlist.txt * */ static void init(); /** * @brief shutdown material registry */ static void shutdown(); /** * @brief clear material registry * */ static void clear(); /** * @brief print registered materials to the system console */ static void list(); /** * @brief load a material into the registry * If a material with the requested name already exists, it will be returned. * If it doesnt, a mew material will be created, containing a single layer * with a texture with the same name as the material. * @param ui_texture set to true if the material is a material used by the user interface * */ static Material *load(const std::string &name, const bool ui_texture=false); /** * @brief find a material in the registry * */ static Material *find(const std::string &name); /** * @brief add a new material to the registry. * */ static Material *add(const std::string &name); static void set_imageloader_func(ImageLoaderFuncPtr func); private: Layers material_layers; std::string material_name; int material_flags; math::Vector2f material_size; static Registry material_registry; static ImageLoaderFuncPtr material_imageloaderfunc; static void load_shaderfile(const std::string &shadername); }; } #endif // __INCLUDED_MODEL_MATERIAL_H__