Merge from trunk 16122-16307
[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 #include "BL_BlenderShader.h"
12
13 #include "PyObjectPlus.h"
14
15 #include "MT_Vector3.h"
16 #include "MT_Vector4.h"
17
18 struct MTFace;
19 class KX_Scene;
20
21 class KX_BlenderMaterial :  public PyObjectPlus, public RAS_IPolyMaterial
22 {
23         Py_Header;
24 public:
25         // --------------------------------
26         KX_BlenderMaterial(
27                 class KX_Scene* scene,
28                 BL_Material*    mat,
29                 bool                    skin,
30                 int                             lightlayer,
31                 void*                   clientobject,
32                 PyTypeObject*   T=&Type
33         );
34
35         virtual ~KX_BlenderMaterial();
36
37         // --------------------------------
38         virtual TCachingInfo GetCachingInfo(void) const {
39                 return (void*) this;
40         }
41
42         virtual 
43         bool Activate(
44                 RAS_IRasterizer* rasty, 
45                 TCachingInfo& cachingInfo
46         ) const;
47         
48         virtual 
49         void ActivateMeshSlot(
50                 const KX_MeshSlot & ms, 
51                 RAS_IRasterizer* rasty 
52         ) const;
53         
54         void ActivateMat(
55                 RAS_IRasterizer* rasty,
56                 TCachingInfo& cachingInfo
57         )const;
58
59         void ActivatShaders(
60                 RAS_IRasterizer* rasty, 
61                 TCachingInfo& cachingInfo
62         )const;
63
64         void ActivateBlenderShaders(
65                 RAS_IRasterizer* rasty, 
66                 TCachingInfo& cachingInfo
67         )const;
68
69         MTFace* GetMTFace(void) const;
70         unsigned int* GetMCol(void) const;
71
72         // for ipos
73         void UpdateIPO(
74                 MT_Vector4 rgba, MT_Vector3 specrgb,
75                 MT_Scalar hard, MT_Scalar spec,
76                 MT_Scalar ref, MT_Scalar emit, MT_Scalar alpha
77         );
78         
79         // --------------------------------
80         virtual PyObject* _getattr(const STR_String& attr);
81         virtual int       _setattr(const STR_String& attr, PyObject *pyvalue);
82
83         KX_PYMETHOD_DOC( KX_BlenderMaterial, getShader );
84         KX_PYMETHOD_DOC( KX_BlenderMaterial, getMaterialIndex );
85         KX_PYMETHOD_DOC( KX_BlenderMaterial, getTexture );
86         KX_PYMETHOD_DOC( KX_BlenderMaterial, setTexture );
87
88         KX_PYMETHOD_DOC( KX_BlenderMaterial, setBlending );
89
90         // --------------------------------
91         // pre calculate to avoid pops/lag at startup
92         virtual void OnConstruction( );
93
94         static void     EndFrame();
95
96 private:
97         BL_Material*            mMaterial;
98         BL_Shader*                      mShader;
99         BL_BlenderShader*       mBlenderShader;
100         KX_Scene*               mScene;
101         BL_Texture              mTextures[MAXTEX];              // texture array
102         bool                    mUserDefBlend;
103         unsigned int    mBlendFunc[2];
104         bool                    mModified;
105         bool                    mConstructed;                   // if false, don't clean on exit
106
107         void SetBlenderGLSLShader();
108
109         void ActivatGLMaterials( RAS_IRasterizer* rasty )const;
110         void ActivateTexGen( RAS_IRasterizer *ras ) const;
111
112         bool UsesLighting(RAS_IRasterizer *rasty) const;
113
114         // message centers
115         void    setTexData( bool enable,RAS_IRasterizer *ras);
116         void    setBlenderShaderData( bool enable, RAS_IRasterizer *ras);
117         void    setShaderData( bool enable, RAS_IRasterizer *ras);
118
119         void    setObjectMatrixData(int i, RAS_IRasterizer *ras);
120         void    setTexMatrixData(int i);
121
122         void    setLightData();
123
124         // cleanup stuff
125         void    OnExit();
126
127         // shader chacing
128         static BL_BlenderShader *mLastBlenderShader;
129         static BL_Shader                *mLastShader;
130
131         mutable int     mPass;
132 };
133
134
135 #endif