BGE: Cleanup: Code style BL_Shader

Reviewers: lordloki, youle, campbellbarton, sergey, kupoman, moguri, panzergame

Reviewed By: panzergame

Projects: #game_engine

Differential Revision: https://developer.blender.org/D1397
This commit is contained in:
Thomas Szepe 2015-10-25 19:43:46 +01:00
parent 06d2ad0185
commit 4f767e37e8
2 changed files with 636 additions and 671 deletions

File diff suppressed because it is too large Load Diff

View File

@ -9,7 +9,6 @@
#include "EXP_PyObjectPlus.h"
#include "BL_Material.h"
#include "BL_Texture.h"
// --
#include "MT_Matrix4x4.h"
#include "MT_Matrix3x3.h"
#include "MT_Tuple2.h"
@ -18,17 +17,19 @@
/**
* BL_Sampler
* Sampler access
* Sampler access
*/
class BL_Sampler
{
public:
BL_Sampler():
BL_Sampler()
:
mLoc(-1)
{
}
int mLoc; // Sampler location
int mLoc; // Sampler location
#ifdef WITH_CXX_GUARDEDALLOC
MEM_CXX_CLASS_ALLOC_FUNCS("GE:BL_Sampler")
#endif
@ -36,27 +37,23 @@ public:
/**
* BL_Uniform
* uniform storage
* uniform storage
*/
class BL_Uniform
class BL_Uniform
{
private:
int mLoc; // Uniform location
void* mData; // Memory allocated for variable
bool mDirty; // Caching variable
int mType; // Enum UniformTypes
bool mTranspose; // Transpose matrices
const int mDataLen; // Length of our data
int mLoc; // Uniform location
void *mData; // Memory allocated for variable
bool mDirty; // Caching variable
int mType; // Enum UniformTypes
bool mTranspose; // Transpose matrices
const int mDataLen; // Length of our data
public:
BL_Uniform(int data_size);
~BL_Uniform();
void Apply(class BL_Shader *shader);
void SetData(int location, int type, bool transpose=false);
enum UniformTypes {
UNI_NONE =0,
UNI_NONE = 0,
UNI_INT,
UNI_FLOAT,
UNI_INT2,
@ -70,10 +67,11 @@ public:
UNI_MAX
};
int GetLocation() { return mLoc; }
void* getData() { return mData; }
void Apply(class BL_Shader *shader);
void SetData(int location, int type, bool transpose = false);
int GetLocation() { return mLoc; }
void *getData() { return mData; }
#ifdef WITH_CXX_GUARDEDALLOC
MEM_CXX_CLASS_ALLOC_FUNCS("GE:BL_Uniform")
#endif
@ -81,22 +79,23 @@ public:
/**
* BL_DefUniform
* pre defined uniform storage
* pre defined uniform storage
*/
class BL_DefUniform
{
public:
BL_DefUniform() :
BL_DefUniform()
:
mType(0),
mLoc(0),
mFlag(0)
{
}
int mType;
int mLoc;
unsigned int mFlag;
int mType;
int mLoc;
unsigned int mFlag;
#ifdef WITH_CXX_GUARDEDALLOC
MEM_CXX_CLASS_ALLOC_FUNCS("GE:BL_DefUniform")
#endif
@ -104,46 +103,46 @@ public:
/**
* BL_Shader
* shader access
* shader access
*/
class BL_Shader : public PyObjectPlus
{
Py_Header
private:
typedef std::vector<BL_Uniform*> BL_UniformVec;
typedef std::vector<BL_DefUniform*> BL_UniformVecDef;
typedef std::vector<BL_Uniform *> BL_UniformVec;
typedef std::vector<BL_DefUniform *> BL_UniformVecDef;
unsigned int mShader; // Shader object
int mPass; // 1.. unused
bool mOk; // Valid and ok
bool mUse; // ...
//BL_Sampler mSampler[MAXTEX]; // Number of samplers
int mAttr; // Tangent attribute
const char* vertProg; // Vertex program string
const char* fragProg; // Fragment program string
bool mError; // ...
bool mDirty; //
unsigned int mShader; // Shader object
int mPass; // 1.. unused
bool mOk; // Valid and ok
bool mUse;
//BL_Sampler mSampler[MAXTEX]; // Number of samplers
int mAttr; // Tangent attribute
const char *vertProg; // Vertex program string
const char *fragProg; // Fragment program string
bool mError;
bool mDirty;
// Stored uniform variables
BL_UniformVec mUniforms;
BL_UniformVecDef mPreDef;
// Compiles and links the shader
bool LinkProgram();
// Stored uniform variables
BL_UniformVec mUniforms;
BL_UniformVecDef mPreDef;
// search by location
BL_Uniform* FindUniform(const int location);
BL_Uniform *FindUniform(const int location);
// clears uniform data
void ClearUniforms();
void ClearUniforms();
public:
BL_Shader();
virtual ~BL_Shader();
// Unused for now tangent is set as
// tex coords
// Unused for now tangent is set as tex coords
enum AttribTypes {
SHD_TANGENT =1
SHD_TANGENT = 1
};
enum GenType {
@ -151,76 +150,63 @@ public:
MODELVIEWMATRIX_TRANSPOSE,
MODELVIEWMATRIX_INVERSE,
MODELVIEWMATRIX_INVERSETRANSPOSE,
// Model matrix
MODELMATRIX,
MODELMATRIX_TRANSPOSE,
MODELMATRIX_INVERSE,
MODELMATRIX_INVERSETRANSPOSE,
// View Matrix
VIEWMATRIX,
VIEWMATRIX_TRANSPOSE,
VIEWMATRIX_INVERSE,
VIEWMATRIX_INVERSETRANSPOSE,
// Current camera position
CAM_POS,
// RAS timer
CONSTANT_TIMER
};
const char* GetVertPtr();
const char* GetFragPtr();
void SetVertPtr( char *vert );
void SetFragPtr( char *frag );
// ---
int getNumPass() {return mPass;}
bool GetError() {return mError;}
// ---
//const BL_Sampler* GetSampler(int i);
void SetSampler(int loc, int unit);
const char *GetVertPtr();
const char *GetFragPtr();
void SetVertPtr(char *vert);
void SetFragPtr(char *frag);
int getNumPass() { return mPass; }
bool GetError() { return mError; }
bool Ok()const;
unsigned int GetProg();
void SetProg(bool enable);
int GetAttribute() { return mAttr; }
//const BL_Sampler *GetSampler(int i);
void SetSampler(int loc, int unit);
bool Ok() const;
unsigned int GetProg();
void SetProg(bool enable);
int GetAttribute() { return mAttr; }
// --
// Apply methods : sets colected uniforms
void ApplyShader();
void UnloadShader();
// Update predefined uniforms each render call
void Update(const class RAS_MeshSlot & ms, class RAS_IRasterizer* rasty);
//// Set sampler units (copied)
//void InitializeSampler(int unit, BL_Texture* texture );
void SetUniformfv(int location,int type, float *param, int size,bool transpose=false);
void SetUniformiv(int location,int type, int *param, int size,bool transpose=false);
void Update(const class RAS_MeshSlot &ms, class RAS_IRasterizer *rasty);
// Set sampler units (copied)
//void InitializeSampler(int unit, BL_Texture *texture);
void SetUniformfv(int location, int type, float *param, int size, bool transpose = false);
void SetUniformiv(int location, int type, int *param, int size, bool transpose = false);
int GetAttribLocation(const char *name);
void BindAttribute(const char *attr, int loc);
int GetUniformLocation(const char *name);
void SetUniform(int uniform, const MT_Tuple2& vec);
void SetUniform(int uniform, const MT_Tuple3& vec);
void SetUniform(int uniform, const MT_Tuple4& vec);
void SetUniform(int uniform, const MT_Matrix4x4& vec, bool transpose=false);
void SetUniform(int uniform, const MT_Matrix3x3& vec, bool transpose=false);
void SetUniform(int uniform, const float& val);
void SetUniform(int uniform, const float* val, int len);
void SetUniform(int uniform, const int* val, int len);
void SetUniform(int uniform, const unsigned int& val);
void SetUniform(int uniform, const MT_Tuple2 &vec);
void SetUniform(int uniform, const MT_Tuple3 &vec);
void SetUniform(int uniform, const MT_Tuple4 &vec);
void SetUniform(int uniform, const MT_Matrix4x4 &vec, bool transpose = false);
void SetUniform(int uniform, const MT_Matrix3x3 &vec, bool transpose = false);
void SetUniform(int uniform, const float &val);
void SetUniform(int uniform, const float *val, int len);
void SetUniform(int uniform, const int *val, int len);
void SetUniform(int uniform, const unsigned int &val);
void SetUniform(int uniform, const int val);
// Python interface
#ifdef WITH_PYTHON
virtual PyObject *py_repr(void) { return PyUnicode_FromFormat("BL_Shader\n\tvertex shader:%s\n\n\tfragment shader%s\n\n", vertProg, fragProg); }
virtual PyObject *py_repr()
{
return PyUnicode_FromFormat("BL_Shader\n\tvertex shader:%s\n\n\tfragment shader%s\n\n", vertProg, fragProg);
}
// -----------------------------------
KX_PYMETHOD_DOC(BL_Shader, setSource);