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 #include <string> // Standard C++ string library
45 #include <map> // STL associative "array"
46 #include <vector> // STL "array"
48 #include "Include/compiler.h"
59 typedef vector < fgFRAGMENT * > frag_list_type;
60 typedef frag_list_type::iterator frag_list_iterator;
61 typedef frag_list_type::const_iterator frag_list_const_iterator;
64 // #define FG_MAX_MATERIAL_FRAGS 800
66 // MSVC++ 6.0 kuldge - Need forward declaration of friends.
68 istream& operator >> ( istream& in, fgMATERIAL& m );
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 );
121 // Material management class
122 class fgMATERIAL_MGR {
126 // associative array of materials
127 typedef map < string, fgMATERIAL, less<string> > container;
128 typedef container::iterator iterator;
129 typedef container::const_iterator const_iterator;
131 iterator begin() { return material_map.begin(); }
132 const_iterator begin() const { return material_map.begin(); }
134 iterator end() { return material_map.end(); }
135 const_iterator end() const { return material_map.end(); }
138 fgMATERIAL_MGR ( void );
140 // Load a library of material properties
141 int load_lib ( void );
143 bool get_textures_loaded() { return textures_loaded; }
145 // Initialize the transient list of fragments for each material property
146 void init_transient_material_lists( void );
148 bool find( const string& material, fgMATERIAL*& mtl_ptr );
150 void render_fragments();
153 ~fgMATERIAL_MGR ( void );
157 // Have textures been loaded
158 bool textures_loaded;
160 container material_map;
164 // global material management class
165 extern fgMATERIAL_MGR material_mgr;
168 #endif // _MATERIAL_HXX
172 // Revision 1.6 1999/02/02 20:13:39 curt
173 // MSVC++ portability changes by Bernie Bright:
175 // Lib/Serial/serial.[ch]xx: Initial Windows support - incomplete.
176 // Simulator/Astro/stars.cxx: typo? included <stdio> instead of <cstdio>
177 // Simulator/Cockpit/hud.cxx: Added Standard headers
178 // Simulator/Cockpit/panel.cxx: Redefinition of default parameter
179 // Simulator/Flight/flight.cxx: Replaced cout with FG_LOG. Deleted <stdio.h>
180 // Simulator/Main/fg_init.cxx:
181 // Simulator/Main/GLUTmain.cxx:
182 // Simulator/Main/options.hxx: Shuffled <fg_serial.hxx> dependency
183 // Simulator/Objects/material.hxx:
184 // Simulator/Time/timestamp.hxx: VC++ friend kludge
185 // Simulator/Scenery/tile.[ch]xx: Fixed using std::X declarations
186 // Simulator/Main/views.hxx: Added a constant
188 // Revision 1.5 1998/10/12 23:49:18 curt
189 // Changes from NHV to make the code more dynamic with fewer hard coded limits.
191 // Revision 1.4 1998/09/17 18:35:53 curt
192 // Tweaks and optimizations by Norman Vine.
194 // Revision 1.3 1998/09/10 19:07:12 curt
195 // /Simulator/Objects/fragment.hxx
196 // Nested fgFACE inside fgFRAGMENT since its not used anywhere else.
198 // ./Simulator/Objects/material.cxx
199 // ./Simulator/Objects/material.hxx
200 // Made fgMATERIAL and fgMATERIAL_MGR bona fide classes with private
201 // data members - that should keep the rabble happy :)
203 // ./Simulator/Scenery/tilemgr.cxx
204 // In viewable() delay evaluation of eye[0] and eye[1] in until they're
206 // Change to fgTileMgrRender() to call fgMATERIAL_MGR::render_fragments()
209 // ./Include/fg_stl_config.h
210 // ./Include/auto_ptr.hxx
211 // Added support for g++ 2.7.
212 // Further changes to other files are forthcoming.
214 // Brief summary of changes required for g++ 2.7.
215 // operator->() not supported by iterators: use (*i).x instead of i->x
216 // default template arguments not supported,
217 // <functional> doesn't have mem_fun_ref() needed by callbacks.
218 // some std include files have different names.
219 // template member functions not supported.
221 // Revision 1.2 1998/09/01 19:03:09 curt
222 // Changes contributed by Bernie Bright <bbright@c031.aone.net.au>
223 // - The new classes in libmisc.tgz define a stream interface into zlib.
224 // I've put these in a new directory, Lib/Misc. Feel free to rename it
225 // to something more appropriate. However you'll have to change the
226 // include directives in all the other files. Additionally you'll have
227 // add the library to Lib/Makefile.am and Simulator/Main/Makefile.am.
229 // The StopWatch class in Lib/Misc requires a HAVE_GETRUSAGE autoconf
230 // test so I've included the required changes in config.tgz.
232 // There are a fair few changes to Simulator/Objects as I've moved
233 // things around. Loading tiles is quicker but thats not where the delay
234 // is. Tile loading takes a few tenths of a second per file on a P200
235 // but it seems to be the post-processing that leads to a noticeable
236 // blip in framerate. I suppose its time to start profiling to see where
239 // I've included a brief description of each archives contents.
244 // C++ stream interface into zlib.
245 // Taken from zlib-1.1.3/contrib/iostream/.
246 // Minor mods for STL compatibility.
247 // There's no copyright associated with these so I assume they're
248 // covered by zlib's.
252 // FlightGear input stream using gz_ifstream. Tries to open the
253 // given filename. If that fails then filename is examined and a
254 // ".gz" suffix is removed or appended and that file is opened.
257 // A simple timer for benchmarking. Not used in production code.
258 // Taken from the Blitz++ project. Covered by GPL.
262 // Some simple string manipulation routines.
264 // Simulator/Airports/
265 // Load airports database using fgstream.
266 // Changed fgAIRPORTS to use set<> instead of map<>.
267 // Added bool fgAIRPORTS::search() as a neater way doing the lookup.
268 // Returns true if found.
271 // Modified fgStarsInit() to load stars database using fgstream.
273 // Simulator/Objects/
274 // Modified fgObjLoad() to use fgstream.
275 // Modified fgMATERIAL_MGR::load_lib() to use fgstream.
276 // Many changes to fgMATERIAL.
277 // Some changes to fgFRAGMENT but I forget what!
279 // Revision 1.1 1998/08/25 16:51:24 curt
280 // Moved from ../Scenery
282 // Revision 1.10 1998/07/24 21:42:06 curt
283 // material.cxx: whups, double method declaration with no definition.
284 // obj.cxx: tweaks to avoid errors in SGI's CC.
285 // tile.cxx: optimizations by Norman Vine.
286 // tilemgr.cxx: optimizations by Norman Vine.
288 // Revision 1.9 1998/07/06 21:34:33 curt
289 // Added using namespace std for compilers that support this.
291 // Revision 1.8 1998/06/17 21:36:39 curt
292 // Load and manage multiple textures defined in the Materials library.
293 // Boost max material fagments for each material property to 800.
294 // Multiple texture support when rendering.
296 // Revision 1.7 1998/06/12 00:58:04 curt
297 // Build only static libraries.
298 // Declare memmove/memset for Sloaris.
300 // Revision 1.6 1998/06/06 01:09:31 curt
301 // I goofed on the log message in the last commit ... now fixed.
303 // Revision 1.5 1998/06/06 01:07:17 curt
304 // Increased per material fragment list size from 100 to 400.
305 // Now correctly draw viewable fragments in per material order.
307 // Revision 1.4 1998/06/05 22:39:53 curt
308 // Working on sorting by, and rendering by material properties.
310 // Revision 1.3 1998/06/03 00:47:50 curt
311 // No .h for STL includes.
312 // Minor view culling optimizations.
314 // Revision 1.2 1998/06/01 17:56:20 curt
315 // Incremental additions to material.cxx (not fully functional)
316 // Tweaked vfc_ratio math to avoid divide by zero.
318 // Revision 1.1 1998/05/30 01:56:45 curt
319 // Added material.cxx material.hxx