]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/material/mat.hxx
materials.xml format update
[simgear.git] / simgear / scene / material / mat.hxx
index 621f7940243c8d67c60bd2cefa105b689d3b5c21..9e2d06e432d58d7f490a85c4222040ab4f87ece2 100644 (file)
 #include <simgear/math/SGMath.hxx>
 
 #include <osg/ref_ptr>
-#include <osg/StateSet>
 
+namespace osg
+{
+class StateSet;
+}
+
+#include <simgear/scene/model/SGReaderWriterXMLOptions.hxx>
 #include <simgear/props/props.hxx>
 #include <simgear/structure/SGSharedPtr.hxx>
 #include <simgear/scene/util/SGSceneFeatures.hxx>
 
 #include "matmodel.hxx"
 
-SG_USING_STD(string);
-SG_USING_STD(vector);
-SG_USING_STD(map);
-
+namespace simgear
+{
+class Effect;
+void reload_shaders();
+}
 
 class SGMaterialGlyph;
 
@@ -79,29 +85,10 @@ 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, const char *season );
-
-
-  /**
-   * 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 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 state for this material.
-   */
-  SGMaterial( osg::StateSet *s );
+  SGMaterial( const osgDB::ReaderWriter::Options*, const SGPropertyNode *props);
 
+  SGMaterial(const simgear::SGReaderWriterXMLOptions*,
+             const SGPropertyNode *props);
   /**
    * Destructor.
    */
@@ -116,8 +103,7 @@ public:
   /**
    * Get the textured state.
    */
-  osg::StateSet *get_state (int n = -1);
-
+  simgear::Effect *get_effect(int n = -1);
 
   /**
    * Get the number of textures assigned to this material.
@@ -147,23 +133,37 @@ public:
   inline double get_light_coverage () const { return light_coverage; }
 
   /**
-   * Get the forest coverage.
+   * Get the wood coverage.
    *
-   * A smaller number means more generated forest canopy.
+   * A smaller number means more generated woods within the forest.
    *
-   * @return The area (m^2) covered by each canopy.
+   * @return The area (m^2) covered by each wood.
    */
-  inline double get_tree_coverage () const { return tree_coverage; }
+  inline double get_wood_coverage () const { return wood_coverage; }
 
   /**
-   * Get the forest height.
+   * 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.
    */
   inline double get_tree_height () const { return tree_height; }
 
   /**
-   * Get the forest width.
+   * Get the tree width.
    *
    * @return The average width of the trees.
    */
@@ -188,7 +188,7 @@ public:
    *
    * @return the texture to use for trees.
    */
-  inline string get_tree_texture () const { return  tree_texture; }
+  inline std::string get_tree_texture () const { return  tree_texture; }
 
   /**
    * Return if the surface material is solid, if it is not solid, a fluid
@@ -219,12 +219,12 @@ public:
   /**
    * Get the list of names for this material
    */
-  const vector<string>& get_names() const { return _names; }
+  const std::vector<std::string>& get_names() const { return _names; }
 
   /**
    * add the given name to the list of names this material is known
    */
-  void add_name(const string& name) { _names.push_back(name); }
+  void add_name(const std::string& name) { _names.push_back(name); }
 
   /**
    * Get the number of randomly-placed objects defined for this material.
@@ -241,7 +241,7 @@ public:
   /**
    * Return pointer to glyph class, or 0 if it doesn't exist.
    */
-  SGMaterialGlyph * get_glyph (const string& name) const;
+  SGMaterialGlyph * get_glyph (const std::string& name) const;
 
   void set_light_color(const SGVec4f& color)
   { emission = color; }
@@ -272,11 +272,15 @@ protected:
 protected:
 
   struct _internal_state {
-      _internal_state( osg::StateSet *s, const string &t, bool l )
-                  : state(s), texture_path(t), texture_loaded(l) {}
-      osg::ref_ptr<osg::StateSet> state;
-      string texture_path;
-      bool texture_loaded;
+      _internal_state(simgear::Effect *e, bool l,
+                      const simgear::SGReaderWriterXMLOptions *o);
+      _internal_state(simgear::Effect *e, const std::string &t, bool l,
+                      const simgear::SGReaderWriterXMLOptions *o);
+      void add_texture(const std::string &t, int i);
+      osg::ref_ptr<simgear::Effect> effect;
+      std::vector<std::pair<std::string,int> > texture_paths;
+      bool effect_realized;
+      osg::ref_ptr<const simgear::SGReaderWriterXMLOptions> options;
   };
 
 private:
@@ -287,7 +291,7 @@ private:
   ////////////////////////////////////////////////////////////////////
 
   // texture status
-  vector<_internal_state> _status;
+  std::vector<_internal_state> _status;
 
   // Round-robin counter
   mutable unsigned int _current_ptr;
@@ -304,9 +308,15 @@ private:
   // coverage of night lighting.
   double light_coverage;
   
-  // coverage of trees
-  double tree_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;
 
@@ -338,29 +348,27 @@ private:
   SGVec4f ambient, diffuse, specular, emission;
   double shininess;
 
+  // effect for this material
+  std::string effect;
+
   // the list of names for this material. May be empty.
-  vector<string> _names;
+  std::vector<std::string> _names;
 
-  vector<SGSharedPtr<SGMatModelGroup> > object_groups;
+  std::vector<SGSharedPtr<SGMatModelGroup> > object_groups;
 
   // taxiway-/runway-sign texture elements
-  map<string, SGSharedPtr<SGMaterialGlyph> > glyphs;
+  std::map<std::string, SGSharedPtr<SGMaterialGlyph> > glyphs;
   
   // Tree texture, typically a strip of applicable tree textures
-  string tree_texture;
+  std::string tree_texture;
 \f
   ////////////////////////////////////////////////////////////////////
   // Internal constructors and methods.
   ////////////////////////////////////////////////////////////////////
 
-  SGMaterial( const string &fg_root, const SGMaterial &mat ); // unimplemented
-
-  void read_properties( const string &fg_root, const SGPropertyNode *props, const char *season );
-  void build_state( bool defer_tex_load );
-  void set_state( osg::StateSet *s );
-
-  void assignTexture( osg::StateSet *state, const std::string &fname, bool _wrapu = true, bool _wrapv = true, bool _mipmap = true );
-
+  void read_properties(const simgear::SGReaderWriterXMLOptions* options,
+                        const SGPropertyNode *props);
+  void buildEffectProperties(const simgear::SGReaderWriterXMLOptions* options);
 };