1 // material.hxx -- class to handle material properties
3 // Written by Curtis Olson, started May 1998.
5 // Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 // (Log is kept at end of this file)
30 # error This library requires C++
44 #if defined ( __sun__ )
45 extern "C" void *memmove(void *, const void *, size_t);
46 extern "C" void *memset(void *, int, size_t);
49 #include <string> // Standard C++ string library
50 #include <map> // STL associative "array"
51 #include <vector> // STL "array"
53 #ifdef NEEDNAMESPACESTD
62 typedef vector < fgFRAGMENT * > frag_list_type;
63 typedef frag_list_type::iterator frag_list_iterator;
64 typedef frag_list_type::const_iterator frag_list_const_iterator;
67 // #define FG_MAX_MATERIAL_FRAGS 800
70 // Material property class
74 // OpenGL texture name
77 // file name of texture
83 // material properties
84 GLfloat ambient[4], diffuse[4], specular[4], emissive[4];
87 // transient list of objects with this material type (used for sorting
88 // by material to reduce GL state changes when rendering the scene
97 int size() const { return list.size(); }
98 bool empty() const { return list.size() == 0; }
101 void init_sort_list( void ) {
102 list.erase( list.begin(), list.end() );
105 bool append_sort_list( fgFRAGMENT *object ) {
106 list.push_back( object );
110 void render_fragments();
115 ~fgMATERIAL ( void );
117 friend istream& operator >> ( istream& in, fgMATERIAL& m );
120 istream& operator >> ( istream& in, fgMATERIAL& m );
122 // Material management class
123 class fgMATERIAL_MGR {
127 // associative array of materials
128 typedef map < string, fgMATERIAL, less<string> > container;
129 typedef container::iterator iterator;
130 typedef container::const_iterator const_iterator;
132 iterator begin() { return material_map.begin(); }
133 const_iterator begin() const { return material_map.begin(); }
135 iterator end() { return material_map.end(); }
136 const_iterator end() const { return material_map.end(); }
139 fgMATERIAL_MGR ( void );
141 // Load a library of material properties
142 int load_lib ( void );
144 bool get_textures_loaded() { return textures_loaded; }
146 // Initialize the transient list of fragments for each material property
147 void init_transient_material_lists( void );
149 bool find( const string& material, fgMATERIAL*& mtl_ptr );
151 void render_fragments();
154 ~fgMATERIAL_MGR ( void );
158 // Have textures been loaded
159 bool textures_loaded;
161 container material_map;
165 // global material management class
166 extern fgMATERIAL_MGR material_mgr;
169 #endif // _MATERIAL_HXX
173 // Revision 1.5 1998/10/12 23:49:18 curt
174 // Changes from NHV to make the code more dynamic with fewer hard coded limits.
176 // Revision 1.4 1998/09/17 18:35:53 curt
177 // Tweaks and optimizations by Norman Vine.
179 // Revision 1.3 1998/09/10 19:07:12 curt
180 // /Simulator/Objects/fragment.hxx
181 // Nested fgFACE inside fgFRAGMENT since its not used anywhere else.
183 // ./Simulator/Objects/material.cxx
184 // ./Simulator/Objects/material.hxx
185 // Made fgMATERIAL and fgMATERIAL_MGR bona fide classes with private
186 // data members - that should keep the rabble happy :)
188 // ./Simulator/Scenery/tilemgr.cxx
189 // In viewable() delay evaluation of eye[0] and eye[1] in until they're
191 // Change to fgTileMgrRender() to call fgMATERIAL_MGR::render_fragments()
194 // ./Include/fg_stl_config.h
195 // ./Include/auto_ptr.hxx
196 // Added support for g++ 2.7.
197 // Further changes to other files are forthcoming.
199 // Brief summary of changes required for g++ 2.7.
200 // operator->() not supported by iterators: use (*i).x instead of i->x
201 // default template arguments not supported,
202 // <functional> doesn't have mem_fun_ref() needed by callbacks.
203 // some std include files have different names.
204 // template member functions not supported.
206 // Revision 1.2 1998/09/01 19:03:09 curt
207 // Changes contributed by Bernie Bright <bbright@c031.aone.net.au>
208 // - The new classes in libmisc.tgz define a stream interface into zlib.
209 // I've put these in a new directory, Lib/Misc. Feel free to rename it
210 // to something more appropriate. However you'll have to change the
211 // include directives in all the other files. Additionally you'll have
212 // add the library to Lib/Makefile.am and Simulator/Main/Makefile.am.
214 // The StopWatch class in Lib/Misc requires a HAVE_GETRUSAGE autoconf
215 // test so I've included the required changes in config.tgz.
217 // There are a fair few changes to Simulator/Objects as I've moved
218 // things around. Loading tiles is quicker but thats not where the delay
219 // is. Tile loading takes a few tenths of a second per file on a P200
220 // but it seems to be the post-processing that leads to a noticeable
221 // blip in framerate. I suppose its time to start profiling to see where
224 // I've included a brief description of each archives contents.
229 // C++ stream interface into zlib.
230 // Taken from zlib-1.1.3/contrib/iostream/.
231 // Minor mods for STL compatibility.
232 // There's no copyright associated with these so I assume they're
233 // covered by zlib's.
237 // FlightGear input stream using gz_ifstream. Tries to open the
238 // given filename. If that fails then filename is examined and a
239 // ".gz" suffix is removed or appended and that file is opened.
242 // A simple timer for benchmarking. Not used in production code.
243 // Taken from the Blitz++ project. Covered by GPL.
247 // Some simple string manipulation routines.
249 // Simulator/Airports/
250 // Load airports database using fgstream.
251 // Changed fgAIRPORTS to use set<> instead of map<>.
252 // Added bool fgAIRPORTS::search() as a neater way doing the lookup.
253 // Returns true if found.
256 // Modified fgStarsInit() to load stars database using fgstream.
258 // Simulator/Objects/
259 // Modified fgObjLoad() to use fgstream.
260 // Modified fgMATERIAL_MGR::load_lib() to use fgstream.
261 // Many changes to fgMATERIAL.
262 // Some changes to fgFRAGMENT but I forget what!
264 // Revision 1.1 1998/08/25 16:51:24 curt
265 // Moved from ../Scenery
267 // Revision 1.10 1998/07/24 21:42:06 curt
268 // material.cxx: whups, double method declaration with no definition.
269 // obj.cxx: tweaks to avoid errors in SGI's CC.
270 // tile.cxx: optimizations by Norman Vine.
271 // tilemgr.cxx: optimizations by Norman Vine.
273 // Revision 1.9 1998/07/06 21:34:33 curt
274 // Added using namespace std for compilers that support this.
276 // Revision 1.8 1998/06/17 21:36:39 curt
277 // Load and manage multiple textures defined in the Materials library.
278 // Boost max material fagments for each material property to 800.
279 // Multiple texture support when rendering.
281 // Revision 1.7 1998/06/12 00:58:04 curt
282 // Build only static libraries.
283 // Declare memmove/memset for Sloaris.
285 // Revision 1.6 1998/06/06 01:09:31 curt
286 // I goofed on the log message in the last commit ... now fixed.
288 // Revision 1.5 1998/06/06 01:07:17 curt
289 // Increased per material fragment list size from 100 to 400.
290 // Now correctly draw viewable fragments in per material order.
292 // Revision 1.4 1998/06/05 22:39:53 curt
293 // Working on sorting by, and rendering by material properties.
295 // Revision 1.3 1998/06/03 00:47:50 curt
296 // No .h for STL includes.
297 // Minor view culling optimizations.
299 // Revision 1.2 1998/06/01 17:56:20 curt
300 // Incremental additions to material.cxx (not fully functional)
301 // Tweaked vfc_ratio math to avoid divide by zero.
303 // Revision 1.1 1998/05/30 01:56:45 curt
304 // Added material.cxx material.hxx