1 // materialmgr.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.
24 #ifndef _MATERIALMGR_HXX
25 #define _MATERIALMGR_HXX
29 # error This library requires C++
40 #include "Include/compiler.h"
45 #include STL_STRING // Standard C++ string library
46 #include <map> // STL associative "array"
47 #include <vector> // STL "array"
49 #include "material.hxx"
61 typedef vector < fgFRAGMENT * > frag_list_type;
62 typedef frag_list_type::iterator frag_list_iterator;
63 typedef frag_list_type::const_iterator frag_list_const_iterator;
66 // #define FG_MAX_MATERIAL_FRAGS 800
68 // MSVC++ 6.0 kuldge - Need forward declaration of friends.
69 // class FGMaterialSlot;
70 // istream& operator >> ( istream& in, FGMaterialSlot& m );
72 // Material property class
73 class FGMaterialSlot {
78 // OpenGL texture name
81 // file name of texture
82 // string texture_name;
88 // double xsize, ysize;
90 // material properties
91 // GLfloat ambient[4], diffuse[4], specular[4], emissive[4];
94 // transient list of objects with this material type (used for sorting
95 // by material to reduce GL state changes when rendering the scene
102 FGMaterialSlot ( void );
104 int size() const { return list.size(); }
105 bool empty() const { return list.size() == 0; }
108 void init_sort_list( void ) {
109 list.erase( list.begin(), list.end() );
112 bool append_sort_list( fgFRAGMENT *object ) {
113 list.push_back( object );
117 void render_fragments();
119 // void load_texture();
122 ~FGMaterialSlot ( void );
124 // friend istream& operator >> ( istream& in, FGMaterialSlot& m );
126 inline FGMaterial get_m() const { return m; }
127 inline void set_m( FGMaterial new_m ) { m = new_m; }
131 // Material management class
132 class fgMATERIAL_MGR {
136 // associative array of materials
137 typedef map < string, FGMaterialSlot, less<string> > container;
138 typedef container::iterator iterator;
139 typedef container::const_iterator const_iterator;
141 iterator begin() { return material_map.begin(); }
142 const_iterator begin() const { return material_map.begin(); }
144 iterator end() { return material_map.end(); }
145 const_iterator end() const { return material_map.end(); }
148 fgMATERIAL_MGR ( void );
150 // Load a library of material properties
151 int load_lib ( void );
153 inline bool loaded() const { return textures_loaded; }
155 // Initialize the transient list of fragments for each material property
156 void init_transient_material_lists( void );
158 bool find( const string& material, FGMaterialSlot*& mtl_ptr );
160 void render_fragments();
163 ~fgMATERIAL_MGR ( void );
167 // Have textures been loaded
168 bool textures_loaded;
170 container material_map;
175 // global material management class
176 extern fgMATERIAL_MGR material_mgr;
179 #endif // _MATERIALMGR_HXX