012bbef279502b5554d219a3b40cc3fd95d98c5a
[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 TFace;
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, // light/obj list
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         {
39                 // --
40                 return (void*) this;
41         }
42
43         // --------------------------------
44         virtual bool Activate(
45                 RAS_IRasterizer* rasty, 
46                 TCachingInfo& cachingInfo) const;
47         
48         void ActivateMat(
49                 RAS_IRasterizer* rasty, 
50                 TCachingInfo& cachingInfo)const;
51                 
52         void ActivatShaders(
53                 RAS_IRasterizer* rasty, 
54                 TCachingInfo& cachingInfo)const;
55         // --------------------------------
56
57         TFace* GetTFace(void) const;
58
59         // for ipos
60         void UpdateIPO(
61                 MT_Vector4 rgba, MT_Vector3 specrgb,
62                 MT_Scalar hard, MT_Scalar spec,
63                 MT_Scalar ref, MT_Scalar emit, MT_Scalar alpha
64         );
65         
66         // --------------------------------
67         virtual PyObject* _getattr(const STR_String& attr);
68         virtual int       _setattr(const STR_String& attr, PyObject *pyvalue);
69
70         KX_PYMETHOD_DOC( KX_BlenderMaterial, getShader );
71         KX_PYMETHOD_DOC( KX_BlenderMaterial, useShader );
72         KX_PYMETHOD_DOC( KX_BlenderMaterial, getMaterialIndex );
73         KX_PYMETHOD_DOC( KX_BlenderMaterial, getTexture );
74         KX_PYMETHOD_DOC( KX_BlenderMaterial, setTexture );
75
76         // --------------------------------
77         // pre calculate to avoid pops/lag at startup
78         virtual void OnConstruction( );
79
80 private:
81         BL_Material*    mMaterial;
82         BL_Shader*              mShader;
83         bool                    mUseShader;
84         KX_Scene*               mScene;
85         BL_Texture              mTextures[MAXTEX];              // texture array
86         
87         // message centers
88         void    setTexData( bool enable );
89         void    setShaderData( bool enable );
90
91         void    setTextureEnvironment( int textureIndex );
92         void    setEnvMap( bool val, bool cube=false);
93         void    setTexMatrixData(int i);
94         bool    setDefaultBlending();
95         bool    setBlending( int ind, bool enable=false );
96         void    setObjectMatrixData(int i);
97
98         // cleanup stuff
99         void    DisableTexData();
100         void    OnExit();
101
102         //void  DisableNonEnabled();
103         // --
104         mutable int     mPass;
105 };
106
107
108 #endif