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"
52 #ifdef NEEDNAMESPACESTD
60 #define FG_MAX_MATERIAL_FRAGS 800
63 // Material property class
67 // OpenGL texture name
70 // file name of texture
76 // material properties
77 GLfloat ambient[4], diffuse[4], specular[4], emissive[4];
80 // transient list of objects with this material type (used for sorting
81 // by material to reduce GL state changes when rendering the scene
82 fgFRAGMENT * list[FG_MAX_MATERIAL_FRAGS];
89 void init_sort_list( void ) {
93 int append_sort_list( fgFRAGMENT *object );
101 istream& operator >> ( istream& in, fgMATERIAL& m );
103 // Material management class
104 class fgMATERIAL_MGR {
108 // associative array of materials
109 typedef map < string, fgMATERIAL, less<string> > container;
110 typedef container::iterator iterator;
111 typedef container::const_iterator const_iterator;
113 container material_map;
116 fgMATERIAL_MGR ( void );
118 // Load a library of material properties
119 int load_lib ( void );
121 // Initialize the transient list of fragments for each material property
122 void init_transient_material_lists( void );
124 bool find( const string& material, fgMATERIAL*& mtl_ptr );
127 ~fgMATERIAL_MGR ( void );
131 // global material management class
132 extern fgMATERIAL_MGR material_mgr;
135 #endif // _MATERIAL_HXX
139 // Revision 1.2 1998/09/01 19:03:09 curt
140 // Changes contributed by Bernie Bright <bbright@c031.aone.net.au>
141 // - The new classes in libmisc.tgz define a stream interface into zlib.
142 // I've put these in a new directory, Lib/Misc. Feel free to rename it
143 // to something more appropriate. However you'll have to change the
144 // include directives in all the other files. Additionally you'll have
145 // add the library to Lib/Makefile.am and Simulator/Main/Makefile.am.
147 // The StopWatch class in Lib/Misc requires a HAVE_GETRUSAGE autoconf
148 // test so I've included the required changes in config.tgz.
150 // There are a fair few changes to Simulator/Objects as I've moved
151 // things around. Loading tiles is quicker but thats not where the delay
152 // is. Tile loading takes a few tenths of a second per file on a P200
153 // but it seems to be the post-processing that leads to a noticeable
154 // blip in framerate. I suppose its time to start profiling to see where
157 // I've included a brief description of each archives contents.
162 // C++ stream interface into zlib.
163 // Taken from zlib-1.1.3/contrib/iostream/.
164 // Minor mods for STL compatibility.
165 // There's no copyright associated with these so I assume they're
166 // covered by zlib's.
170 // FlightGear input stream using gz_ifstream. Tries to open the
171 // given filename. If that fails then filename is examined and a
172 // ".gz" suffix is removed or appended and that file is opened.
175 // A simple timer for benchmarking. Not used in production code.
176 // Taken from the Blitz++ project. Covered by GPL.
180 // Some simple string manipulation routines.
182 // Simulator/Airports/
183 // Load airports database using fgstream.
184 // Changed fgAIRPORTS to use set<> instead of map<>.
185 // Added bool fgAIRPORTS::search() as a neater way doing the lookup.
186 // Returns true if found.
189 // Modified fgStarsInit() to load stars database using fgstream.
191 // Simulator/Objects/
192 // Modified fgObjLoad() to use fgstream.
193 // Modified fgMATERIAL_MGR::load_lib() to use fgstream.
194 // Many changes to fgMATERIAL.
195 // Some changes to fgFRAGMENT but I forget what!
197 // Revision 1.1 1998/08/25 16:51:24 curt
198 // Moved from ../Scenery
200 // Revision 1.10 1998/07/24 21:42:06 curt
201 // material.cxx: whups, double method declaration with no definition.
202 // obj.cxx: tweaks to avoid errors in SGI's CC.
203 // tile.cxx: optimizations by Norman Vine.
204 // tilemgr.cxx: optimizations by Norman Vine.
206 // Revision 1.9 1998/07/06 21:34:33 curt
207 // Added using namespace std for compilers that support this.
209 // Revision 1.8 1998/06/17 21:36:39 curt
210 // Load and manage multiple textures defined in the Materials library.
211 // Boost max material fagments for each material property to 800.
212 // Multiple texture support when rendering.
214 // Revision 1.7 1998/06/12 00:58:04 curt
215 // Build only static libraries.
216 // Declare memmove/memset for Sloaris.
218 // Revision 1.6 1998/06/06 01:09:31 curt
219 // I goofed on the log message in the last commit ... now fixed.
221 // Revision 1.5 1998/06/06 01:07:17 curt
222 // Increased per material fragment list size from 100 to 400.
223 // Now correctly draw viewable fragments in per material order.
225 // Revision 1.4 1998/06/05 22:39:53 curt
226 // Working on sorting by, and rendering by material properties.
228 // Revision 1.3 1998/06/03 00:47:50 curt
229 // No .h for STL includes.
230 // Minor view culling optimizations.
232 // Revision 1.2 1998/06/01 17:56:20 curt
233 // Incremental additions to material.cxx (not fully functional)
234 // Tweaked vfc_ratio math to avoid divide by zero.
236 // Revision 1.1 1998/05/30 01:56:45 curt
237 // Added material.cxx material.hxx