]> git.mxchange.org Git - flightgear.git/blob - src/Objects/materialmgr.hxx
Replaced Durk's mymath.* with plib/sg.h (contributed by Durk).
[flightgear.git] / src / Objects / materialmgr.hxx
1 // materialmgr.hxx -- class to handle material properties
2 //
3 // Written by Curtis Olson, started May 1998.
4 //
5 // Copyright (C) 1998  Curtis L. Olson  - curt@me.umn.edu
6 //
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.
11 //
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.
16 //
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.
20 //
21 // $Id$
22
23
24 #ifndef _MATERIALMGR_HXX
25 #define _MATERIALMGR_HXX
26
27
28 #ifndef __cplusplus                                                          
29 # error This library requires C++
30 #endif                                   
31
32 #ifdef HAVE_CONFIG_H
33 #  include <config.h>
34 #endif
35
36 #ifdef HAVE_WINDOWS_H
37 #  include <windows.h>
38 #endif
39
40 #include <simgear/compiler.h>
41
42 #include <GL/glut.h>
43 #include <simgear/xgl/xgl.h>
44
45 #include STL_STRING             // Standard C++ string library
46 #include <map>                  // STL associative "array"
47 #include <vector>               // STL "array"
48
49 #include <plib/ssg.h>           // plib include
50
51 #include "material.hxx"
52 #include "fragment.hxx"
53
54 FG_USING_STD(string);
55 FG_USING_STD(map);
56 FG_USING_STD(vector);
57 FG_USING_STD(less);
58
59 // forward decl.
60 class fgFRAGMENT;
61
62
63 // convenience types
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;
67
68
69 // #define FG_MAX_MATERIAL_FRAGS 800
70
71 // MSVC++ 6.0 kuldge - Need forward declaration of friends.
72 // class FGMaterialSlot;
73 // istream& operator >> ( istream& in, FGMaterialSlot& m );
74
75 // Material property class
76 class FGMaterialSlot {
77
78 private:
79     FGMaterial m;
80
81     // transient list of objects with this material type (used for sorting
82     // by material to reduce GL state changes when rendering the scene
83     frag_list_type list;
84     // size_t list_size;
85
86     // ssg stage structure
87     ssgStateSelector *state;
88     bool state_valid;
89
90 public:
91
92     // Constructor
93     FGMaterialSlot ( void );
94
95     int size() const { return list.size(); }
96     bool empty() const { return list.size() == 0; }
97
98     // Sorting routines
99     void init_sort_list( void ) {
100         list.erase( list.begin(), list.end() );
101     }
102
103     bool append_sort_list( fgFRAGMENT *object ) {
104         list.push_back( object );
105         return true;
106     }
107
108     // void render_fragments();
109
110     // Destructor
111     ~FGMaterialSlot ( void );
112
113     // friend istream& operator >> ( istream& in, FGMaterialSlot& m );
114
115     inline FGMaterial get_m() const { return m; }
116     inline void set_m( FGMaterial new_m ) { m = new_m; }
117
118     // ssg state
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; }
123 };
124
125
126 // Material management class
127 class fgMATERIAL_MGR {
128
129 public:
130
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;
135
136     iterator begin() { return material_map.begin(); }
137     const_iterator begin() const { return material_map.begin(); }
138
139     iterator end() { return material_map.end(); }
140     const_iterator end() const { return material_map.end(); }
141
142     // Constructor
143     fgMATERIAL_MGR ( void );
144
145     // Load a library of material properties
146     int load_lib ( void );
147
148     inline bool loaded() const { return materials_loaded; }
149
150     // Initialize the transient list of fragments for each material property
151     void init_transient_material_lists( void );
152
153     bool find( const string& material, FGMaterialSlot*& mtl_ptr );
154
155     // void render_fragments();
156
157     void set_step (int step);
158
159     // Destructor
160     ~fgMATERIAL_MGR ( void );
161
162 private:
163
164     // Has the material properties lib been loaded
165     bool materials_loaded;
166
167     container material_map;
168
169 };
170
171
172 // global material management class
173 extern fgMATERIAL_MGR material_mgr;
174
175
176 #endif // _MATERIALMGR_HXX 
177
178