applied Charlies patch for game engine graphics. display list support, and bumpmappin...
[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,
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         TFace* GetTFace(void) const;
65
66         // for ipos
67         void UpdateIPO(
68                 MT_Vector4 rgba, MT_Vector3 specrgb,
69                 MT_Scalar hard, MT_Scalar spec,
70                 MT_Scalar ref, MT_Scalar emit, MT_Scalar alpha
71         );
72         
73         // --------------------------------
74         virtual PyObject* _getattr(const STR_String& attr);
75         virtual int       _setattr(const STR_String& attr, PyObject *pyvalue);
76
77         KX_PYMETHOD_DOC( KX_BlenderMaterial, getShader );
78         KX_PYMETHOD_DOC( KX_BlenderMaterial, getMaterialIndex );
79         KX_PYMETHOD_DOC( KX_BlenderMaterial, getTexture );
80         KX_PYMETHOD_DOC( KX_BlenderMaterial, setTexture );
81
82         KX_PYMETHOD_DOC( KX_BlenderMaterial, setBlending );
83
84         // --------------------------------
85         // pre calculate to avoid pops/lag at startup
86         virtual void OnConstruction( );
87 private:
88         BL_Material*    mMaterial;
89         BL_Shader*              mShader;
90         KX_Scene*               mScene;
91         BL_Texture              mTextures[MAXTEX];              // texture array
92         bool                    mUserDefBlend;
93         unsigned int    mBlendFunc[2];
94         bool                    mModified;
95
96         void ActivatGLMaterials( RAS_IRasterizer* rasty )const;
97         void ActivateTexGen( RAS_IRasterizer *ras ) const;
98
99
100         // message centers
101         void    setTexData( bool enable,RAS_IRasterizer *ras);
102         void    setShaderData( bool enable, RAS_IRasterizer *ras);
103
104         bool    setDefaultBlending();
105         void    setObjectMatrixData(int i, RAS_IRasterizer *ras);
106         void    setTexMatrixData(int i);
107
108         void    setLightData();
109
110         // cleanup stuff
111         void    OnExit();
112
113         mutable int     mPass;
114 };
115
116
117 #endif