SLProject 4.0.000
|
Encapsulation of an OpenGL shader program object. More...
#include <SLGLProgram.h>
Public Member Functions | |
SLGLProgram (SLAssetManager *am, const string &vertShaderFile, const string &fragShaderFile, const string &geomShaderFile="", const string &programName="") | |
Ctor with a vertex and a fragment shader filename. More... | |
~SLGLProgram () override | |
void | deleteDataGpu () |
Delete all Gpu data. More... | |
void | addShader (SLGLShader *shader) |
SLGLProgram::addShader adds a shader to the shader list. More... | |
void | init (SLVLight *lights) |
void | initTF (const char *writeBackAttrib[], int size) |
virtual void | beginShader (SLCamera *cam, SLMaterial *mat, SLVLight *lights)=0 |
starter for derived classes More... | |
virtual void | endShader ()=0 |
void | beginUse (SLCamera *cam, SLMaterial *mat, SLVLight *lights) |
SLint | passLightsToUniforms (SLVLight *lights, SLuint nextTexUnit) const |
void | endUse () |
SLGLProgram::endUse stops the shader program. More... | |
void | useProgram () |
void | addUniform1f (SLGLUniform1f *u) |
add float uniform More... | |
void | addUniform1i (SLGLUniform1i *u) |
add int uniform More... | |
SLuint | progID () const |
SLVGLShader & | shaders () |
SLint | getUniformLocation (const SLchar *name) const |
SLint | uniform1f (const SLchar *name, SLfloat v0) const |
Passes the float value v0 to the uniform variable "name". More... | |
SLint | uniform2f (const SLchar *name, SLfloat v0, SLfloat v1) const |
Passes the float values v0 & v1 to the uniform variable "name". More... | |
SLint | uniform3f (const SLchar *name, SLfloat v0, SLfloat v1, SLfloat v2) const |
Passes the float values v0, v1 & v2 to the uniform variable "name". More... | |
SLint | uniform4f (const SLchar *name, SLfloat v0, SLfloat v1, SLfloat v2, SLfloat v3) const |
Passes the float values v0,v1,v2 & v3 to the uniform variable "name". More... | |
SLint | uniform1i (const SLchar *name, SLint v0) const |
Passes the int values v0 to the uniform variable "name". More... | |
SLint | uniform2i (const SLchar *name, SLint v0, SLint v1) const |
Passes the int values v0 & v1 to the uniform variable "name". More... | |
SLint | uniform3i (const SLchar *name, SLint v0, SLint v1, SLint v2) const |
Passes the int values v0, v1 & v2 to the uniform variable "name". More... | |
SLint | uniform4i (const SLchar *name, SLint v0, SLint v1, SLint v2, SLint v3) const |
Passes the int values v0, v1, v2 & v3 to the uniform variable "name". More... | |
SLint | uniform1fv (const SLchar *name, SLsizei count, const SLfloat *value) const |
Passes 1 float value py pointer to the uniform variable "name". More... | |
SLint | uniform2fv (const SLchar *name, SLsizei count, const SLfloat *value) const |
Passes 2 float values py pointer to the uniform variable "name". More... | |
SLint | uniform3fv (const SLchar *name, SLsizei count, const SLfloat *value) const |
Passes 3 float values py pointer to the uniform variable "name". More... | |
SLint | uniform4fv (const SLchar *name, SLsizei count, const SLfloat *value) const |
Passes 4 float values py pointer to the uniform variable "name". More... | |
SLint | uniform1iv (const SLchar *name, SLsizei count, const SLint *value) const |
Passes 1 int value py pointer to the uniform variable "name". More... | |
SLint | uniform2iv (const SLchar *name, SLsizei count, const SLint *value) const |
Passes 2 int values py pointer to the uniform variable "name". More... | |
SLint | uniform3iv (const SLchar *name, SLsizei count, const SLint *value) const |
Passes 3 int values py pointer to the uniform variable "name". More... | |
SLint | uniform4iv (const SLchar *name, GLsizei count, const SLint *value) const |
Passes 4 int values py pointer to the uniform variable "name". More... | |
SLint | uniformMatrix2fv (const SLchar *name, SLsizei count, const SLfloat *value, GLboolean transpose=false) const |
Passes a 2x2 float matrix values py pointer to the uniform variable "name". More... | |
void | uniformMatrix2fv (SLint loc, SLsizei count, const SLfloat *value, GLboolean transpose=false) const |
Passes a 2x2 float matrix values py pointer to the uniform at location loc. More... | |
SLint | uniformMatrix3fv (const SLchar *name, SLsizei count, const SLfloat *value, GLboolean transpose=false) const |
Passes a 3x3 float matrix values py pointer to the uniform variable "name". More... | |
void | uniformMatrix3fv (SLint loc, SLsizei count, const SLfloat *value, GLboolean transpose=false) const |
Passes a 3x3 float matrix values py pointer to the uniform at location loc. More... | |
SLint | uniformMatrix4fv (const SLchar *name, SLsizei count, const SLfloat *value, GLboolean transpose=false) const |
Passes a 4x4 float matrix values py pointer to the uniform variable "name". More... | |
void | uniformMatrix4fv (SLint loc, SLsizei count, const SLfloat *value, GLboolean transpose=false) const |
Passes a 4x4 float matrix values py pointer to the uniform at location loc. More... | |
Public Member Functions inherited from SLObject | |
SLObject (const SLstring &Name="", const SLstring &url="") | |
virtual | ~SLObject () |
void | name (const SLstring &Name) |
void | url (const SLstring &url) |
const SLstring & | name () const |
const SLstring & | url () const |
Protected Attributes | |
SLuint | _progID |
OpenGL shader program object ID. More... | |
SLbool | _isLinked |
Flag if program is linked. More... | |
SLVGLShader | _shaders |
Vector of all shader objects. More... | |
SLVUniform1f | _uniforms1f |
Vector of uniform1f variables. More... | |
SLVUniform1i | _uniforms1i |
Vector of uniform1i variables. More... | |
Protected Attributes inherited from SLObject | |
SLstring | _name |
name of an object More... | |
SLstring | _url |
uniform resource locator More... | |
Encapsulation of an OpenGL shader program object.
The SLGLProgram base class represents a shader program object of the OpenGL Shading Language (GLSL). Multiple SLGLShader objects can be attached and linked at run time. An SLGLProgram object can then be attached to an SLMaterial node for execution. An SLGLProgram object can hold an vector of uniform variable that can transfer variables from the CPU program to the GPU program. For more details on GLSL please refer to official GLSL documentation and to SLGLShader.
All shader files are located in the directory data/shaders. For OSX, iOS and Android applications they are copied to the appropriate file system locations.
SLGLProgram::SLGLProgram | ( | SLAssetManager * | am, |
const string & | vertShaderFile, | ||
const string & | fragShaderFile, | ||
const string & | geomShaderFile = "" , |
||
const string & | programName = "" |
||
) |
Ctor with a vertex and a fragment shader filename.
Constructor for shader programs. Shader programs can be used in multiple materials and can belong therefore to the global assets such as meshes (SLMesh), materials (SLMaterial), textures (SLGLTexture) and shader programs (SLGLProgram).
am | Pointer to a global asset manager. If passed the asset manager is the owner of the instance and will do the deallocation. If a nullptr is passed the creator is responsible for the deallocation. |
vertShaderFile | Name of the vertex shader file. If only a filename is passed it will be search on the SLGLProgram::defaultPath. |
fragShaderFile | Name of the fragment shader file. If only a filename is passed it will be search on the SLGLProgram::defaultPath. |
geomShaderFile | Name of the geometry shader file. If only a filename is passed it will be search on the SLGLProgram::defaultPath. |
programName | existing program name to use |
|
override |
The destructor should be called by the owner of the shader program. If an asset manager was passed in the constructor it will do it after scene destruction. The destructor deletes all shader objects (SLGLShader) in the RAM as well as on the GPU.
void SLGLProgram::addShader | ( | SLGLShader * | shader | ) |
SLGLProgram::addShader adds a shader to the shader list.
void SLGLProgram::addUniform1f | ( | SLGLUniform1f * | u | ) |
add float uniform
SLGLProgram::addUniform1f add a uniform variable to the list.
void SLGLProgram::addUniform1i | ( | SLGLUniform1i * | u | ) |
add int uniform
SLGLProgram::addUniform1f add a uniform variable to the list.
|
pure virtual |
starter for derived classes
Implemented in SLGLProgramGenerated, and SLGLProgramGeneric.
void SLGLProgram::beginUse | ( | SLCamera * | cam, |
SLMaterial * | mat, | ||
SLVLight * | lights | ||
) |
SLGLProgram::beginUse starts using the shader program and transfers the the camera, lights and material parameter as uniform variables. It also passes the custom uniform variables of the _uniform1fList as well as the texture names.
void SLGLProgram::deleteDataGpu | ( | ) |
Delete all Gpu data.
|
pure virtual |
Implemented in SLGLProgramGenerated, and SLGLProgramGeneric.
void SLGLProgram::endUse | ( | ) |
SLGLProgram::endUse stops the shader program.
void SLGLProgram::init | ( | SLVLight * | lights | ) |
SLGLProgram::init creates the OpenGL shader program object, compiles all shader objects and attaches them to the shader program. At the end all shaders are linked. If a shader fails to compile a simple texture only shader is compiled that shows an error message in the texture.
void SLGLProgram::initTF | ( | const char * | writeBackAttrib[], |
int | size | ||
) |
SLGLProgram::initTF() initializes shader for transform feedback. Does not replace any code from the shader and assumes valid syntax for the shader used. Used for particle systems
< flag if light is on
< position of light in world space
< position of light in view space
< ambient light intensity (Ia)
< diffuse light intensity (Id)
< specular light intensity (Is)
< spot direction in world space
< spot direction in view space
< spot cutoff angle 1-180 degrees
< cosine of spot cutoff angle
< spot exponent
< att. factor (const,linear,quadratic)
< flag if att. must be calculated
< flag if light creates shadows
< flag if percentage-closer filtering is enabled
< radius of area to sample
< shadow mapping min. bias at 0 deg.
< shadow mapping max. bias at 90 deg.
< flag if light has a cube shadow map
< projection matrix of the light
< pointers to depth-buffers for shadow mapping
< number of cascades for cascaded shadow mapping
|
inline |
|
inline |
Passes the float value v0 to the uniform variable "name".
Passes 1 float value py pointer to the uniform variable "name".
Passes the int values v0 to the uniform variable "name".
Passes 1 int value py pointer to the uniform variable "name".
Passes the float values v0 & v1 to the uniform variable "name".
Passes 2 float values py pointer to the uniform variable "name".
Passes the int values v0 & v1 to the uniform variable "name".
Passes 2 int values py pointer to the uniform variable "name".
Passes the float values v0, v1 & v2 to the uniform variable "name".
Passes 3 float values py pointer to the uniform variable "name".
Passes the int values v0, v1 & v2 to the uniform variable "name".
Passes 3 int values py pointer to the uniform variable "name".
SLint SLGLProgram::uniform4f | ( | const SLchar * | name, |
SLfloat | v0, | ||
SLfloat | v1, | ||
SLfloat | v2, | ||
SLfloat | v3 | ||
) | const |
Passes the float values v0,v1,v2 & v3 to the uniform variable "name".
Passes 4 float values py pointer to the uniform variable "name".
Passes the int values v0, v1, v2 & v3 to the uniform variable "name".
Passes 4 int values py pointer to the uniform variable "name".
SLint SLGLProgram::uniformMatrix2fv | ( | const SLchar * | name, |
SLsizei | count, | ||
const SLfloat * | value, | ||
GLboolean | transpose = false |
||
) | const |
Passes a 2x2 float matrix values py pointer to the uniform variable "name".
void SLGLProgram::uniformMatrix2fv | ( | SLint | loc, |
SLsizei | count, | ||
const SLfloat * | value, | ||
GLboolean | transpose = false |
||
) | const |
Passes a 2x2 float matrix values py pointer to the uniform at location loc.
SLint SLGLProgram::uniformMatrix3fv | ( | const SLchar * | name, |
SLsizei | count, | ||
const SLfloat * | value, | ||
GLboolean | transpose = false |
||
) | const |
Passes a 3x3 float matrix values py pointer to the uniform variable "name".
void SLGLProgram::uniformMatrix3fv | ( | SLint | loc, |
SLsizei | count, | ||
const SLfloat * | value, | ||
GLboolean | transpose = false |
||
) | const |
Passes a 3x3 float matrix values py pointer to the uniform at location loc.
SLint SLGLProgram::uniformMatrix4fv | ( | const SLchar * | name, |
SLsizei | count, | ||
const SLfloat * | value, | ||
GLboolean | transpose = false |
||
) | const |
Passes a 4x4 float matrix values py pointer to the uniform variable "name".
void SLGLProgram::uniformMatrix4fv | ( | SLint | loc, |
SLsizei | count, | ||
const SLfloat * | value, | ||
GLboolean | transpose = false |
||
) | const |
Passes a 4x4 float matrix values py pointer to the uniform at location loc.
void SLGLProgram::useProgram | ( | ) |
SLGLProgram::useProgram inits the first time the program and then uses it. Call this initialization if you pass your own custom uniform variables.
|
protected |
Flag if program is linked.
|
protected |
OpenGL shader program object ID.
|
protected |
Vector of all shader objects.
|
protected |
Vector of uniform1f variables.
|
protected |
Vector of uniform1i variables.