SLProject
4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
|
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.
Definition at line 55 of file SLGLProgram.h.
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 |
Definition at line 39 of file SLGLProgram.cpp.
|
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.
Definition at line 66 of file SLGLProgram.cpp.
void SLGLProgram::addShader | ( | SLGLShader * | shader | ) |
SLGLProgram::addShader adds a shader to the shader list.
Definition at line 116 of file SLGLProgram.cpp.
void SLGLProgram::addUniform1f | ( | SLGLUniform1f * | u | ) |
add float uniform
SLGLProgram::addUniform1f add a uniform variable to the list.
Definition at line 564 of file SLGLProgram.cpp.
void SLGLProgram::addUniform1i | ( | SLGLUniform1i * | u | ) |
add int uniform
SLGLProgram::addUniform1f add a uniform variable to the list.
Definition at line 570 of file SLGLProgram.cpp.
|
pure virtual |
starter for derived classes
Implemented in SLGLProgramGeneric, and SLGLProgramGenerated.
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.
Definition at line 334 of file SLGLProgram.cpp.
void SLGLProgram::deleteDataGpu | ( | ) |
|
pure virtual |
Implemented in SLGLProgramGeneric, and SLGLProgramGenerated.
void SLGLProgram::endUse | ( | ) |
Definition at line 575 of file SLGLProgram.cpp.
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.
Definition at line 225 of file SLGLProgram.cpp.
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
Definition at line 126 of file SLGLProgram.cpp.
< 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
Definition at line 367 of file SLGLProgram.cpp.
|
inline |
Definition at line 88 of file SLGLProgram.h.
|
inline |
Definition at line 89 of file SLGLProgram.h.
Passes the float value v0 to the uniform variable "name".
Definition at line 583 of file SLGLProgram.cpp.
Passes 1 float value py pointer to the uniform variable "name".
Definition at line 666 of file SLGLProgram.cpp.
Passes the int values v0 to the uniform variable "name".
Definition at line 624 of file SLGLProgram.cpp.
Passes 1 int value py pointer to the uniform variable "name".
Definition at line 707 of file SLGLProgram.cpp.
Passes the float values v0 & v1 to the uniform variable "name".
Definition at line 591 of file SLGLProgram.cpp.
Passes 2 float values py pointer to the uniform variable "name".
Definition at line 676 of file SLGLProgram.cpp.
Passes the int values v0 & v1 to the uniform variable "name".
Definition at line 632 of file SLGLProgram.cpp.
Passes 2 int values py pointer to the uniform variable "name".
Definition at line 717 of file SLGLProgram.cpp.
Passes the float values v0, v1 & v2 to the uniform variable "name".
Definition at line 601 of file SLGLProgram.cpp.
Passes 3 float values py pointer to the uniform variable "name".
Definition at line 686 of file SLGLProgram.cpp.
Passes the int values v0, v1 & v2 to the uniform variable "name".
Definition at line 642 of file SLGLProgram.cpp.
Passes 3 int values py pointer to the uniform variable "name".
Definition at line 727 of file SLGLProgram.cpp.
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".
Definition at line 612 of file SLGLProgram.cpp.
Passes 4 float values py pointer to the uniform variable "name".
Definition at line 697 of file SLGLProgram.cpp.
Passes the int values v0, v1, v2 & v3 to the uniform variable "name".
Definition at line 653 of file SLGLProgram.cpp.
Passes 4 int values py pointer to the uniform variable "name".
Definition at line 737 of file SLGLProgram.cpp.
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".
Definition at line 747 of file SLGLProgram.cpp.
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.
Definition at line 758 of file SLGLProgram.cpp.
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".
Definition at line 767 of file SLGLProgram.cpp.
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.
Definition at line 778 of file SLGLProgram.cpp.
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".
Definition at line 787 of file SLGLProgram.cpp.
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.
Definition at line 798 of file SLGLProgram.cpp.
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.
Definition at line 318 of file SLGLProgram.cpp.
|
protected |
Flag if program is linked.
Definition at line 142 of file SLGLProgram.h.
|
protected |
OpenGL shader program object ID.
Definition at line 141 of file SLGLProgram.h.
|
protected |
Vector of all shader objects.
Definition at line 143 of file SLGLProgram.h.
|
protected |
Vector of uniform1f variables.
Definition at line 144 of file SLGLProgram.h.
|
protected |
Vector of uniform1i variables.
Definition at line 145 of file SLGLProgram.h.