Blender V2.61 - r43446

RAS_IPolygonMaterial.h

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 
00032 #ifndef __RAS_IPOLYGONMATERIAL
00033 #define __RAS_IPOLYGONMATERIAL
00034 
00035 #include "STR_HashedString.h"
00036 
00037 #include "MT_Vector3.h"
00038 #include "STR_HashedString.h"
00039 
00040 #ifdef WITH_CXX_GUARDEDALLOC
00041 #include "MEM_guardedalloc.h"
00042 #endif
00043 
00044 class RAS_IRasterizer;
00045 struct MTFace;
00046 struct Material;
00047 struct Image;
00048 struct Scene;
00049 class SCA_IScene;
00050 struct GameSettings;
00051 
00052 enum MaterialProps
00053 {
00054     RAS_ZSORT       =1,
00055     RAS_TRANSPARENT =2,
00056     RAS_TRIANGLE    =4,
00057     RAS_MULTITEX    =8,
00058     RAS_MULTILIGHT  =16,
00059     RAS_BLENDERMAT  =32,
00060     RAS_GLSHADER    =64,
00061     RAS_AUTOGEN     =128,
00062     RAS_NORMAL      =256,
00063     RAS_DEFMULTI    =512,
00064     RAS_BLENDERGLSL =1024,
00065     RAS_CASTSHADOW  =2048
00066 };
00067 
00072 class RAS_IPolyMaterial
00073 {
00074     //todo: remove these variables from this interface/protocol class
00075 protected:
00076     STR_HashedString        m_texturename;
00077     STR_HashedString        m_materialname; //also needed for touchsensor  
00078     int                     m_tile;
00079     int                     m_tilexrep,m_tileyrep;
00080     int                     m_drawingmode;
00081     int                     m_alphablend;
00082     bool                    m_alpha;
00083     bool                    m_zsort;
00084     bool                    m_light;
00085     int                     m_materialindex;
00086     
00087     unsigned int            m_polymatid;
00088     static unsigned int     m_newpolymatid;
00089 
00090     // will move...
00091     unsigned int            m_flag;//MaterialProps
00092     int                     m_multimode; // sum of values
00093 public:
00094     MT_Vector3          m_diffuse;
00095     float               m_shininess;
00096     MT_Vector3          m_specular;
00097     float               m_specularity;
00098     
00100     typedef void* TCachingInfo;
00101 
00102     // care! these are taken from blender polygonflags, see file DNA_mesh_types.h for #define TF_BILLBOARD etc.
00103     enum MaterialFlags
00104     {
00105         BILLBOARD_SCREENALIGNED = 512,  /* GEMAT_HALO */
00106         BILLBOARD_AXISALIGNED   = 1024, /* GEMAT_BILLBOARD */
00107         SHADOW          =2048   /* GEMAT_SHADOW */
00108     };
00109 
00110     RAS_IPolyMaterial();
00111     RAS_IPolyMaterial(const STR_String& texname,
00112                       const STR_String& matname,
00113                       int materialindex,
00114                       int tile,
00115                       int tilexrep,
00116                       int tileyrep,
00117                       int transp,
00118                       bool alpha,
00119                       bool zsort);
00120     void Initialize(const STR_String& texname,
00121                     const STR_String& matname,
00122                     int materialindex,
00123                     int tile,
00124                     int tilexrep,
00125                     int tileyrep,
00126                     int transp,
00127                     bool alpha,
00128                     bool zsort,
00129                     bool light,
00130                     bool image,
00131                     struct GameSettings* game);
00132 
00133     virtual ~RAS_IPolyMaterial() {};
00134  
00140     virtual TCachingInfo GetCachingInfo(void) const { return 0; }
00141 
00149     virtual bool Activate(RAS_IRasterizer* rasty, TCachingInfo& cachingInfo) const 
00150     { 
00151         return false; 
00152     }
00153     virtual void ActivateMeshSlot(const class RAS_MeshSlot & ms, RAS_IRasterizer* rasty) const {}
00154 
00155     virtual bool                Equals(const RAS_IPolyMaterial& lhs) const;
00156     bool                Less(const RAS_IPolyMaterial& rhs) const;
00157     //int                   GetLightLayer() const;
00158     bool                IsAlpha() const;
00159     bool                IsZSort() const;
00160     unsigned int        hash() const;
00161     int                 GetDrawingMode() const;
00162     const STR_String&   GetMaterialName() const;
00163     dword               GetMaterialNameHash() const;
00164     const STR_String&   GetTextureName() const;
00165     unsigned int        GetFlag() const;
00166     int                 GetMaterialIndex() const;
00167 
00168     virtual Material*   GetBlenderMaterial() const;
00169     virtual Image*      GetBlenderImage() const;
00170     virtual Scene*      GetBlenderScene() const;
00171     virtual void        ReleaseMaterial();
00172     virtual void        GetMaterialRGBAColor(unsigned char *rgba) const;
00173     virtual bool        UsesLighting(RAS_IRasterizer *rasty) const;
00174     virtual bool        UsesObjectColor() const;
00175     virtual bool        CastsShadows() const;
00176 
00177     virtual void        Replace_IScene(SCA_IScene *val) {}; /* overridden by KX_BlenderMaterial */
00178 
00182     int                 ConvertFaceMode(struct GameSettings *game, bool image) const;
00183 
00184     /*
00185      * PreCalculate texture gen
00186      */
00187     virtual void OnConstruction(int layer){}
00188         
00189         
00190 #ifdef WITH_CXX_GUARDEDALLOC
00191 public:
00192     void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:RAS_IPolyMaterial"); }
00193     void operator delete( void *mem ) { MEM_freeN(mem); }
00194 #endif
00195 };
00196 
00197 inline  bool operator ==( const RAS_IPolyMaterial & rhs,const RAS_IPolyMaterial & lhs)
00198 {
00199     return ( rhs.Equals(lhs));
00200 }
00201 
00202 inline  bool operator < ( const RAS_IPolyMaterial & lhs, const RAS_IPolyMaterial & rhs)
00203 {
00204     return lhs.Less(rhs);
00205 }
00206 
00207 #endif //__RAS_IPOLYGONMATERIAL
00208