doxygen: prevent GPL license block from being parsed as doxygen comment.
[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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 void  RAS_IPolyMaterial::Initialize( 
36                                 const STR_String& texname,
37                                 const STR_String& matname,
38                                 int materialindex,
39                                 int tile,
40                                 int tilexrep,
41                                 int tileyrep,
42                                 int mode,
43                                 int transp,
44                                 bool alpha,
45                                 bool zsort)
46 {
47         m_texturename = texname;
48         m_materialname = matname;
49         m_materialindex = materialindex;
50         m_tile = tile;
51         m_tilexrep = tilexrep;
52         m_tileyrep = tileyrep;
53         m_drawingmode = mode;
54         m_transp = transp;
55         m_alpha = alpha;
56         m_zsort = zsort;
57         m_polymatid = m_newpolymatid++;
58         m_flag = 0;
59         m_multimode = 0;
60         m_shininess = 35.0;
61         m_specular.setValue(0.5,0.5,0.5);
62         m_specularity = 1.0;
63         m_diffuse.setValue(0.5,0.5,0.5);
64 }
65
66 RAS_IPolyMaterial::RAS_IPolyMaterial() 
67                 : m_texturename("__Dummy_Texture_Name__"),
68                 m_materialname("__Dummy_Material_Name__"),
69                 m_tile(0),
70                 m_tilexrep(0),
71                 m_tileyrep(0),
72                 m_drawingmode (0),
73                 m_transp(0),
74                 m_alpha(false),
75                 m_zsort(false),
76                 m_materialindex(0),
77                 m_polymatid(0),
78                 m_flag(0),
79                 m_multimode(0)
80 {
81         m_shininess = 35.0;
82         m_specular = MT_Vector3(0.5,0.5,0.5);
83         m_specularity = 1.0;
84         m_diffuse = MT_Vector3(0.5,0.5,0.5);
85 }
86
87 RAS_IPolyMaterial::RAS_IPolyMaterial(const STR_String& texname,
88                                                                          const STR_String& matname,
89                                                                          int materialindex,
90                                                                          int tile,
91                                                                          int tilexrep,
92                                                                          int tileyrep,
93                                                                          int mode,
94                                                                          int transp,
95                                                                          bool alpha,
96                                                                          bool zsort)
97                 : m_texturename(texname),
98                 m_materialname(matname),
99                 m_tile(tile),
100                 m_tilexrep(tilexrep),
101                 m_tileyrep(tileyrep),
102                 m_drawingmode (mode),
103                 m_transp(transp),
104                 m_alpha(alpha),
105                 m_zsort(zsort),
106                 m_materialindex(materialindex),
107                 m_polymatid(m_newpolymatid++),
108                 m_flag(0),
109                 m_multimode(0)
110 {
111         m_shininess = 35.0;
112         m_specular = MT_Vector3(0.5,0.5,0.5);
113         m_specularity = 1.0;
114         m_diffuse = MT_Vector3(0.5,0.5,0.5);
115 }
116
117
118 bool RAS_IPolyMaterial::Equals(const RAS_IPolyMaterial& lhs) const
119 {
120         if(m_flag &RAS_BLENDERMAT)
121         {
122                 bool test = (
123                         this->m_multimode                       ==              lhs.m_multimode &&
124                         this->m_flag                            ==              lhs.m_flag              &&
125                         this->m_drawingmode                     ==              lhs.m_drawingmode &&
126                         this->m_transp                          ==              lhs.m_transp &&
127                         this->m_texturename.hash()      ==              lhs.m_texturename.hash() &&
128                         this->m_materialname.hash() ==          lhs.m_materialname.hash()
129                 );
130
131                 return test;
132         }
133         else
134         {
135                 return (
136                                 this->m_tile            ==              lhs.m_tile &&
137                                 this->m_tilexrep        ==              lhs.m_tilexrep &&
138                                 this->m_tileyrep        ==              lhs.m_tileyrep &&
139                                 this->m_transp          ==              lhs.m_transp &&
140                                 this->m_alpha           ==              lhs.m_alpha &&
141                                 this->m_zsort           ==              lhs.m_zsort &&
142                                 this->m_drawingmode     ==              lhs.m_drawingmode &&
143                                 this->m_texturename.hash()      ==              lhs.m_texturename.hash() &&
144                                 this->m_materialname.hash() ==          lhs.m_materialname.hash()
145                 );
146         }
147 }
148
149
150 void RAS_IPolyMaterial::GetMaterialRGBAColor(unsigned char *rgba) const
151 {
152         *rgba++ = 0xFF;
153         *rgba++ = 0xFF;
154         *rgba++ = 0xFF;
155         *rgba++ = 0xFF;
156 }
157
158 bool RAS_IPolyMaterial::Less(const RAS_IPolyMaterial& rhs) const
159 {
160         if (Equals(rhs))
161                 return false;
162                 
163         return m_polymatid < rhs.m_polymatid;
164 }
165
166 bool RAS_IPolyMaterial::IsAlpha() const
167 {
168         return m_alpha || m_zsort;
169 }
170
171 bool RAS_IPolyMaterial::IsZSort() const
172 {
173         return m_zsort;
174 }
175
176 unsigned int RAS_IPolyMaterial::hash() const
177 {
178         return m_texturename.hash();
179 }
180
181 int RAS_IPolyMaterial::GetDrawingMode() const
182 {
183         return m_drawingmode;
184 }
185
186 const STR_String& RAS_IPolyMaterial::GetMaterialName() const
187
188         return m_materialname;
189 }
190
191 dword RAS_IPolyMaterial::GetMaterialNameHash() const
192 {
193         return m_materialname.hash();
194 }
195
196 const STR_String& RAS_IPolyMaterial::GetTextureName() const
197 {
198         return m_texturename;
199 }
200
201 int RAS_IPolyMaterial::GetMaterialIndex() const
202 {
203         return m_materialindex;
204 }
205
206 Material *RAS_IPolyMaterial::GetBlenderMaterial() const
207 {
208         return NULL;
209 }
210
211 Image *RAS_IPolyMaterial::GetBlenderImage() const
212 {
213         return NULL;
214 }
215
216 Scene* RAS_IPolyMaterial::GetBlenderScene() const
217 {
218         return NULL;
219 }
220
221 void RAS_IPolyMaterial::ReleaseMaterial()
222 {
223 }
224
225 unsigned int    RAS_IPolyMaterial::GetFlag() const
226 {
227         return m_flag;
228 }
229
230 bool RAS_IPolyMaterial::UsesLighting(RAS_IRasterizer *rasty) const
231 {
232         bool dolights = false;
233
234         if(m_flag & RAS_BLENDERMAT)
235                 dolights = (m_flag &RAS_MULTILIGHT)!=0;
236         else if(rasty->GetDrawingMode() < RAS_IRasterizer::KX_SOLID);
237         else if(rasty->GetDrawingMode() == RAS_IRasterizer::KX_SHADOW);
238         else
239                 dolights = (m_drawingmode & 16)!=0;
240         
241         return dolights;
242 }
243
244 bool RAS_IPolyMaterial::UsesObjectColor() const
245 {
246         return !(m_flag & RAS_BLENDERGLSL);
247 }
248
249 unsigned int RAS_IPolyMaterial::m_newpolymatid = 0;
250