]> git.mxchange.org Git - flightgear.git/blob - src/Objects/materialmgr.hxx
source tree reorganization prior to flightgear 0.7
[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 "material.hxx"
50
51 FG_USING_STD(string);
52 FG_USING_STD(map);
53 FG_USING_STD(vector);
54 FG_USING_STD(less);
55
56 // forward decl.
57 class fgFRAGMENT;
58
59
60 // convenience types
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;
64
65
66 // #define FG_MAX_MATERIAL_FRAGS 800
67
68 // MSVC++ 6.0 kuldge - Need forward declaration of friends.
69 // class FGMaterialSlot;
70 // istream& operator >> ( istream& in, FGMaterialSlot& m );
71
72 // Material property class
73 class FGMaterialSlot {
74
75 private:
76     FGMaterial m;
77
78     // OpenGL texture name
79     // GLuint texture_id;
80
81     // file name of texture
82     // string texture_name;
83
84     // alpha texture?
85     // int alpha;
86
87     // texture size
88     // double xsize, ysize;
89
90     // material properties
91     // GLfloat ambient[4], diffuse[4], specular[4], emissive[4];
92     // GLint texture_ptr;
93
94     // transient list of objects with this material type (used for sorting
95     // by material to reduce GL state changes when rendering the scene
96     frag_list_type list;
97     // size_t list_size;
98
99 public:
100
101     // Constructor
102     FGMaterialSlot ( void );
103
104     int size() const { return list.size(); }
105     bool empty() const { return list.size() == 0; }
106
107     // Sorting routines
108     void init_sort_list( void ) {
109         list.erase( list.begin(), list.end() );
110     }
111
112     bool append_sort_list( fgFRAGMENT *object ) {
113         list.push_back( object );
114         return true;
115     }
116
117     void render_fragments();
118
119     // void load_texture();
120
121     // Destructor
122     ~FGMaterialSlot ( void );
123
124     // friend istream& operator >> ( istream& in, FGMaterialSlot& m );
125
126     inline FGMaterial get_m() const { return m; }
127     inline void set_m( FGMaterial new_m ) { m = new_m; }
128 };
129
130
131 // Material management class
132 class fgMATERIAL_MGR {
133
134 public:
135
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;
140
141     iterator begin() { return material_map.begin(); }
142     const_iterator begin() const { return material_map.begin(); }
143
144     iterator end() { return material_map.end(); }
145     const_iterator end() const { return material_map.end(); }
146
147     // Constructor
148     fgMATERIAL_MGR ( void );
149
150     // Load a library of material properties
151     int load_lib ( void );
152
153     inline bool loaded() const { return textures_loaded; }
154
155     // Initialize the transient list of fragments for each material property
156     void init_transient_material_lists( void );
157
158     bool find( const string& material, FGMaterialSlot*& mtl_ptr );
159
160     void render_fragments();
161
162     // Destructor
163     ~fgMATERIAL_MGR ( void );
164
165 private:
166
167     // Have textures been loaded
168     bool textures_loaded;
169
170     container material_map;
171
172 };
173
174
175 // global material management class
176 extern fgMATERIAL_MGR material_mgr;
177
178
179 #endif // _MATERIALMGR_HXX 
180
181