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 <ssg.h> // plib include
51 #include "material.hxx"
63 typedef vector < fgFRAGMENT * > frag_list_type;
64 typedef frag_list_type::iterator frag_list_iterator;
65 typedef frag_list_type::const_iterator frag_list_const_iterator;
68 // #define FG_MAX_MATERIAL_FRAGS 800
70 // MSVC++ 6.0 kuldge - Need forward declaration of friends.
71 // class FGMaterialSlot;
72 // istream& operator >> ( istream& in, FGMaterialSlot& m );
74 // Material property class
75 class FGMaterialSlot {
80 // transient list of objects with this material type (used for sorting
81 // by material to reduce GL state changes when rendering the scene
85 // ssg stage structure
86 ssgSimpleState *state;
92 FGMaterialSlot ( void );
94 int size() const { return list.size(); }
95 bool empty() const { return list.size() == 0; }
98 void init_sort_list( void ) {
99 list.erase( list.begin(), list.end() );
102 bool append_sort_list( fgFRAGMENT *object ) {
103 list.push_back( object );
107 void render_fragments();
110 ~FGMaterialSlot ( void );
112 // friend istream& operator >> ( istream& in, FGMaterialSlot& m );
114 inline FGMaterial get_m() const { return m; }
115 inline void set_m( FGMaterial new_m ) { m = new_m; }
118 inline ssgSimpleState *get_state() { return state; }
119 inline void set_state( ssgSimpleState *s ) { state = s; }
120 inline bool get_state_valid() const { return state_valid; }
121 inline void set_state_valid( bool flag ) { state_valid = flag; }
125 // Material management class
126 class fgMATERIAL_MGR {
130 // associative array of materials
131 typedef map < string, FGMaterialSlot, less<string> > container;
132 typedef container::iterator iterator;
133 typedef container::const_iterator const_iterator;
135 iterator begin() { return material_map.begin(); }
136 const_iterator begin() const { return material_map.begin(); }
138 iterator end() { return material_map.end(); }
139 const_iterator end() const { return material_map.end(); }
142 fgMATERIAL_MGR ( void );
144 // Load a library of material properties
145 int load_lib ( void );
147 inline bool loaded() const { return materials_loaded; }
149 // Initialize the transient list of fragments for each material property
150 void init_transient_material_lists( void );
152 bool find( const string& material, FGMaterialSlot*& mtl_ptr );
154 void render_fragments();
157 ~fgMATERIAL_MGR ( void );
161 // Has the material properties lib been loaded
162 bool materials_loaded;
164 container material_map;
169 // global material management class
170 extern fgMATERIAL_MGR material_mgr;
173 #endif // _MATERIALMGR_HXX