Merged 15170:15635 from trunk (no conflicts or even merges)
[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 #ifdef HAVE_CONFIG_H
33 #include <config.h>
34 #endif
35
36 RAS_IPolyMaterial::RAS_IPolyMaterial(const STR_String& texname,
37                                                                          const STR_String& matname,
38                                                                          int tile,
39                                                                          int tilexrep,
40                                                                          int tileyrep,
41                                                                          int mode,
42                                                                          bool transparant,
43                                                                          bool zsort,
44                                                                          int lightlayer,
45                                                                          bool bIsTriangle,
46                                                                          void* clientobject=NULL) :
47
48                 m_texturename(texname),
49                 m_materialname(matname),
50                 m_tile(tile),
51                 m_tilexrep(tilexrep),
52                 m_tileyrep(tileyrep),
53                 m_drawingmode (mode),
54                 m_transparant(transparant),
55                 m_zsort(zsort),
56                 m_lightlayer(lightlayer),
57                 m_bIsTriangle(bIsTriangle),
58                 m_polymatid(m_newpolymatid++),
59                 m_flag(0),
60                 m_multimode(0)
61 {
62         m_shininess = 35.0;
63         m_specular = MT_Vector3(0.5,0.5,0.5);
64         m_specularity = 1.0;
65         m_diffuse = MT_Vector3(0.5,0.5,0.5);
66 }
67
68
69 bool RAS_IPolyMaterial::Equals(const RAS_IPolyMaterial& lhs) const
70 {
71         if(m_flag &RAS_BLENDERMAT)
72         {
73                 return (
74                         this->m_multimode                       ==              lhs.m_multimode &&
75                         this->m_flag                            ==              lhs.m_flag              &&
76                         this->m_drawingmode                     ==              lhs.m_drawingmode &&
77                         this->m_lightlayer                      ==              lhs.m_lightlayer &&
78                         this->m_texturename.hash()      ==              lhs.m_texturename.hash() &&
79                         this->m_materialname.hash() ==          lhs.m_materialname.hash()
80                 );
81         }
82         else
83         {
84                 return (
85                                 this->m_tile            ==              lhs.m_tile &&
86                                 this->m_tilexrep        ==              lhs.m_tilexrep &&
87                                 this->m_tileyrep        ==              lhs.m_tileyrep &&
88                                 this->m_transparant     ==              lhs.m_transparant &&
89                                 this->m_zsort           ==              lhs.m_zsort &&
90                                 this->m_drawingmode     ==              lhs.m_drawingmode &&
91                                 this->m_bIsTriangle     ==              lhs.m_bIsTriangle &&
92                                 this->m_lightlayer      ==              lhs.m_lightlayer &&
93                                 this->m_texturename.hash()      ==              lhs.m_texturename.hash() &&
94                                 this->m_materialname.hash() ==          lhs.m_materialname.hash()
95                 );
96         }
97 }
98
99 bool RAS_IPolyMaterial::Less(const RAS_IPolyMaterial& rhs) const
100 {
101         if (Equals(rhs))
102                 return false;
103                 
104         return m_polymatid < rhs.m_polymatid;
105 }
106
107 int RAS_IPolyMaterial::GetLightLayer() const
108 {
109         return m_lightlayer;
110 }
111
112 bool RAS_IPolyMaterial::IsTransparant() const
113 {
114         return m_transparant;
115 }
116
117 bool RAS_IPolyMaterial::IsZSort() const
118 {
119         return m_zsort;
120 }
121
122 bool RAS_IPolyMaterial::UsesTriangles() const
123 {
124         return m_bIsTriangle;
125 }
126
127 unsigned int RAS_IPolyMaterial::hash() const
128 {
129         return m_texturename.hash();
130 }
131
132 int RAS_IPolyMaterial::GetDrawingMode() const
133 {
134         return m_drawingmode;
135 }
136
137 const STR_String& RAS_IPolyMaterial::GetMaterialName() const
138
139         return m_materialname;
140 }
141
142 const STR_String& RAS_IPolyMaterial::GetTextureName() const
143 {
144         return m_texturename;
145 }
146
147 const unsigned int      RAS_IPolyMaterial::GetFlag() const
148 {
149         return m_flag;
150 }
151
152 bool RAS_IPolyMaterial::UsesLighting(RAS_IRasterizer *rasty) const
153 {
154         bool dolights = false;
155
156         if(m_flag & RAS_BLENDERMAT)
157                 dolights = (m_flag &RAS_MULTILIGHT)!=0;
158         else if(rasty->GetDrawingMode() < RAS_IRasterizer::KX_SOLID);
159         else if(rasty->GetDrawingMode() == RAS_IRasterizer::KX_SHADOW);
160         else
161                 dolights = (m_drawingmode & 16)!=0;
162         
163         return dolights;
164 }
165
166 unsigned int RAS_IPolyMaterial::m_newpolymatid = 0;
167