SLProject 4.0.000
SLGLProgram Class Referenceabstract

Encapsulation of an OpenGL shader program object. More...

#include <SLGLProgram.h>

Inheritance diagram for SLGLProgram:
[legend]

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
 
SLVGLShadershaders ()
 
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 SLstringname () const
 
const SLstringurl () 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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ SLGLProgram()

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).

Parameters
amPointer 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.
vertShaderFileName of the vertex shader file. If only a filename is passed it will be search on the SLGLProgram::defaultPath.
fragShaderFileName of the fragment shader file. If only a filename is passed it will be search on the SLGLProgram::defaultPath.
geomShaderFileName of the geometry shader file. If only a filename is passed it will be search on the SLGLProgram::defaultPath.
programNameexisting program name to use

◆ ~SLGLProgram()

SLGLProgram::~SLGLProgram ( )
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.

Member Function Documentation

◆ addShader()

void SLGLProgram::addShader ( SLGLShader shader)

SLGLProgram::addShader adds a shader to the shader list.

◆ addUniform1f()

void SLGLProgram::addUniform1f ( SLGLUniform1f u)

add float uniform

SLGLProgram::addUniform1f add a uniform variable to the list.

◆ addUniform1i()

void SLGLProgram::addUniform1i ( SLGLUniform1i u)

add int uniform

SLGLProgram::addUniform1f add a uniform variable to the list.

◆ beginShader()

virtual void SLGLProgram::beginShader ( SLCamera cam,
SLMaterial mat,
SLVLight lights 
)
pure virtual

starter for derived classes

Implemented in SLGLProgramGenerated, and SLGLProgramGeneric.

◆ beginUse()

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.

◆ deleteDataGpu()

void SLGLProgram::deleteDataGpu ( )

Delete all Gpu data.

◆ endShader()

virtual void SLGLProgram::endShader ( )
pure virtual

◆ endUse()

void SLGLProgram::endUse ( )

SLGLProgram::endUse stops the shader program.

◆ getUniformLocation()

SLint SLGLProgram::getUniformLocation ( const SLchar name) const

◆ init()

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.

◆ initTF()

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

◆ passLightsToUniforms()

SLint SLGLProgram::passLightsToUniforms ( SLVLight lights,
SLuint  nextTexUnit 
) const

< 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

◆ progID()

SLuint SLGLProgram::progID ( ) const
inline

◆ shaders()

SLVGLShader & SLGLProgram::shaders ( )
inline

◆ uniform1f()

SLint SLGLProgram::uniform1f ( const SLchar name,
SLfloat  v0 
) const

Passes the float value v0 to the uniform variable "name".

◆ uniform1fv()

SLint SLGLProgram::uniform1fv ( const SLchar name,
SLsizei  count,
const SLfloat value 
) const

Passes 1 float value py pointer to the uniform variable "name".

◆ uniform1i()

SLint SLGLProgram::uniform1i ( const SLchar name,
SLint  v0 
) const

Passes the int values v0 to the uniform variable "name".

◆ uniform1iv()

SLint SLGLProgram::uniform1iv ( const SLchar name,
SLsizei  count,
const SLint value 
) const

Passes 1 int value py pointer to the uniform variable "name".

◆ uniform2f()

SLint SLGLProgram::uniform2f ( const SLchar name,
SLfloat  v0,
SLfloat  v1 
) const

Passes the float values v0 & v1 to the uniform variable "name".

◆ uniform2fv()

SLint SLGLProgram::uniform2fv ( const SLchar name,
SLsizei  count,
const SLfloat value 
) const

Passes 2 float values py pointer to the uniform variable "name".

◆ uniform2i()

SLint SLGLProgram::uniform2i ( const SLchar name,
SLint  v0,
SLint  v1 
) const

Passes the int values v0 & v1 to the uniform variable "name".

◆ uniform2iv()

SLint SLGLProgram::uniform2iv ( const SLchar name,
SLsizei  count,
const SLint value 
) const

Passes 2 int values py pointer to the uniform variable "name".

◆ uniform3f()

SLint SLGLProgram::uniform3f ( const SLchar name,
SLfloat  v0,
SLfloat  v1,
SLfloat  v2 
) const

Passes the float values v0, v1 & v2 to the uniform variable "name".

◆ uniform3fv()

SLint SLGLProgram::uniform3fv ( const SLchar name,
SLsizei  count,
const SLfloat value 
) const

Passes 3 float values py pointer to the uniform variable "name".

◆ uniform3i()

SLint SLGLProgram::uniform3i ( const SLchar name,
SLint  v0,
SLint  v1,
SLint  v2 
) const

Passes the int values v0, v1 & v2 to the uniform variable "name".

◆ uniform3iv()

SLint SLGLProgram::uniform3iv ( const SLchar name,
SLsizei  count,
const SLint value 
) const

Passes 3 int values py pointer to the uniform variable "name".

◆ uniform4f()

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".

◆ uniform4fv()

SLint SLGLProgram::uniform4fv ( const SLchar name,
SLsizei  count,
const SLfloat value 
) const

Passes 4 float values py pointer to the uniform variable "name".

◆ uniform4i()

SLint SLGLProgram::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".

◆ uniform4iv()

SLint SLGLProgram::uniform4iv ( const SLchar name,
GLsizei  count,
const SLint value 
) const

Passes 4 int values py pointer to the uniform variable "name".

◆ uniformMatrix2fv() [1/2]

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".

◆ uniformMatrix2fv() [2/2]

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.

◆ uniformMatrix3fv() [1/2]

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".

◆ uniformMatrix3fv() [2/2]

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.

◆ uniformMatrix4fv() [1/2]

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".

◆ uniformMatrix4fv() [2/2]

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.

◆ useProgram()

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.

Member Data Documentation

◆ _isLinked

SLbool SLGLProgram::_isLinked
protected

Flag if program is linked.

◆ _progID

SLuint SLGLProgram::_progID
protected

OpenGL shader program object ID.

◆ _shaders

SLVGLShader SLGLProgram::_shaders
protected

Vector of all shader objects.

◆ _uniforms1f

SLVUniform1f SLGLProgram::_uniforms1f
protected

Vector of uniform1f variables.

◆ _uniforms1i

SLVUniform1i SLGLProgram::_uniforms1i
protected

Vector of uniform1i variables.


The documentation for this class was generated from the following files: