1
#ifndef __BL_SHADER_H__
2
#define __BL_SHADER_H__
4
#include "PyObjectPlus.h"
5
#include "BL_Material.h"
6
#include "BL_Texture.h"
8
#include "MT_Matrix4x4.h"
9
#include "MT_Matrix3x3.h"
10
#include "MT_Tuple2.h"
11
#include "MT_Tuple3.h"
12
#include "MT_Tuple4.h"
14
#define SHADER_ATTRIBMAX 1
27
int mLoc; // Sampler location
37
int mLoc; // Uniform location
38
void* mData; // Memory allocated for variable
39
bool mDirty; // Caching variable
40
int mType; // Enum UniformTypes
41
bool mTranspose; // Transpose matrices
42
const int mDataLen; // Length of our data
44
BL_Uniform(int data_size);
48
void Apply(class BL_Shader *shader);
49
void SetData(int location, int type, bool transpose=false);
66
int GetLocation() { return mLoc; }
67
void* getData() { return mData; }
72
* pre defined uniform storage
92
class BL_Shader : public PyObjectPlus
96
typedef std::vector<BL_Uniform*> BL_UniformVec;
97
typedef std::vector<BL_DefUniform*> BL_UniformVecDef;
99
unsigned int mShader; // Shader object
100
int mPass; // 1.. unused
101
bool mOk; // Valid and ok
103
//BL_Sampler mSampler[MAXTEX]; // Number of samplers
104
int mAttr; // Tangent attribute
105
const char* vertProg; // Vertex program string
106
const char* fragProg; // Fragment program string
110
// Compiles and links the shader
113
// Stored uniform variables
114
BL_UniformVec mUniforms;
115
BL_UniformVecDef mPreDef;
117
// search by location
118
BL_Uniform* FindUniform(const int location);
119
// clears uniform data
120
void ClearUniforms();
123
BL_Shader(PyTypeObject *T=&Type);
124
virtual ~BL_Shader();
126
// Unused for now tangent is set as
134
MODELVIEWMATRIX_TRANSPOSE,
135
MODELVIEWMATRIX_INVERSE,
136
MODELVIEWMATRIX_INVERSETRANSPOSE,
140
MODELMATRIX_TRANSPOSE,
142
MODELMATRIX_INVERSETRANSPOSE,
146
VIEWMATRIX_TRANSPOSE,
148
VIEWMATRIX_INVERSETRANSPOSE,
150
// Current camera position
157
const char* GetVertPtr();
158
const char* GetFragPtr();
159
void SetVertPtr( char *vert );
160
void SetFragPtr( char *frag );
163
int getNumPass() {return mPass;}
164
bool GetError() {return mError;}
166
//const BL_Sampler* GetSampler(int i);
167
void SetSampler(int loc, int unit);
169
const bool Ok()const;
170
unsigned int GetProg();
171
void SetProg(bool enable);
172
int GetAttribute(){return mAttr;};
175
// Apply methods : sets colected uniforms
179
// Update predefined uniforms each render call
180
void Update(const class RAS_MeshSlot & ms, class RAS_IRasterizer* rasty);
182
//// Set sampler units (copied)
183
//void InitializeSampler(int unit, BL_Texture* texture );
186
void SetUniformfv(int location,int type, float *param, int size,bool transpose=false);
187
void SetUniformiv(int location,int type, int *param, int size,bool transpose=false);
189
int GetAttribLocation(const STR_String& name);
190
void BindAttribute(const STR_String& attr, int loc);
191
int GetUniformLocation(const STR_String& name);
193
void SetUniform(int uniform, const MT_Tuple2& vec);
194
void SetUniform(int uniform, const MT_Tuple3& vec);
195
void SetUniform(int uniform, const MT_Tuple4& vec);
196
void SetUniform(int uniform, const MT_Matrix4x4& vec, bool transpose=false);
197
void SetUniform(int uniform, const MT_Matrix3x3& vec, bool transpose=false);
198
void SetUniform(int uniform, const float& val);
199
void SetUniform(int uniform, const float* val, int len);
200
void SetUniform(int uniform, const int* val, int len);
201
void SetUniform(int uniform, const unsigned int& val);
202
void SetUniform(int uniform, const int val);
205
virtual PyObject* _getattr(const STR_String& attr);
207
// -----------------------------------
208
KX_PYMETHOD_DOC( BL_Shader, setSource );
209
KX_PYMETHOD_DOC( BL_Shader, delSource );
210
KX_PYMETHOD_DOC( BL_Shader, getVertexProg );
211
KX_PYMETHOD_DOC( BL_Shader, getFragmentProg );
212
KX_PYMETHOD_DOC( BL_Shader, setNumberOfPasses );
213
KX_PYMETHOD_DOC( BL_Shader, isValid);
214
KX_PYMETHOD_DOC( BL_Shader, validate);
216
// -----------------------------------
217
KX_PYMETHOD_DOC( BL_Shader, setUniform4f );
218
KX_PYMETHOD_DOC( BL_Shader, setUniform3f );
219
KX_PYMETHOD_DOC( BL_Shader, setUniform2f );
220
KX_PYMETHOD_DOC( BL_Shader, setUniform1f );
221
KX_PYMETHOD_DOC( BL_Shader, setUniform4i );
222
KX_PYMETHOD_DOC( BL_Shader, setUniform3i );
223
KX_PYMETHOD_DOC( BL_Shader, setUniform2i );
224
KX_PYMETHOD_DOC( BL_Shader, setUniform1i );
225
KX_PYMETHOD_DOC( BL_Shader, setUniformfv );
226
KX_PYMETHOD_DOC( BL_Shader, setUniformiv );
227
KX_PYMETHOD_DOC( BL_Shader, setUniformMatrix4 );
228
KX_PYMETHOD_DOC( BL_Shader, setUniformMatrix3 );
229
KX_PYMETHOD_DOC( BL_Shader, setUniformDef );
230
KX_PYMETHOD_DOC( BL_Shader, setAttrib );
231
KX_PYMETHOD_DOC( BL_Shader, setSampler);
234
#endif//__BL_SHADER_H__