]> git.mxchange.org Git - flightgear.git/blob - Objects/material.hxx
Moved from ../Scenery
[flightgear.git] / Objects / material.hxx
1 // material.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 // (Log is kept at end of this file)
23
24
25 #ifndef _MATERIAL_HXX
26 #define _MATERIAL_HXX
27
28
29 #ifndef __cplusplus                                                          
30 # error This library requires C++
31 #endif                                   
32
33 #ifdef HAVE_CONFIG_H
34 #  include <config.h>
35 #endif
36
37 #ifdef HAVE_WINDOWS_H
38 #  include <windows.h>
39 #endif
40
41 #include <GL/glut.h>
42 #include <XGL/xgl.h>
43
44 #if defined ( __sun__ )
45 extern "C" void *memmove(void *, const void *, size_t);
46 extern "C" void *memset(void *, int, size_t);
47 #endif
48
49 #include <string>        // Standard C++ string library
50 #include <map>           // STL associative "array"
51
52 #ifdef NEEDNAMESPACESTD
53 using namespace std;
54 #endif
55
56 #include "fragment.hxx"
57
58
59 #define FG_MAX_MATERIAL_FRAGS 800
60
61
62 // Material property class
63 class fgMATERIAL {
64
65 public:
66     // OpenGL texture name
67     GLuint texture_id;
68
69     // file name of texture
70     char texture_name[256];
71
72     // material properties
73     GLfloat ambient[4], diffuse[4], specular[4], emissive[4];
74     GLint texture_ptr;
75
76     // transient list of objects with this material type (used for sorting
77     // by material to reduce GL state changes when rendering the scene
78     fgFRAGMENT * list[FG_MAX_MATERIAL_FRAGS];
79     int list_size;
80
81     // Constructor
82     fgMATERIAL ( void );
83
84     // Sorting routines
85     void init_sort_list( void );
86     int append_sort_list( fgFRAGMENT *object );
87
88     // Destructor
89     ~fgMATERIAL ( void );
90 };
91
92
93 // Material management class
94 class fgMATERIAL_MGR {
95
96 public:
97
98     // associative array of materials
99     map < string, fgMATERIAL, less<string> > material_map;
100
101     // Constructor
102     fgMATERIAL_MGR ( void );
103
104     // Load a library of material properties
105     int load_lib ( void );
106
107     // Initialize the transient list of fragments for each material property
108     void init_transient_material_lists( void );
109
110     // Destructor
111     ~fgMATERIAL_MGR ( void );
112 };
113
114
115 // global material management class
116 extern fgMATERIAL_MGR material_mgr;
117
118
119 #endif // _MATERIAL_HXX 
120
121
122 // $Log$
123 // Revision 1.1  1998/08/25 16:51:24  curt
124 // Moved from ../Scenery
125 //
126 // Revision 1.10  1998/07/24 21:42:06  curt
127 // material.cxx: whups, double method declaration with no definition.
128 // obj.cxx: tweaks to avoid errors in SGI's CC.
129 // tile.cxx: optimizations by Norman Vine.
130 // tilemgr.cxx: optimizations by Norman Vine.
131 //
132 // Revision 1.9  1998/07/06 21:34:33  curt
133 // Added using namespace std for compilers that support this.
134 //
135 // Revision 1.8  1998/06/17 21:36:39  curt
136 // Load and manage multiple textures defined in the Materials library.
137 // Boost max material fagments for each material property to 800.
138 // Multiple texture support when rendering.
139 //
140 // Revision 1.7  1998/06/12 00:58:04  curt
141 // Build only static libraries.
142 // Declare memmove/memset for Sloaris.
143 //
144 // Revision 1.6  1998/06/06 01:09:31  curt
145 // I goofed on the log message in the last commit ... now fixed.
146 //
147 // Revision 1.5  1998/06/06 01:07:17  curt
148 // Increased per material fragment list size from 100 to 400.
149 // Now correctly draw viewable fragments in per material order.
150 //
151 // Revision 1.4  1998/06/05 22:39:53  curt
152 // Working on sorting by, and rendering by material properties.
153 //
154 // Revision 1.3  1998/06/03 00:47:50  curt
155 // No .h for STL includes.
156 // Minor view culling optimizations.
157 //
158 // Revision 1.2  1998/06/01 17:56:20  curt
159 // Incremental additions to material.cxx (not fully functional)
160 // Tweaked vfc_ratio math to avoid divide by zero.
161 //
162 // Revision 1.1  1998/05/30 01:56:45  curt
163 // Added material.cxx material.hxx
164 //