1 // newmat.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++
44 #include <simgear/compiler.h>
45 #include <simgear/misc/props.hxx>
49 #include STL_STRING // Standard C++ string library
55 * A material in the scene graph.
57 * A material represents information about a single surface type
58 * in the 3D scene graph, including texture, colour, lighting,
59 * tiling, and so on; most of the materials in FlightGear are
60 * defined in the $FG_ROOT/materials.xml file, and can be changed
68 ////////////////////////////////////////////////////////////////////
69 // Public Constructors.
70 ////////////////////////////////////////////////////////////////////
73 * Construct a material from a set of properties.
75 * @param props A property node containing subnodes with the
76 * state information for the material. This node is usually
77 * loaded from the $FG_ROOT/materials.xml file.
79 FGNewMat (const SGPropertyNode * props);
83 * Construct a material from an absolute texture path.
85 * @param texture_path A string containing an absolute path
86 * to a texture file (usually RGB).
88 FGNewMat (const string &texpath);
92 * Construct a material around an existing SSG state.
94 * This constructor allows the application to create a custom,
95 * low-level state for the scene graph and wrap a material around
96 * it. Note: the pointer ownership is transferred to the material.
98 * @param s The SSG state for this material.
100 FGNewMat (ssgSimpleState * s);
105 virtual ~FGNewMat ( void );
109 ////////////////////////////////////////////////////////////////////
111 ////////////////////////////////////////////////////////////////////
114 * Force the texture to load if it hasn't already.
116 * @return true if the texture loaded, false if it was loaded
119 virtual bool load_texture ();
123 * Get the textured state.
125 virtual inline ssgSimpleState *get_textured () { return textured; }
129 * Get the xsize of the texture, in meters.
131 virtual inline double get_xsize() const { return xsize; }
135 * Get the ysize of the texture, in meters.
137 virtual inline double get_ysize() const { return ysize; }
141 * Get the light coverage.
143 * A smaller number means more generated night lighting.
145 * @return The area (m^2?) covered by each light.
147 virtual inline double get_light_coverage () const { return light_coverage; }
151 * Get the current state.
153 virtual inline ssgStateSelector *get_state () const { return state; }
157 * Increment the reference count for this material.
159 * A material with 0 references may be deleted by the
162 virtual inline void ref () { refcount++; }
166 * Decrement the reference count for this material.
168 virtual inline void deRef () { refcount--; }
172 * Get the reference count for this material.
174 * @return The number of references (0 if none).
176 virtual inline int getRef () const { return refcount; }
181 ////////////////////////////////////////////////////////////////////
182 // Protected methods.
183 ////////////////////////////////////////////////////////////////////
186 * Initialization method, invoked by all public constructors.
194 ////////////////////////////////////////////////////////////////////
196 ////////////////////////////////////////////////////////////////////
201 // pointers to ssg states
202 ssgStateSelector *state;
203 ssgSimpleState *textured;
204 ssgSimpleState *nontextured;
215 // coverage of night lighting.
216 double light_coverage;
218 // material properties
219 sgVec4 ambient, diffuse, specular, emission;
221 // true if texture loading deferred, and not yet loaded
224 // ref count so we can properly delete if we have multiple
225 // pointers to this record
230 ////////////////////////////////////////////////////////////////////
231 // Internal constructors and methods.
232 ////////////////////////////////////////////////////////////////////
234 FGNewMat (const FGNewMat &mat); // unimplemented
236 void read_properties (const SGPropertyNode * props);
237 void build_ssg_state(bool defer_tex_load = false);
238 void set_ssg_state( ssgSimpleState *s );
242 #endif // _NEWMAT_HXX