svn merge -r 13452:14721 https://svn.blender.org/svnroot/bf-blender/trunk/blender
[blender.git] / source / gameengine / Ketsji / KX_BlenderMaterial.h
1 #ifndef __KX_BLENDER_MATERIAL_H__
2 #define __KX_BLENDER_MATERIAL_H__
3
4 #include <vector>
5
6
7 #include "RAS_IPolygonMaterial.h"
8 #include "BL_Material.h"
9 #include "BL_Texture.h"
10 #include "BL_Shader.h"
11
12 #include "PyObjectPlus.h"
13
14 #include "MT_Vector3.h"
15 #include "MT_Vector4.h"
16
17 struct MTFace;
18 class KX_Scene;
19
20 class KX_BlenderMaterial :  public PyObjectPlus, public RAS_IPolyMaterial
21 {
22         Py_Header;
23 public:
24         // --------------------------------
25         KX_BlenderMaterial(
26                 class KX_Scene* scene,
27                 BL_Material*    mat,
28                 bool                    skin,
29                 int                             lightlayer,
30                 void*                   clientobject,
31                 PyTypeObject*   T=&Type
32         );
33
34         virtual ~KX_BlenderMaterial();
35
36         // --------------------------------
37         virtual TCachingInfo GetCachingInfo(void) const {
38                 return (void*) this;
39         }
40
41         virtual 
42         bool Activate(
43                 RAS_IRasterizer* rasty, 
44                 TCachingInfo& cachingInfo
45         ) const;
46         
47         virtual 
48         void ActivateMeshSlot(
49                 const KX_MeshSlot & ms, 
50                 RAS_IRasterizer* rasty 
51         ) const;
52         
53         void ActivateMat(
54                 RAS_IRasterizer* rasty,
55                 TCachingInfo& cachingInfo
56         )const;
57
58         void ActivatShaders(
59                 RAS_IRasterizer* rasty, 
60                 TCachingInfo& cachingInfo
61         )const;
62
63
64         MTFace* GetMTFace(void) const;
65         unsigned int* GetMCol(void) const;
66
67         // for ipos
68         void UpdateIPO(
69                 MT_Vector4 rgba, MT_Vector3 specrgb,
70                 MT_Scalar hard, MT_Scalar spec,
71                 MT_Scalar ref, MT_Scalar emit, MT_Scalar alpha
72         );
73         
74         // --------------------------------
75         virtual PyObject* _getattr(const STR_String& attr);
76         virtual int       _setattr(const STR_String& attr, PyObject *pyvalue);
77
78         KX_PYMETHOD_DOC( KX_BlenderMaterial, getShader );
79         KX_PYMETHOD_DOC( KX_BlenderMaterial, getMaterialIndex );
80         KX_PYMETHOD_DOC( KX_BlenderMaterial, getTexture );
81         KX_PYMETHOD_DOC( KX_BlenderMaterial, setTexture );
82
83         KX_PYMETHOD_DOC( KX_BlenderMaterial, setBlending );
84
85         // --------------------------------
86         // pre calculate to avoid pops/lag at startup
87         virtual void OnConstruction( );
88 private:
89         BL_Material*    mMaterial;
90         BL_Shader*              mShader;
91         KX_Scene*               mScene;
92         BL_Texture              mTextures[MAXTEX];              // texture array
93         bool                    mUserDefBlend;
94         unsigned int    mBlendFunc[2];
95         bool                    mModified;
96         bool                    mConstructed;                   // if false, don't clean on exit
97
98         void ActivatGLMaterials( RAS_IRasterizer* rasty )const;
99         void ActivateTexGen( RAS_IRasterizer *ras ) const;
100
101
102         // message centers
103         void    setTexData( bool enable,RAS_IRasterizer *ras);
104         void    setShaderData( bool enable, RAS_IRasterizer *ras);
105
106         bool    setDefaultBlending();
107         void    setObjectMatrixData(int i, RAS_IRasterizer *ras);
108         void    setTexMatrixData(int i);
109
110         void    setLightData();
111
112         // cleanup stuff
113         void    OnExit();
114
115         mutable int     mPass;
116 };
117
118
119 #endif