2011-02-22 10:33:14 +00:00
|
|
|
|
|
|
|
/** \file BL_Shader.h
|
|
|
|
* \ingroup ketsji
|
|
|
|
*/
|
|
|
|
|
2006-01-06 03:46:54 +00:00
|
|
|
#ifndef __BL_SHADER_H__
|
|
|
|
#define __BL_SHADER_H__
|
|
|
|
|
|
|
|
#include "PyObjectPlus.h"
|
|
|
|
#include "BL_Material.h"
|
2006-02-13 05:45:32 +00:00
|
|
|
#include "BL_Texture.h"
|
|
|
|
// --
|
|
|
|
#include "MT_Matrix4x4.h"
|
|
|
|
#include "MT_Matrix3x3.h"
|
|
|
|
#include "MT_Tuple2.h"
|
|
|
|
#include "MT_Tuple3.h"
|
|
|
|
#include "MT_Tuple4.h"
|
2006-01-06 03:46:54 +00:00
|
|
|
|
2006-04-02 21:04:20 +00:00
|
|
|
#define SHADER_ATTRIBMAX 1
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BL_Sampler
|
|
|
|
* Sampler access
|
|
|
|
*/
|
|
|
|
class BL_Sampler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BL_Sampler():
|
2006-04-11 05:57:30 +00:00
|
|
|
mLoc(-1)
|
2006-04-02 21:04:20 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
int mLoc; // Sampler location
|
2009-08-18 15:37:31 +00:00
|
|
|
|
|
|
|
#ifdef WITH_CXX_GUARDEDALLOC
|
|
|
|
public:
|
2010-06-06 01:15:44 +00:00
|
|
|
void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:BL_Sampler"); }
|
2009-08-18 15:37:31 +00:00
|
|
|
void operator delete( void *mem ) { MEM_freeN(mem); }
|
|
|
|
#endif
|
2006-04-02 21:04:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BL_Uniform
|
|
|
|
* uniform storage
|
|
|
|
*/
|
|
|
|
class BL_Uniform
|
2006-01-06 03:46:54 +00:00
|
|
|
{
|
2006-04-02 21:04:20 +00:00
|
|
|
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
|
|
|
|
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_INT,
|
|
|
|
UNI_FLOAT,
|
|
|
|
UNI_INT2,
|
|
|
|
UNI_FLOAT2,
|
|
|
|
UNI_INT3,
|
|
|
|
UNI_FLOAT3,
|
|
|
|
UNI_INT4,
|
|
|
|
UNI_FLOAT4,
|
|
|
|
UNI_MAT3,
|
|
|
|
UNI_MAT4,
|
|
|
|
UNI_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
int GetLocation() { return mLoc; }
|
|
|
|
void* getData() { return mData; }
|
2009-08-18 15:37:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_CXX_GUARDEDALLOC
|
|
|
|
public:
|
2010-06-06 01:15:44 +00:00
|
|
|
void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:BL_Uniform"); }
|
2009-08-18 15:37:31 +00:00
|
|
|
void operator delete( void *mem ) { MEM_freeN(mem); }
|
|
|
|
#endif
|
2006-04-02 21:04:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BL_DefUniform
|
|
|
|
* pre defined uniform storage
|
|
|
|
*/
|
|
|
|
class BL_DefUniform
|
2006-02-13 05:45:32 +00:00
|
|
|
{
|
2006-04-02 21:04:20 +00:00
|
|
|
public:
|
|
|
|
BL_DefUniform() :
|
|
|
|
mType(0),
|
|
|
|
mLoc(0),
|
|
|
|
mFlag(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
int mType;
|
|
|
|
int mLoc;
|
|
|
|
unsigned int mFlag;
|
2009-08-18 15:37:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_CXX_GUARDEDALLOC
|
|
|
|
public:
|
2010-06-06 01:15:44 +00:00
|
|
|
void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:BL_DefUniform"); }
|
2009-08-18 15:37:31 +00:00
|
|
|
void operator delete( void *mem ) { MEM_freeN(mem); }
|
|
|
|
#endif
|
2006-02-13 05:45:32 +00:00
|
|
|
};
|
2006-01-06 03:46:54 +00:00
|
|
|
|
2006-04-02 21:04:20 +00:00
|
|
|
/**
|
|
|
|
* BL_Shader
|
|
|
|
* shader access
|
|
|
|
*/
|
2006-01-06 03:46:54 +00:00
|
|
|
class BL_Shader : public PyObjectPlus
|
|
|
|
{
|
2011-11-06 01:39:36 +00:00
|
|
|
Py_Header
|
2006-01-06 03:46:54 +00:00
|
|
|
private:
|
2006-04-02 21:04:20 +00:00
|
|
|
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; // ...
|
2006-04-11 05:57:30 +00:00
|
|
|
//BL_Sampler mSampler[MAXTEX]; // Number of samplers
|
|
|
|
int mAttr; // Tangent attribute
|
2008-09-20 11:08:35 +00:00
|
|
|
const char* vertProg; // Vertex program string
|
|
|
|
const char* fragProg; // Fragment program string
|
2006-04-02 21:04:20 +00:00
|
|
|
bool mError; // ...
|
|
|
|
bool mDirty; //
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
// clears uniform data
|
|
|
|
void ClearUniforms();
|
2006-01-06 03:46:54 +00:00
|
|
|
|
|
|
|
public:
|
2009-06-28 11:22:26 +00:00
|
|
|
BL_Shader();
|
2006-01-06 03:46:54 +00:00
|
|
|
virtual ~BL_Shader();
|
|
|
|
|
2006-04-02 21:04:20 +00:00
|
|
|
// Unused for now tangent is set as
|
|
|
|
// tex coords
|
|
|
|
enum AttribTypes {
|
2006-02-13 05:45:32 +00:00
|
|
|
SHD_TANGENT =1
|
|
|
|
};
|
|
|
|
|
|
|
|
enum GenType {
|
|
|
|
MODELVIEWMATRIX,
|
|
|
|
MODELVIEWMATRIX_TRANSPOSE,
|
|
|
|
MODELVIEWMATRIX_INVERSE,
|
|
|
|
MODELVIEWMATRIX_INVERSETRANSPOSE,
|
|
|
|
|
|
|
|
// Model matrix
|
|
|
|
MODELMATRIX,
|
|
|
|
MODELMATRIX_TRANSPOSE,
|
|
|
|
MODELMATRIX_INVERSE,
|
|
|
|
MODELMATRIX_INVERSETRANSPOSE,
|
|
|
|
|
|
|
|
// View Matrix
|
|
|
|
VIEWMATRIX,
|
|
|
|
VIEWMATRIX_TRANSPOSE,
|
|
|
|
VIEWMATRIX_INVERSE,
|
|
|
|
VIEWMATRIX_INVERSETRANSPOSE,
|
2006-04-02 21:04:20 +00:00
|
|
|
|
|
|
|
// Current camera position
|
|
|
|
CAM_POS,
|
|
|
|
|
|
|
|
// RAS timer
|
|
|
|
CONSTANT_TIMER
|
2006-02-13 05:45:32 +00:00
|
|
|
};
|
|
|
|
|
2006-04-02 21:04:20 +00:00
|
|
|
const char* GetVertPtr();
|
|
|
|
const char* GetFragPtr();
|
|
|
|
void SetVertPtr( char *vert );
|
|
|
|
void SetFragPtr( char *frag );
|
2006-01-06 03:46:54 +00:00
|
|
|
|
|
|
|
// ---
|
|
|
|
int getNumPass() {return mPass;}
|
2006-01-18 06:04:11 +00:00
|
|
|
bool GetError() {return mError;}
|
2006-01-06 03:46:54 +00:00
|
|
|
// ---
|
2006-04-11 05:57:30 +00:00
|
|
|
//const BL_Sampler* GetSampler(int i);
|
2006-02-13 05:45:32 +00:00
|
|
|
void SetSampler(int loc, int unit);
|
2006-01-06 03:46:54 +00:00
|
|
|
|
2009-02-25 03:26:02 +00:00
|
|
|
bool Ok()const;
|
2006-01-06 03:46:54 +00:00
|
|
|
unsigned int GetProg();
|
2006-02-13 05:45:32 +00:00
|
|
|
void SetProg(bool enable);
|
2012-03-08 03:05:57 +00:00
|
|
|
int GetAttribute() { return mAttr; }
|
2006-02-13 05:45:32 +00:00
|
|
|
|
2006-04-02 21:04:20 +00:00
|
|
|
// --
|
|
|
|
// Apply methods : sets colected uniforms
|
|
|
|
void ApplyShader();
|
|
|
|
void UnloadShader();
|
2006-02-13 05:45:32 +00:00
|
|
|
|
2006-04-02 21:04:20 +00:00
|
|
|
// Update predefined uniforms each render call
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
void Update(const class RAS_MeshSlot & ms, class RAS_IRasterizer* rasty);
|
2006-02-13 05:45:32 +00:00
|
|
|
|
2006-04-11 05:57:30 +00:00
|
|
|
//// Set sampler units (copied)
|
|
|
|
//void InitializeSampler(int unit, BL_Texture* texture );
|
2006-01-06 03:46:54 +00:00
|
|
|
|
2006-04-02 21:04:20 +00:00
|
|
|
|
|
|
|
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 STR_String& name);
|
|
|
|
void BindAttribute(const STR_String& attr, int loc);
|
|
|
|
int GetUniformLocation(const STR_String& 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 int val);
|
|
|
|
|
|
|
|
// Python interface
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2009-06-29 02:25:54 +00:00
|
|
|
virtual PyObject* py_repr(void) { return PyUnicode_FromFormat("BL_Shader\n\tvertex shader:%s\n\n\tfragment shader%s\n\n", vertProg, fragProg); }
|
2006-01-06 03:46:54 +00:00
|
|
|
|
2006-04-11 05:57:30 +00:00
|
|
|
// -----------------------------------
|
2012-04-29 17:11:40 +00:00
|
|
|
KX_PYMETHOD_DOC(BL_Shader, setSource);
|
|
|
|
KX_PYMETHOD_DOC(BL_Shader, delSource);
|
|
|
|
KX_PYMETHOD_DOC(BL_Shader, getVertexProg);
|
|
|
|
KX_PYMETHOD_DOC(BL_Shader, getFragmentProg);
|
|
|
|
KX_PYMETHOD_DOC(BL_Shader, setNumberOfPasses);
|
|
|
|
KX_PYMETHOD_DOC(BL_Shader, isValid);
|
|
|
|
KX_PYMETHOD_DOC(BL_Shader, validate);
|
2006-04-11 05:57:30 +00:00
|
|
|
|
|
|
|
// -----------------------------------
|
2012-04-29 17:11:40 +00:00
|
|
|
KX_PYMETHOD_DOC(BL_Shader, setUniform4f);
|
|
|
|
KX_PYMETHOD_DOC(BL_Shader, setUniform3f);
|
|
|
|
KX_PYMETHOD_DOC(BL_Shader, setUniform2f);
|
|
|
|
KX_PYMETHOD_DOC(BL_Shader, setUniform1f);
|
|
|
|
KX_PYMETHOD_DOC(BL_Shader, setUniform4i);
|
|
|
|
KX_PYMETHOD_DOC(BL_Shader, setUniform3i);
|
|
|
|
KX_PYMETHOD_DOC(BL_Shader, setUniform2i);
|
|
|
|
KX_PYMETHOD_DOC(BL_Shader, setUniform1i);
|
|
|
|
KX_PYMETHOD_DOC(BL_Shader, setUniformfv);
|
|
|
|
KX_PYMETHOD_DOC(BL_Shader, setUniformiv);
|
|
|
|
KX_PYMETHOD_DOC(BL_Shader, setUniformMatrix4);
|
|
|
|
KX_PYMETHOD_DOC(BL_Shader, setUniformMatrix3);
|
|
|
|
KX_PYMETHOD_DOC(BL_Shader, setUniformDef);
|
|
|
|
KX_PYMETHOD_DOC(BL_Shader, setAttrib);
|
|
|
|
KX_PYMETHOD_DOC(BL_Shader, setSampler);
|
2009-09-29 21:42:40 +00:00
|
|
|
#endif
|
2006-01-06 03:46:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif//__BL_SHADER_H__
|