doxygen: prevent GPL license block from being parsed as doxygen comment.
[blender.git] / source / gameengine / Ketsji / KX_BlenderMaterial.h
1
2 /** \file KX_BlenderMaterial.h
3  *  \ingroup ketsji
4  */
5
6 #ifndef __KX_BLENDER_MATERIAL_H__
7 #define __KX_BLENDER_MATERIAL_H__
8
9 #include <vector>
10
11
12 #include "RAS_IPolygonMaterial.h"
13 #include "BL_Material.h"
14 #include "BL_Texture.h"
15 #include "BL_Shader.h"
16 #include "BL_BlenderShader.h"
17
18 #include "PyObjectPlus.h"
19
20 #include "MT_Vector3.h"
21 #include "MT_Vector4.h"
22
23 #ifdef WITH_CXX_GUARDEDALLOC
24 #include "MEM_guardedalloc.h"
25 #endif
26
27 #include "SCA_IScene.h" /* only for Replace_IScene */
28 #include "KX_Scene.h"
29
30 struct MTFace;
31 class KX_Scene;
32
33 class KX_BlenderMaterial :  public PyObjectPlus, public RAS_IPolyMaterial
34 {
35         Py_Header;
36 public:
37         // --------------------------------
38         KX_BlenderMaterial();
39         void Initialize(
40                 class KX_Scene* scene,
41                 BL_Material*    mat
42         );
43
44         virtual ~KX_BlenderMaterial();
45
46         // --------------------------------
47         virtual TCachingInfo GetCachingInfo(void) const {
48                 return (void*) this;
49         }
50
51         virtual 
52         bool Activate(
53                 RAS_IRasterizer* rasty, 
54                 TCachingInfo& cachingInfo
55         ) const;
56         
57         virtual 
58         void ActivateMeshSlot(
59                 const RAS_MeshSlot & ms, 
60                 RAS_IRasterizer* rasty 
61         ) const;
62         
63         void ActivateMat(
64                 RAS_IRasterizer* rasty,
65                 TCachingInfo& cachingInfo
66         )const;
67
68         void ActivatShaders(
69                 RAS_IRasterizer* rasty, 
70                 TCachingInfo& cachingInfo
71         )const;
72
73         void ActivateBlenderShaders(
74                 RAS_IRasterizer* rasty, 
75                 TCachingInfo& cachingInfo
76         )const;
77
78         Material* GetBlenderMaterial() const;
79         MTFace* GetMTFace(void) const;
80         unsigned int* GetMCol(void) const;
81         BL_Texture * getTex (unsigned int idx) { 
82                 return (idx < MAXTEX) ? mTextures + idx : NULL; 
83         }
84         Image * getImage (unsigned int idx) { 
85                 return (idx < MAXTEX && mMaterial) ? mMaterial->img[idx] : NULL; 
86         }
87         unsigned int* getBlendFunc() {
88                 return mBlendFunc;
89         }
90         // for ipos
91         void UpdateIPO(
92                 MT_Vector4 rgba, MT_Vector3 specrgb,
93                 MT_Scalar hard, MT_Scalar spec,
94                 MT_Scalar ref, MT_Scalar emit, MT_Scalar alpha
95         );
96         
97         virtual void Replace_IScene(SCA_IScene *val)
98         {
99                 mScene= static_cast<KX_Scene *>(val);
100                 if (mBlenderShader)
101                 {
102                         mBlenderShader->SetScene(mScene);
103                 }
104         };
105
106 #ifdef WITH_PYTHON
107         // --------------------------------
108         virtual PyObject* py_repr(void) { return PyUnicode_FromString(mMaterial->matname.ReadPtr()); }
109
110         static PyObject* pyattr_get_shader(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
111         static PyObject* pyattr_get_materialIndex(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
112         static PyObject* pyattr_get_blending(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
113         static int       pyattr_set_blending(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
114
115         KX_PYMETHOD_DOC( KX_BlenderMaterial, getShader );
116         KX_PYMETHOD_DOC( KX_BlenderMaterial, getMaterialIndex );
117         KX_PYMETHOD_DOC( KX_BlenderMaterial, getTexture );
118         KX_PYMETHOD_DOC( KX_BlenderMaterial, setTexture );
119
120         KX_PYMETHOD_DOC( KX_BlenderMaterial, setBlending );
121 #endif // WITH_PYTHON
122
123         // --------------------------------
124         // pre calculate to avoid pops/lag at startup
125         virtual void OnConstruction(int layer);
126
127         static void     EndFrame();
128
129 private:
130         BL_Material*            mMaterial;
131         BL_Shader*                      mShader;
132         BL_BlenderShader*       mBlenderShader;
133         KX_Scene*               mScene;
134         BL_Texture              mTextures[MAXTEX];              // texture array
135         bool                    mUserDefBlend;
136         unsigned int    mBlendFunc[2];
137         bool                    mModified;
138         bool                    mConstructed;                   // if false, don't clean on exit
139
140         void SetBlenderGLSLShader(int layer);
141
142         void ActivatGLMaterials( RAS_IRasterizer* rasty )const;
143         void ActivateTexGen( RAS_IRasterizer *ras ) const;
144
145         bool UsesLighting(RAS_IRasterizer *rasty) const;
146         void GetMaterialRGBAColor(unsigned char *rgba) const;
147         Scene* GetBlenderScene() const;
148         void ReleaseMaterial();
149
150         // message centers
151         void    setTexData( bool enable,RAS_IRasterizer *ras);
152         void    setBlenderShaderData( bool enable, RAS_IRasterizer *ras);
153         void    setShaderData( bool enable, RAS_IRasterizer *ras);
154
155         void    setObjectMatrixData(int i, RAS_IRasterizer *ras);
156         void    setTexMatrixData(int i);
157
158         void    setLightData();
159
160         // cleanup stuff
161         void    OnExit();
162
163         // shader chacing
164         static BL_BlenderShader *mLastBlenderShader;
165         static BL_Shader                *mLastShader;
166
167         mutable int     mPass;
168 };
169
170
171 #endif