Blender V2.61 - r43446

RAS_IPolygonMaterial.cpp

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