6af00d63c2dad98a0b35909e7db54706774c13e8
[blender.git] / source / gameengine / Rasterizer / RAS_IPolygonMaterial.cpp
1 /**
2  * $Id$
3  * ***** BEGIN GPL LICENSE BLOCK *****
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software Foundation,
17  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18  *
19  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20  * All rights reserved.
21  *
22  * The Original Code is: all of this file.
23  *
24  * Contributor(s): none yet.
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include "RAS_IPolygonMaterial.h"
30 #include "RAS_IRasterizer.h"
31
32 #include "DNA_image_types.h"
33 #include "DNA_meshdata_types.h"
34
35 #ifdef HAVE_CONFIG_H
36 #include <config.h>
37 #endif
38
39 void  RAS_IPolyMaterial::Initialize( 
40                                 const STR_String& texname,
41                                 const STR_String& matname,
42                                 int materialindex,
43                                 int tile,
44                                 int tilexrep,
45                                 int tileyrep,
46                                 int mode,
47                                 int transp,
48                                 bool alpha,
49                                 bool zsort,
50                                 int lightlayer)
51 {
52         m_texturename = texname;
53         m_materialname = matname;
54         m_materialindex = materialindex;
55         m_tile = tile;
56         m_tilexrep = tilexrep;
57         m_tileyrep = tileyrep;
58         m_drawingmode = mode;
59         m_transp = transp;
60         m_alpha = alpha;
61         m_zsort = zsort;
62         //m_lightlayer = lightlayer;
63         m_polymatid = m_newpolymatid++;
64         m_flag = 0;
65         m_multimode = 0;
66         m_shininess = 35.0;
67         m_specular.setValue(0.5,0.5,0.5);
68         m_specularity = 1.0;
69         m_diffuse.setValue(0.5,0.5,0.5);
70 }
71
72 RAS_IPolyMaterial::RAS_IPolyMaterial() 
73                 : m_texturename("__Dummy_Texture_Name__"),
74                 m_materialname("__Dummy_Material_Name__"),
75                 m_materialindex(0),
76                 m_tile(0),
77                 m_tilexrep(0),
78                 m_tileyrep(0),
79                 m_drawingmode (0),
80                 m_transp(0),
81                 m_alpha(false),
82                 m_zsort(false),
83                 //m_lightlayer(0),
84                 m_polymatid(0),
85                 m_flag(0),
86                 m_multimode(0)
87 {
88         m_shininess = 35.0;
89         m_specular = MT_Vector3(0.5,0.5,0.5);
90         m_specularity = 1.0;
91         m_diffuse = MT_Vector3(0.5,0.5,0.5);
92 }
93
94 RAS_IPolyMaterial::RAS_IPolyMaterial(const STR_String& texname,
95                                                                          const STR_String& matname,
96                                                                          int materialindex,
97                                                                          int tile,
98                                                                          int tilexrep,
99                                                                          int tileyrep,
100                                                                          int mode,
101                                                                          int transp,
102                                                                          bool alpha,
103                                                                          bool zsort,
104                                                                          int lightlayer)
105                 : m_texturename(texname),
106                 m_materialname(matname),
107                 m_materialindex(materialindex),
108                 m_tile(tile),
109                 m_tilexrep(tilexrep),
110                 m_tileyrep(tileyrep),
111                 m_drawingmode (mode),
112                 m_transp(transp),
113                 m_alpha(alpha),
114                 m_zsort(zsort),
115                 //m_lightlayer(lightlayer),
116                 m_polymatid(m_newpolymatid++),
117                 m_flag(0),
118                 m_multimode(0)
119 {
120         m_shininess = 35.0;
121         m_specular = MT_Vector3(0.5,0.5,0.5);
122         m_specularity = 1.0;
123         m_diffuse = MT_Vector3(0.5,0.5,0.5);
124 }
125
126
127 bool RAS_IPolyMaterial::Equals(const RAS_IPolyMaterial& lhs) const
128 {
129         if(m_flag &RAS_BLENDERMAT)
130         {
131                 bool test = (
132                         this->m_multimode                       ==              lhs.m_multimode &&
133                         this->m_flag                            ==              lhs.m_flag              &&
134                         this->m_drawingmode                     ==              lhs.m_drawingmode &&
135                         this->m_transp                          ==              lhs.m_transp &&
136                         this->m_texturename.hash()      ==              lhs.m_texturename.hash() &&
137                         this->m_materialname.hash() ==          lhs.m_materialname.hash()
138                 );
139
140                 return test;
141         }
142         else
143         {
144                 return (
145                                 this->m_tile            ==              lhs.m_tile &&
146                                 this->m_tilexrep        ==              lhs.m_tilexrep &&
147                                 this->m_tileyrep        ==              lhs.m_tileyrep &&
148                                 this->m_transp          ==              lhs.m_transp &&
149                                 this->m_alpha           ==              lhs.m_alpha &&
150                                 this->m_zsort           ==              lhs.m_zsort &&
151                                 this->m_drawingmode     ==              lhs.m_drawingmode &&
152                                 this->m_texturename.hash()      ==              lhs.m_texturename.hash() &&
153                                 this->m_materialname.hash() ==          lhs.m_materialname.hash()
154                 );
155         }
156 }
157
158
159 void RAS_IPolyMaterial::GetMaterialRGBAColor(unsigned char *rgba) const
160 {
161         *rgba++ = 0xFF;
162         *rgba++ = 0xFF;
163         *rgba++ = 0xFF;
164         *rgba++ = 0xFF;
165 }
166
167 bool RAS_IPolyMaterial::Less(const RAS_IPolyMaterial& rhs) const
168 {
169         if (Equals(rhs))
170                 return false;
171                 
172         return m_polymatid < rhs.m_polymatid;
173 }
174
175 //int RAS_IPolyMaterial::GetLightLayer() const
176 //{
177 //      return m_lightlayer;
178 //}
179
180 bool RAS_IPolyMaterial::IsAlpha() const
181 {
182         return m_alpha || m_zsort;
183 }
184
185 bool RAS_IPolyMaterial::IsZSort() const
186 {
187         return m_zsort;
188 }
189
190 unsigned int RAS_IPolyMaterial::hash() const
191 {
192         return m_texturename.hash();
193 }
194
195 int RAS_IPolyMaterial::GetDrawingMode() const
196 {
197         return m_drawingmode;
198 }
199
200 const STR_String& RAS_IPolyMaterial::GetMaterialName() const
201
202         return m_materialname;
203 }
204
205 dword RAS_IPolyMaterial::GetMaterialNameHash() const
206 {
207         return m_materialname.hash();
208 }
209
210 const STR_String& RAS_IPolyMaterial::GetTextureName() const
211 {
212         return m_texturename;
213 }
214
215 int RAS_IPolyMaterial::GetMaterialIndex() const
216 {
217         return m_materialindex;
218 }
219
220 Material *RAS_IPolyMaterial::GetBlenderMaterial() const
221 {
222         return NULL;
223 }
224
225 Scene* RAS_IPolyMaterial::GetBlenderScene() const
226 {
227         return NULL;
228 }
229
230 void RAS_IPolyMaterial::ReleaseMaterial()
231 {
232 }
233
234 unsigned int    RAS_IPolyMaterial::GetFlag() const
235 {
236         return m_flag;
237 }
238
239 bool RAS_IPolyMaterial::UsesLighting(RAS_IRasterizer *rasty) const
240 {
241         bool dolights = false;
242
243         if(m_flag & RAS_BLENDERMAT)
244                 dolights = (m_flag &RAS_MULTILIGHT)!=0;
245         else if(rasty->GetDrawingMode() < RAS_IRasterizer::KX_SOLID);
246         else if(rasty->GetDrawingMode() == RAS_IRasterizer::KX_SHADOW);
247         else
248                 dolights = (m_drawingmode & 16)!=0;
249         
250         return dolights;
251 }
252
253 bool RAS_IPolyMaterial::UsesObjectColor() const
254 {
255         return !(m_flag & RAS_BLENDERGLSL);
256 }
257
258 unsigned int RAS_IPolyMaterial::m_newpolymatid = 0;
259