This commit was manufactured by cvs2svn to create branch 'orange'.
[blender.git] / source / gameengine / Ketsji / BL_Shader.h
1 #ifndef __BL_SHADER_H__
2 #define __BL_SHADER_H__
3
4 #include "PyObjectPlus.h"
5 #include "BL_Material.h"
6
7 // -----------------------------------
8 // user state management
9 typedef struct uSampler
10 {
11         unsigned int    type;
12         int                             pass;
13         int                             unit;
14         int                             loc;
15         unsigned int    glTexture;
16 }uSampler;
17
18 #define SAMP_2D         1
19 #define SAMP_CUBE       2
20
21
22 // -----------------------------------
23 typedef struct uBlending
24 {
25         unsigned int pass;
26         int src;        // GL_ blend func values
27         int dest;
28         float const_color[4];
29 }uBlending;
30 // -----------------------------------
31
32 // ----------------
33 class BL_Shader : public PyObjectPlus
34 {
35         Py_Header;
36 private:
37         unsigned int    mShader, 
38                                         mVert,
39                                         mFrag;
40         int                             mPass;
41         bool                    mOk;
42         bool                    mUse;
43         uSampler                mSampler[MAXTEX];
44         uBlending               mBlending;
45         char*                   vertProg;
46         char*                   fragProg;
47         bool                    LinkProgram();
48         bool                    PrintInfo(int len, unsigned int handle, const char *type);
49
50 public:
51         BL_Shader(int n, PyTypeObject *T=&Type);
52         virtual ~BL_Shader();
53
54         char*           GetVertPtr();
55         char*           GetFragPtr();
56         void            SetVertPtr( char *vert );
57         void            SetFragPtr( char *frag );
58         
59         // ---
60         int getNumPass()        {return mPass;}
61         bool use()                      {return mUse;}
62
63         // ---
64         // access
65         const uSampler*         getSampler(int i);
66         const uBlending*        getBlending( int pass );
67         const bool                      Ok()const;
68
69         unsigned int            GetProg();
70         unsigned int            GetVertexShader();
71         unsigned int            GetFragmentShader();
72         
73         void InitializeSampler(
74                 int type,
75                 int unit,
76                 int pass,
77                 unsigned int texture
78         );
79
80         // -----------------------------------
81         // python interface
82         virtual PyObject* _getattr(const STR_String& attr);
83
84         KX_PYMETHOD_DOC( BL_Shader, setSource );
85         KX_PYMETHOD_DOC( BL_Shader, delSource );
86         KX_PYMETHOD_DOC( BL_Shader, getVertexProg );
87         KX_PYMETHOD_DOC( BL_Shader, getFragmentProg );
88         KX_PYMETHOD_DOC( BL_Shader, setNumberOfPasses );
89
90         // -----------------------------------
91         KX_PYMETHOD_DOC( BL_Shader, isValid);
92         KX_PYMETHOD_DOC( BL_Shader, validate);
93         KX_PYMETHOD_DOC( BL_Shader, setUniform4f );
94         KX_PYMETHOD_DOC( BL_Shader, setUniform3f );
95         KX_PYMETHOD_DOC( BL_Shader, setUniform2f );
96         KX_PYMETHOD_DOC( BL_Shader, setUniform1f );
97         KX_PYMETHOD_DOC( BL_Shader, setUniform4i );
98         KX_PYMETHOD_DOC( BL_Shader, setUniform3i );
99         KX_PYMETHOD_DOC( BL_Shader, setUniform2i );
100         KX_PYMETHOD_DOC( BL_Shader, setUniform1i );
101
102         KX_PYMETHOD_DOC( BL_Shader, setUniformfv );
103         KX_PYMETHOD_DOC( BL_Shader, setUniformiv );
104
105         KX_PYMETHOD_DOC( BL_Shader, setUniformMatrix4 );
106         KX_PYMETHOD_DOC( BL_Shader, setUniformMatrix3 );
107
108         // these come from within the material buttons
109         // sampler2d/samplerCube work
110         KX_PYMETHOD_DOC( BL_Shader, setSampler);
111         // user blending funcs
112         KX_PYMETHOD_DOC( BL_Shader, setBlending );
113 };
114
115
116
117 #endif//__BL_SHADER_H__