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 <simgear/compiler.h>
43 #include <simgear/xgl/xgl.h>
45 #include STL_STRING // Standard C++ string library
46 #include <map> // STL associative "array"
47 #include <vector> // STL "array"
49 #include <plib/ssg.h> // plib include
51 #include "material.hxx"
52 #include "fragment.hxx"
64 typedef vector < fgFRAGMENT * > frag_list_type;
65 typedef frag_list_type::iterator frag_list_iterator;
66 typedef frag_list_type::const_iterator frag_list_const_iterator;
69 // #define FG_MAX_MATERIAL_FRAGS 800
71 // MSVC++ 6.0 kuldge - Need forward declaration of friends.
72 // class FGMaterialSlot;
73 // istream& operator >> ( istream& in, FGMaterialSlot& m );
75 // Material property class
76 class FGMaterialSlot {
81 // transient list of objects with this material type (used for sorting
82 // by material to reduce GL state changes when rendering the scene
86 // ssg stage structure
87 ssgStateSelector *state;
93 FGMaterialSlot ( void );
95 int size() const { return list.size(); }
96 bool empty() const { return list.size() == 0; }
99 void init_sort_list( void ) {
100 list.erase( list.begin(), list.end() );
103 bool append_sort_list( fgFRAGMENT *object ) {
104 list.push_back( object );
108 // void render_fragments();
111 ~FGMaterialSlot ( void );
113 // friend istream& operator >> ( istream& in, FGMaterialSlot& m );
115 inline FGMaterial get_m() const { return m; }
116 inline void set_m( FGMaterial new_m ) { m = new_m; }
119 inline ssgStateSelector *get_state() { return state; }
120 inline void set_state( ssgStateSelector *s ) { state = s; }
121 inline bool get_state_valid() const { return state_valid; }
122 inline void set_state_valid( bool flag ) { state_valid = flag; }
126 // Material management class
127 class fgMATERIAL_MGR {
131 // associative array of materials
132 typedef map < string, FGMaterialSlot, less<string> > container;
133 typedef container::iterator iterator;
134 typedef container::const_iterator const_iterator;
136 iterator begin() { return material_map.begin(); }
137 const_iterator begin() const { return material_map.begin(); }
139 iterator end() { return material_map.end(); }
140 const_iterator end() const { return material_map.end(); }
143 fgMATERIAL_MGR ( void );
145 // Load a library of material properties
146 int load_lib ( void );
148 inline bool loaded() const { return materials_loaded; }
150 // Initialize the transient list of fragments for each material property
151 void init_transient_material_lists( void );
153 bool find( const string& material, FGMaterialSlot*& mtl_ptr );
155 // void render_fragments();
157 void set_step (int step);
160 ~fgMATERIAL_MGR ( void );
164 // Has the material properties lib been loaded
165 bool materials_loaded;
167 container material_map;
172 // global material management class
173 extern fgMATERIAL_MGR material_mgr;
176 #endif // _MATERIALMGR_HXX