1 // mat.hxx -- a material in the scene graph.
2 // TODO: this class needs to be renamed.
4 // Written by Curtis Olson, started May 1998.
5 // Overhauled by David Megginson, December 2001
7 // Copyright (C) 1998 - 2000 Curtis L. Olson - curt@flightgear.org
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License as
11 // published by the Free Software Foundation; either version 2 of the
12 // License, or (at your option) any later version.
14 // This program is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 # error This library requires C++
33 #include <simgear/compiler.h>
35 #include STL_STRING // Standard C++ string library
40 #include <simgear/props/props.hxx>
41 #include <simgear/scene/model/modellib.hxx>
43 #include "matmodel.hxx"
49 * A material in the scene graph.
51 * A material represents information about a single surface type
52 * in the 3D scene graph, including texture, colour, lighting,
53 * tiling, and so on; most of the materials in FlightGear are
54 * defined in the $FG_ROOT/materials.xml file, and can be changed
62 ////////////////////////////////////////////////////////////////////
63 // Public Constructors.
64 ////////////////////////////////////////////////////////////////////
67 * Construct a material from a set of properties.
69 * @param props A property node containing subnodes with the
70 * state information for the material. This node is usually
71 * loaded from the $FG_ROOT/materials.xml file.
73 SGMaterial( const string &fg_root, const SGPropertyNode *props );
77 * Construct a material from an absolute texture path.
79 * @param texture_path A string containing an absolute path
80 * to a texture file (usually RGB).
82 SGMaterial( const string &texpath );
86 * Construct a material around an existing SSG state.
88 * This constructor allows the application to create a custom,
89 * low-level state for the scene graph and wrap a material around
90 * it. Note: the pointer ownership is transferred to the material.
92 * @param s The SSG state for this material.
94 SGMaterial( ssgSimpleState *s );
99 virtual ~SGMaterial( void );
103 ////////////////////////////////////////////////////////////////////
105 ////////////////////////////////////////////////////////////////////
108 * Force the texture to load if it hasn't already.
110 * @return true if the texture loaded, false if it was loaded
113 virtual bool load_texture ();
117 * Get the textured state.
119 virtual inline ssgSimpleState *get_state () const { return state; }
123 * Get the xsize of the texture, in meters.
125 virtual inline double get_xsize() const { return xsize; }
129 * Get the ysize of the texture, in meters.
131 virtual inline double get_ysize() const { return ysize; }
135 * Get the light coverage.
137 * A smaller number means more generated night lighting.
139 * @return The area (m^2?) covered by each light.
141 virtual inline double get_light_coverage () const { return light_coverage; }
145 * Get the number of randomly-placed objects defined for this material.
147 virtual int get_object_group_count () const { return object_groups.size(); }
151 * Get a randomly-placed object for this material.
153 virtual SGMatModelGroup * get_object_group (int index) const {
154 return object_groups[index];
159 * Increment the reference count for this material.
161 * A material with 0 references may be deleted by the
164 virtual inline void ref () { refcount++; }
168 * Decrement the reference count for this material.
170 virtual inline void deRef () { refcount--; }
174 * Get the reference count for this material.
176 * @return The number of references (0 if none).
178 virtual inline int getRef () const { return refcount; }
183 ////////////////////////////////////////////////////////////////////
184 // Protected methods.
185 ////////////////////////////////////////////////////////////////////
188 * Initialization method, invoked by all public constructors.
196 ////////////////////////////////////////////////////////////////////
198 ////////////////////////////////////////////////////////////////////
203 // pointers to ssg states
204 ssgSimpleState *state;
215 // coverage of night lighting.
216 double light_coverage;
218 // material properties
219 sgVec4 ambient, diffuse, specular, emission;
222 // true if texture loading deferred, and not yet loaded
225 vector<SGMatModelGroup *> object_groups;
227 // ref count so we can properly delete if we have multiple
228 // pointers to this record
233 ////////////////////////////////////////////////////////////////////
234 // Internal constructors and methods.
235 ////////////////////////////////////////////////////////////////////
237 SGMaterial( const string &fg_root, const SGMaterial &mat ); // unimplemented
239 void read_properties( const string &fg_root, const SGPropertyNode *props );
240 void build_ssg_state( bool defer_tex_load );
241 void set_ssg_state( ssgSimpleState *s );
246 #endif // _SG_MAT_HXX