Blender  V2.59
RAS_IPolygonMaterial.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: RAS_IPolygonMaterial.cpp 35390 2011-03-07 19:14:17Z dfelinto $
00003  * ***** BEGIN GPL LICENSE BLOCK *****
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software Foundation,
00017  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018  *
00019  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00020  * All rights reserved.
00021  *
00022  * The Original Code is: all of this file.
00023  *
00024  * Contributor(s): none yet.
00025  *
00026  * ***** END GPL LICENSE BLOCK *****
00027  */
00028 
00034 #include "RAS_IPolygonMaterial.h"
00035 #include "RAS_IRasterizer.h"
00036 
00037 #include "DNA_image_types.h"
00038 #include "DNA_meshdata_types.h"
00039 
00040 void  RAS_IPolyMaterial::Initialize( 
00041                                 const STR_String& texname,
00042                                 const STR_String& matname,
00043                                 int materialindex,
00044                                 int tile,
00045                                 int tilexrep,
00046                                 int tileyrep,
00047                                 int mode,
00048                                 int transp,
00049                                 bool alpha,
00050                                 bool zsort)
00051 {
00052         m_texturename = texname;
00053         m_materialname = matname;
00054         m_materialindex = materialindex;
00055         m_tile = tile;
00056         m_tilexrep = tilexrep;
00057         m_tileyrep = tileyrep;
00058         m_drawingmode = mode;
00059         m_transp = transp;
00060         m_alpha = alpha;
00061         m_zsort = zsort;
00062         m_polymatid = m_newpolymatid++;
00063         m_flag = 0;
00064         m_multimode = 0;
00065         m_shininess = 35.0;
00066         m_specular.setValue(0.5,0.5,0.5);
00067         m_specularity = 1.0;
00068         m_diffuse.setValue(0.5,0.5,0.5);
00069 }
00070 
00071 RAS_IPolyMaterial::RAS_IPolyMaterial() 
00072                 : m_texturename("__Dummy_Texture_Name__"),
00073                 m_materialname("__Dummy_Material_Name__"),
00074                 m_tile(0),
00075                 m_tilexrep(0),
00076                 m_tileyrep(0),
00077                 m_drawingmode (0),
00078                 m_transp(0),
00079                 m_alpha(false),
00080                 m_zsort(false),
00081                 m_materialindex(0),
00082                 m_polymatid(0),
00083                 m_flag(0),
00084                 m_multimode(0)
00085 {
00086         m_shininess = 35.0;
00087         m_specular = MT_Vector3(0.5,0.5,0.5);
00088         m_specularity = 1.0;
00089         m_diffuse = MT_Vector3(0.5,0.5,0.5);
00090 }
00091 
00092 RAS_IPolyMaterial::RAS_IPolyMaterial(const STR_String& texname,
00093                                                                          const STR_String& matname,
00094                                                                          int materialindex,
00095                                                                          int tile,
00096                                                                          int tilexrep,
00097                                                                          int tileyrep,
00098                                                                          int mode,
00099                                                                          int transp,
00100                                                                          bool alpha,
00101                                                                          bool zsort)
00102                 : m_texturename(texname),
00103                 m_materialname(matname),
00104                 m_tile(tile),
00105                 m_tilexrep(tilexrep),
00106                 m_tileyrep(tileyrep),
00107                 m_drawingmode (mode),
00108                 m_transp(transp),
00109                 m_alpha(alpha),
00110                 m_zsort(zsort),
00111                 m_materialindex(materialindex),
00112                 m_polymatid(m_newpolymatid++),
00113                 m_flag(0),
00114                 m_multimode(0)
00115 {
00116         m_shininess = 35.0;
00117         m_specular = MT_Vector3(0.5,0.5,0.5);
00118         m_specularity = 1.0;
00119         m_diffuse = MT_Vector3(0.5,0.5,0.5);
00120 }
00121 
00122 
00123 bool RAS_IPolyMaterial::Equals(const RAS_IPolyMaterial& lhs) const
00124 {
00125         if(m_flag &RAS_BLENDERMAT)
00126         {
00127                 bool test = (
00128                         this->m_multimode                       ==              lhs.m_multimode &&
00129                         this->m_flag                            ==              lhs.m_flag              &&
00130                         this->m_drawingmode                     ==              lhs.m_drawingmode &&
00131                         this->m_transp                          ==              lhs.m_transp &&
00132                         this->m_texturename.hash()      ==              lhs.m_texturename.hash() &&
00133                         this->m_materialname.hash() ==          lhs.m_materialname.hash()
00134                 );
00135 
00136                 return test;
00137         }
00138         else
00139         {
00140                 return (
00141                                 this->m_tile            ==              lhs.m_tile &&
00142                                 this->m_tilexrep        ==              lhs.m_tilexrep &&
00143                                 this->m_tileyrep        ==              lhs.m_tileyrep &&
00144                                 this->m_transp          ==              lhs.m_transp &&
00145                                 this->m_alpha           ==              lhs.m_alpha &&
00146                                 this->m_zsort           ==              lhs.m_zsort &&
00147                                 this->m_drawingmode     ==              lhs.m_drawingmode &&
00148                                 this->m_texturename.hash()      ==              lhs.m_texturename.hash() &&
00149                                 this->m_materialname.hash() ==          lhs.m_materialname.hash()
00150                 );
00151         }
00152 }
00153 
00154 
00155 void RAS_IPolyMaterial::GetMaterialRGBAColor(unsigned char *rgba) const
00156 {
00157         *rgba++ = 0xFF;
00158         *rgba++ = 0xFF;
00159         *rgba++ = 0xFF;
00160         *rgba++ = 0xFF;
00161 }
00162 
00163 bool RAS_IPolyMaterial::Less(const RAS_IPolyMaterial& rhs) const
00164 {
00165         if (Equals(rhs))
00166                 return false;
00167                 
00168         return m_polymatid < rhs.m_polymatid;
00169 }
00170 
00171 bool RAS_IPolyMaterial::IsAlpha() const
00172 {
00173         return m_alpha || m_zsort;
00174 }
00175 
00176 bool RAS_IPolyMaterial::IsZSort() const
00177 {
00178         return m_zsort;
00179 }
00180 
00181 unsigned int RAS_IPolyMaterial::hash() const
00182 {
00183         return m_texturename.hash();
00184 }
00185 
00186 int RAS_IPolyMaterial::GetDrawingMode() const
00187 {
00188         return m_drawingmode;
00189 }
00190 
00191 const STR_String& RAS_IPolyMaterial::GetMaterialName() const
00192 { 
00193         return m_materialname;
00194 }
00195 
00196 dword RAS_IPolyMaterial::GetMaterialNameHash() const
00197 {
00198         return m_materialname.hash();
00199 }
00200 
00201 const STR_String& RAS_IPolyMaterial::GetTextureName() const
00202 {
00203         return m_texturename;
00204 }
00205 
00206 int RAS_IPolyMaterial::GetMaterialIndex() const
00207 {
00208         return m_materialindex;
00209 }
00210 
00211 Material *RAS_IPolyMaterial::GetBlenderMaterial() const
00212 {
00213         return NULL;
00214 }
00215 
00216 Image *RAS_IPolyMaterial::GetBlenderImage() const
00217 {
00218         return NULL;
00219 }
00220 
00221 Scene* RAS_IPolyMaterial::GetBlenderScene() const
00222 {
00223         return NULL;
00224 }
00225 
00226 void RAS_IPolyMaterial::ReleaseMaterial()
00227 {
00228 }
00229 
00230 unsigned int    RAS_IPolyMaterial::GetFlag() const
00231 {
00232         return m_flag;
00233 }
00234 
00235 bool RAS_IPolyMaterial::UsesLighting(RAS_IRasterizer *rasty) const
00236 {
00237         bool dolights = false;
00238 
00239         if(m_flag & RAS_BLENDERMAT)
00240                 dolights = (m_flag &RAS_MULTILIGHT)!=0;
00241         else if(rasty->GetDrawingMode() < RAS_IRasterizer::KX_SOLID);
00242         else if(rasty->GetDrawingMode() == RAS_IRasterizer::KX_SHADOW);
00243         else
00244                 dolights = (m_drawingmode & RAS_IRasterizer::KX_LIGHT)!=0;
00245         
00246         return dolights;
00247 }
00248 
00249 bool RAS_IPolyMaterial::UsesObjectColor() const
00250 {
00251         return !(m_flag & RAS_BLENDERGLSL);
00252 }
00253 
00254 unsigned int RAS_IPolyMaterial::m_newpolymatid = 0;
00255