X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fscene%2Fmaterial%2Fmat.hxx;h=619ae8dae08bae9c62ccfb1ad68c1a7b8c071eea;hb=d04cf4d8978866eb80a1639b6d4ddfe387338c77;hp=a32bde3220cd450a9b1bbe22b9d2d31fcad3d1d3;hpb=7fc8c026884b2d0a1b683765c089a9bef5ac47c8;p=simgear.git diff --git a/simgear/scene/material/mat.hxx b/simgear/scene/material/mat.hxx index a32bde32..619ae8da 100644 --- a/simgear/scene/material/mat.hxx +++ b/simgear/scene/material/mat.hxx @@ -18,7 +18,7 @@ // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software -// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // // $Id$ @@ -26,25 +26,39 @@ #ifndef _SG_MAT_HXX #define _SG_MAT_HXX -#ifndef __cplusplus +#ifndef __cplusplus # error This library requires C++ -#endif +#endif #include -#include STL_STRING // Standard C++ string library +#include // Standard C++ string library #include +#include -#include -#include +#include +#include + +namespace osg +{ +class StateSet; +} + +#include #include +#include +#include #include "matmodel.hxx" -SG_USING_STD(string); -SG_USING_STD(vector); +namespace simgear +{ +class Effect; +void reload_shaders(); +} +class SGMaterialGlyph; /** * A material in the scene graph. @@ -55,7 +69,7 @@ SG_USING_STD(vector); * defined in the $FG_ROOT/materials.xml file, and can be changed * at runtime. */ -class SGMaterial { +class SGMaterial : public SGReferenced { public: @@ -71,33 +85,14 @@ public: * state information for the material. This node is usually * loaded from the $FG_ROOT/materials.xml file. */ - SGMaterial( const string &fg_root, const SGPropertyNode *props ); - - - /** - * Construct a material from an absolute texture path. - * - * @param texture_path A string containing an absolute path - * to a texture file (usually RGB). - */ - SGMaterial( const string &texpath ); - - - /** - * Construct a material around an existing SSG state. - * - * This constructor allows the application to create a custom, - * low-level state for the scene graph and wrap a material around - * it. Note: the pointer ownership is transferred to the material. - * - * @param s The SSG state for this material. - */ - SGMaterial( ssgSimpleState *s ); + SGMaterial( const osgDB::ReaderWriter::Options*, const SGPropertyNode *props); + SGMaterial(const simgear::SGReaderWriterXMLOptions*, + const SGPropertyNode *props); /** * Destructor. */ - virtual ~SGMaterial( void ); + ~SGMaterial( void ); @@ -105,37 +100,27 @@ public: // Public methods. //////////////////////////////////////////////////////////////////// - /** - * Force the texture to load if it hasn't already. - * - * @return true if the texture loaded, false if it was loaded - * already. - */ - virtual bool load_texture (int n = -1); - - /** * Get the textured state. */ - virtual ssgSimpleState *get_state (int n = -1) const; - + simgear::Effect *get_effect(int n = -1); /** * Get the number of textures assigned to this material. */ - virtual inline int get_num() const { return _status.size(); } + inline int get_num() const { return _status.size(); } /** * Get the xsize of the texture, in meters. */ - virtual inline double get_xsize() const { return xsize; } + inline double get_xsize() const { return xsize; } /** * Get the ysize of the texture, in meters. */ - virtual inline double get_ysize() const { return ysize; } + inline double get_ysize() const { return ysize; } /** @@ -143,46 +128,134 @@ public: * * A smaller number means more generated night lighting. * - * @return The area (m^2?) covered by each light. + * @return The area (m^2) covered by each light. */ - virtual inline double get_light_coverage () const { return light_coverage; } + inline double get_light_coverage () const { return light_coverage; } + /** + * Get the wood coverage. + * + * A smaller number means more generated woods within the forest. + * + * @return The area (m^2) covered by each wood. + */ + inline double get_wood_coverage () const { return wood_coverage; } /** - * Get the number of randomly-placed objects defined for this material. + * Get the density of the wood + * + * @return The area (m^2) covered by each tree in the wood. + */ + inline double get_tree_density () const { return tree_density; } + + /** + * Get the size of each wood + * + * @return the average area (m^2) of each wood + */ + inline double get_wood_size () const { return wood_size; } + + /** + * Get the tree height. + * + * @return The average height of the trees. */ - virtual int get_object_group_count () const { return object_groups.size(); } + inline double get_tree_height () const { return tree_height; } + /** + * Get the tree width. + * + * @return The average width of the trees. + */ + inline double get_tree_width () const { return tree_width; } /** - * Get a randomly-placed object for this material. + * Get the forest LoD range. + * + * @return The LoD range for the trees. */ - virtual SGMatModelGroup * get_object_group (int index) const { - return object_groups[index]; - } + inline double get_tree_range () const { return tree_range; } + + /** + * Get the number of tree varieties available + * + * @return the number of different trees defined in the texture strip + */ + inline int get_tree_varieties () const { return tree_varieties; } + + /** + * Get the texture strip to use for trees + * + * @return the texture to use for trees. + */ + inline std::string get_tree_texture () const { return tree_texture; } + + /** + * Return if the surface material is solid, if it is not solid, a fluid + * can be assumed, that is usually water. + */ + bool get_solid () const { return solid; } + /** + * Get the friction factor for that material + */ + double get_friction_factor () const { return friction_factor; } /** - * Increment the reference count for this material. - * - * A material with 0 references may be deleted by the - * material library. + * Get the rolling friction for that material */ - virtual inline void ref () { refcount++; } + double get_rolling_friction () const { return rolling_friction; } + /** + * Get the bumpines for that material + */ + double get_bumpiness () const { return bumpiness; } /** - * Decrement the reference count for this material. + * Get the load resistance */ - virtual inline void deRef () { refcount--; } + double get_load_resistance () const { return load_resistance; } + /** + * Get the list of names for this material + */ + const std::vector& get_names() const { return _names; } /** - * Get the reference count for this material. - * - * @return The number of references (0 if none). + * add the given name to the list of names this material is known */ - virtual inline int getRef () const { return refcount; } + void add_name(const std::string& name) { _names.push_back(name); } + + /** + * Get the number of randomly-placed objects defined for this material. + */ + int get_object_group_count () const { return object_groups.size(); } + + /** + * Get a randomly-placed object for this material. + */ + SGMatModelGroup * get_object_group (int index) const { + return object_groups[index]; + } + + /** + * Return pointer to glyph class, or 0 if it doesn't exist. + */ + SGMaterialGlyph * get_glyph (const std::string& name) const; + + void set_light_color(const SGVec4f& color) + { emission = color; } + const SGVec4f& get_light_color() const + { return emission; } + + SGVec2f get_tex_coord_scale() const + { + float tex_width = get_xsize(); + float tex_height = get_ysize(); + + return SGVec2f((0 < tex_width) ? 1000.0f/tex_width : 1.0f, + (0 < tex_height) ? 1000.0f/tex_height : 1.0f); + } protected: @@ -194,16 +267,17 @@ protected: /** * Initialization method, invoked by all public constructors. */ - virtual void init(); + void init(); protected: struct _internal_state { - _internal_state( ssgSimpleState *s, const string &t, bool l ) - : state(s), texture_path(t), texture_loaded(l) {} - ssgSimpleState *state; - string texture_path; - bool texture_loaded; + _internal_state(simgear::Effect *e, const std::string &t, bool l, + const simgear::SGReaderWriterXMLOptions *o); + osg::ref_ptr effect; + std::string texture_path; + bool effect_realized; + osg::ref_ptr options; }; private: @@ -214,10 +288,10 @@ private: //////////////////////////////////////////////////////////////////// // texture status - vector<_internal_state> _status; + std::vector<_internal_state> _status; // Round-robin counter - unsigned int _current_ptr; + mutable unsigned int _current_ptr; // texture size double xsize, ysize; @@ -226,34 +300,104 @@ private: bool wrapu, wrapv; // use mipmapping? - int mipmap; + bool mipmap; // coverage of night lighting. double light_coverage; + + // coverage of woods + double wood_coverage; + + // The size of each wood + double wood_size; + + // Tree density within the wood + double tree_density; + + // Range at which trees become visible + double tree_range; + + // Height of the tree + double tree_height; + + // Width of the tree + double tree_width; + + // Number of varieties of tree texture + int tree_varieties; + + // True if the material is solid, false if it is a fluid + bool solid; + + // the friction factor of that surface material + double friction_factor; + + // the rolling friction of that surface material + double rolling_friction; + + // the bumpiness of that surface material + double bumpiness; + + // the load resistance of that surface material + double load_resistance; // material properties - sgVec4 ambient, diffuse, specular, emission; + SGVec4f ambient, diffuse, specular, emission; double shininess; - vector object_groups; + // effect for this material + std::string effect; - // ref count so we can properly delete if we have multiple - // pointers to this record - int refcount; + // the list of names for this material. May be empty. + std::vector _names; + std::vector > object_groups; + // taxiway-/runway-sign texture elements + std::map > glyphs; + + // Tree texture, typically a strip of applicable tree textures + std::string tree_texture; //////////////////////////////////////////////////////////////////// // Internal constructors and methods. //////////////////////////////////////////////////////////////////// - SGMaterial( const string &fg_root, const SGMaterial &mat ); // unimplemented + void read_properties(const simgear::SGReaderWriterXMLOptions* options, + const SGPropertyNode *props); + void buildEffectProperties(const simgear::SGReaderWriterXMLOptions* options); +}; - void read_properties( const string &fg_root, const SGPropertyNode *props ); - void build_ssg_state( bool defer_tex_load ); - void set_ssg_state( ssgSimpleState *s ); +class SGMaterialGlyph : public SGReferenced { +public: + SGMaterialGlyph(SGPropertyNode *); + inline double get_left() const { return _left; } + inline double get_right() const { return _right; } + inline double get_width() const { return _right - _left; } +protected: + double _left; + double _right; }; +class SGMaterialUserData : public osg::Referenced { +public: + SGMaterialUserData(const SGMaterial* material) : + mMaterial(material) + {} + const SGMaterial* getMaterial() const + { return mMaterial; } +private: + // this cannot be an SGSharedPtr since that would create a cicrular reference + // making it impossible to ever free the space needed by SGMaterial + const SGMaterial* mMaterial; +}; + +void +SGSetTextureFilter( int max); + +int +SGGetTextureFilter(); + #endif // _SG_MAT_HXX