Blender  V2.59
RAS_IPolygonMaterial.h
Go to the documentation of this file.
00001 /*
00002  * $Id: RAS_IPolygonMaterial.h 35072 2011-02-22 12:42:55Z jesterking $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00021  * All rights reserved.
00022  *
00023  * The Original Code is: all of this file.
00024  *
00025  * Contributor(s): none yet.
00026  *
00027  * ***** END GPL LICENSE BLOCK *****
00028  */
00029 
00034 #ifndef __RAS_IPOLYGONMATERIAL
00035 #define __RAS_IPOLYGONMATERIAL
00036 
00037 #include "STR_HashedString.h"
00038 
00039 #include "MT_Vector3.h"
00040 #include "STR_HashedString.h"
00041 
00042 #ifdef WITH_CXX_GUARDEDALLOC
00043 #include "MEM_guardedalloc.h"
00044 #endif
00045 
00046 class RAS_IRasterizer;
00047 struct MTFace;
00048 struct Material;
00049 struct Image;
00050 struct Scene;
00051 class SCA_IScene;
00052 
00053 enum MaterialProps
00054 {
00055         RAS_ZSORT               =1,
00056         RAS_TRANSPARENT =2,
00057         RAS_TRIANGLE    =4,
00058         RAS_MULTITEX    =8,
00059         RAS_MULTILIGHT  =16,
00060         RAS_BLENDERMAT  =32,
00061         RAS_GLSHADER    =64,
00062         RAS_AUTOGEN             =128,
00063         RAS_NORMAL              =256,
00064         RAS_DEFMULTI    =512,
00065         RAS_BLENDERGLSL =1024
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;  // tface->mode
00081         int                                             m_transp;
00082         bool                                    m_alpha;
00083         bool                                    m_zsort;
00084         int                                             m_materialindex;
00085         
00086         unsigned int                    m_polymatid;
00087         static unsigned int             m_newpolymatid;
00088 
00089         // will move...
00090         unsigned int                    m_flag;//MaterialProps
00091         int                                             m_multimode; // sum of values
00092 public:
00093         MT_Vector3                      m_diffuse;
00094         float                           m_shininess;
00095         MT_Vector3                      m_specular;
00096         float                           m_specularity;
00097         
00099         typedef void* TCachingInfo;
00100 
00101         // care! these are taken from blender polygonflags, see file DNA_mesh_types.h for #define TF_BILLBOARD etc.
00102         enum MaterialFlags
00103         {
00104                 BILLBOARD_SCREENALIGNED = 256,
00105                 BILLBOARD_AXISALIGNED = 4096,
00106                 SHADOW                            =8192
00107         };
00108 
00109         RAS_IPolyMaterial();
00110         RAS_IPolyMaterial(const STR_String& texname,
00111                                           const STR_String& matname,
00112                                           int materialindex,
00113                                           int tile,
00114                                           int tilexrep,
00115                                           int tileyrep,
00116                                           int mode,
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 mode,
00127                                         int transp,
00128                                         bool alpha,
00129                                         bool zsort);
00130         virtual ~RAS_IPolyMaterial() {};
00131  
00137         virtual TCachingInfo GetCachingInfo(void) const { return 0; }
00138 
00146         virtual bool Activate(RAS_IRasterizer* rasty, TCachingInfo& cachingInfo) const 
00147         { 
00148                 return false; 
00149         }
00150         virtual void ActivateMeshSlot(const class RAS_MeshSlot & ms, RAS_IRasterizer* rasty) const {}
00151 
00152         virtual bool                            Equals(const RAS_IPolyMaterial& lhs) const;
00153         bool                            Less(const RAS_IPolyMaterial& rhs) const;
00154         //int                                   GetLightLayer() const;
00155         bool                            IsAlpha() const;
00156         bool                            IsZSort() const;
00157         unsigned int            hash() const;
00158         int                                     GetDrawingMode() const;
00159         const STR_String&       GetMaterialName() const;
00160         dword                           GetMaterialNameHash() const;
00161         const STR_String&       GetTextureName() const;
00162         unsigned int            GetFlag() const;
00163         int                                     GetMaterialIndex() const;
00164 
00165         virtual Material*   GetBlenderMaterial() const;
00166         virtual Image*      GetBlenderImage() const;
00167         virtual Scene*          GetBlenderScene() const;
00168         virtual void            ReleaseMaterial();
00169         virtual void            GetMaterialRGBAColor(unsigned char *rgba) const;
00170         virtual bool            UsesLighting(RAS_IRasterizer *rasty) const;
00171         virtual bool            UsesObjectColor() const;
00172 
00173         virtual void            Replace_IScene(SCA_IScene *val) {}; /* overridden by KX_BlenderMaterial */
00174 
00175         /*
00176          * PreCalculate texture gen
00177          */
00178         virtual void OnConstruction(int layer){}
00179                 
00180                 
00181 #ifdef WITH_CXX_GUARDEDALLOC
00182 public:
00183         void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:RAS_IPolyMaterial"); }
00184         void operator delete( void *mem ) { MEM_freeN(mem); }
00185 #endif
00186 };
00187 
00188 inline  bool operator ==( const RAS_IPolyMaterial & rhs,const RAS_IPolyMaterial & lhs)
00189 {
00190         return ( rhs.Equals(lhs));
00191 }
00192 
00193 inline  bool operator < ( const RAS_IPolyMaterial & lhs, const RAS_IPolyMaterial & rhs)
00194 {
00195         return lhs.Less(rhs);
00196 }
00197 
00198 #endif //__RAS_IPOLYGONMATERIAL
00199