]> git.mxchange.org Git - flightgear.git/blob - src/Objects/materialmgr.hxx
Lighting/ssgSimpleState fixes.
[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 "Include/compiler.h"
41
42 #include <GL/glut.h>
43 #include <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 <ssg.h>                // plib include
50
51 #include "material.hxx"
52
53 FG_USING_STD(string);
54 FG_USING_STD(map);
55 FG_USING_STD(vector);
56 FG_USING_STD(less);
57
58 // forward decl.
59 class fgFRAGMENT;
60
61
62 // convenience types
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;
66
67
68 // #define FG_MAX_MATERIAL_FRAGS 800
69
70 // MSVC++ 6.0 kuldge - Need forward declaration of friends.
71 // class FGMaterialSlot;
72 // istream& operator >> ( istream& in, FGMaterialSlot& m );
73
74 // Material property class
75 class FGMaterialSlot {
76
77 private:
78     FGMaterial m;
79
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     frag_list_type list;
83     // size_t list_size;
84
85     // ssg stage structure
86     ssgSimpleState *state;
87     bool state_valid;
88
89 public:
90
91     // Constructor
92     FGMaterialSlot ( void );
93
94     int size() const { return list.size(); }
95     bool empty() const { return list.size() == 0; }
96
97     // Sorting routines
98     void init_sort_list( void ) {
99         list.erase( list.begin(), list.end() );
100     }
101
102     bool append_sort_list( fgFRAGMENT *object ) {
103         list.push_back( object );
104         return true;
105     }
106
107     void render_fragments();
108
109     // Destructor
110     ~FGMaterialSlot ( void );
111
112     // friend istream& operator >> ( istream& in, FGMaterialSlot& m );
113
114     inline FGMaterial get_m() const { return m; }
115     inline void set_m( FGMaterial new_m ) { m = new_m; }
116
117     // ssg state
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; }
122 };
123
124
125 // Material management class
126 class fgMATERIAL_MGR {
127
128 public:
129
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;
134
135     iterator begin() { return material_map.begin(); }
136     const_iterator begin() const { return material_map.begin(); }
137
138     iterator end() { return material_map.end(); }
139     const_iterator end() const { return material_map.end(); }
140
141     // Constructor
142     fgMATERIAL_MGR ( void );
143
144     // Load a library of material properties
145     int load_lib ( void );
146
147     inline bool loaded() const { return materials_loaded; }
148
149     // Initialize the transient list of fragments for each material property
150     void init_transient_material_lists( void );
151
152     bool find( const string& material, FGMaterialSlot*& mtl_ptr );
153
154     void render_fragments();
155
156     // Destructor
157     ~fgMATERIAL_MGR ( void );
158
159 private:
160
161     // Has the material properties lib been loaded
162     bool materials_loaded;
163
164     container material_map;
165
166 };
167
168
169 // global material management class
170 extern fgMATERIAL_MGR material_mgr;
171
172
173 #endif // _MATERIALMGR_HXX 
174
175