Final merge of HEAD (bf-blender) into the orange branch.
[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, getMaterialIndex );
72         KX_PYMETHOD_DOC( KX_BlenderMaterial, getTexture );
73         KX_PYMETHOD_DOC( KX_BlenderMaterial, setTexture );
74
75         KX_PYMETHOD_DOC( KX_BlenderMaterial, setBlending );
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         KX_Scene*               mScene;
84         BL_Texture              mTextures[MAXTEX];              // texture array
85         
86         bool                    mUserDefBlend;
87         unsigned int    mBlendFunc[2];
88         bool                    mModified;
89
90         // message centers
91         void    setTexData( bool enable );
92         void    setShaderData( bool enable );
93
94         void    setTextureEnvironment( int textureIndex );
95         void    setEnvMap( bool val, bool cube=false);
96         void    setTexMatrixData(int i);
97         bool    setDefaultBlending();
98         void    setObjectMatrixData(int i);
99
100         // cleanup stuff
101         void    DisableTexData();
102         void    OnExit();
103
104         //void  DisableNonEnabled();
105         // --
106         mutable int     mPass;
107 };
108
109
110 #endif