SLProject 4.0.000
SLGLProgramGenerated Class Reference

Generated Shader Program class inherited from SLGLProgram. More...

#include <SLGLProgramGenerated.h>

Inheritance diagram for SLGLProgramGenerated:
[legend]

Public Member Functions

 ~SLGLProgramGenerated () override=default
 
 SLGLProgramGenerated (SLAssetManager *am, const string &programName, SLMaterial *mat, SLVLight *lights)
 ctor for generated shader program More...
 
 SLGLProgramGenerated (SLAssetManager *am, const string &programName, SLMaterial *mat, bool isDrawProg, SLstring geomShader="")
 ctor for generated shader program PS More...
 
void buildProgramCodePS (SLMaterial *mat, bool isDrawProg)
 
void buildProgramCode (SLMaterial *mat, SLVLight *lights)
 
void beginShader (SLCamera *cam, SLMaterial *mat, SLVLight *lights) override
 starter for derived classes More...
 
void endShader () override
 
- Public Member Functions inherited from 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. 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
 

Static Public Member Functions

static bool lightsDoShadowMapping (SLVLight *lights)
 Returns true if at least one of the light does shadow mapping. More...
 
static void buildProgramName (SLMaterial *mat, SLVLight *lights, string &programName)
 Builds unique program name that identifies shader program. More...
 
static void buildProgramNamePS (SLMaterial *mat, string &programName, bool isDrawProg)
 

Private Member Functions

void buildPerPixCook (SLMaterial *mat, SLVLight *lights)
 
void buildPerPixBlinn (SLMaterial *mat, SLVLight *lights)
 
void buildPerPixParticle (SLMaterial *mat)
 
void buildPerPixParticleUpdate (SLMaterial *mat)
 
void buildPerPixVideoBkgdSm (SLVLight *lights)
 

Static Private Member Functions

static string fragInput_u_lightSm (SLVLight *lights)
 
static string fragInput_u_shadowMaps (SLVLight *lights)
 
static string fragFunctionShadowTest (SLVLight *lights)
 Adds the core shadow mapping test routine depending on the lights. More...
 
static string shaderHeader (int numLights)
 Adds shader header code. More...
 
static string shaderHeader ()
 Adds shader header code. More...
 
static void addCodeToShader (SLGLShader *shader, const string &code, const string &name)
 Add vertex shader code to the SLGLShader instance. More...
 

Static Private Attributes

static string generatedShaderPath
 

Additional Inherited Members

- Protected Attributes inherited from SLGLProgram
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

Generated Shader Program class inherited from SLGLProgram.

An instance of this class generates the shader code on the fly at construction time based on the information of the passed material and lights vector. The generated program depends on the following parameters:

  • mat->reflectionModel (Blinn-Phong or Cook-Torrance)
  • mat->textures
  • light->createsShadows
  • active camera for the fog and projection parameters

The shader program gets a unique name with the following pattern:

 genCook-D00-N00-E00-O01-RM00-Sky-C4s
    |    |   |   |   |   |    |   |
    |    |   |   |   |   |    |   + Directional light w. 4 shadow cascades
    |    |   |   |   |   |    + Ambient light from skybox
    |    |   |   |   |   + Roughness-metallic map with index 0 and uv 0
    |    |   |   |   + Ambient Occlusion map with index 0 and uv 1
    |    |   |   + Emissive Map with index 0 and uv 0
    |    |   + Normal Map with index 0 and uv 0
    |    + Diffuse Texture Mapping with index 0 and uv 0
    + Cook-Torrance or Blinn-Phong lighting model

The above example is for a material with 5 textures and a scene with one light. The shader program is constructed when a material is for the first time activated (SLMaterial::activate) and it's program pointer is null. The old system of custom written GLSL shader program is still valid. At the end of SLMaterial::activate the generated vertex and fragment shader get compiled, linked and activated with the OpenGL functions in SLGLShader and SLGLProgram. After successful compilation the shader get exported into the applications config directory if they not yet exist there.

Constructor & Destructor Documentation

◆ ~SLGLProgramGenerated()

SLGLProgramGenerated::~SLGLProgramGenerated ( )
overridedefault

◆ SLGLProgramGenerated() [1/2]

SLGLProgramGenerated::SLGLProgramGenerated ( SLAssetManager am,
const string &  programName,
SLMaterial mat,
SLVLight lights 
)
inline

ctor for generated shader program

◆ SLGLProgramGenerated() [2/2]

SLGLProgramGenerated::SLGLProgramGenerated ( SLAssetManager am,
const string &  programName,
SLMaterial mat,
bool  isDrawProg,
SLstring  geomShader = "" 
)
inline

ctor for generated shader program PS

Member Function Documentation

◆ addCodeToShader()

void SLGLProgramGenerated::addCodeToShader ( SLGLShader shader,
const string &  code,
const string &  name 
)
staticprivate

Add vertex shader code to the SLGLShader instance.

◆ beginShader()

void SLGLProgramGenerated::beginShader ( SLCamera cam,
SLMaterial mat,
SLVLight lights 
)
inlineoverridevirtual

starter for derived classes

Implements SLGLProgram.

◆ buildPerPixBlinn()

void SLGLProgramGenerated::buildPerPixBlinn ( SLMaterial mat,
SLVLight lights 
)
private

◆ buildPerPixCook()

void SLGLProgramGenerated::buildPerPixCook ( SLMaterial mat,
SLVLight lights 
)
private

◆ buildPerPixParticle()

void SLGLProgramGenerated::buildPerPixParticle ( SLMaterial mat)
private

◆ buildPerPixParticleUpdate()

void SLGLProgramGenerated::buildPerPixParticleUpdate ( SLMaterial mat)
private

◆ buildPerPixVideoBkgdSm()

void SLGLProgramGenerated::buildPerPixVideoBkgdSm ( SLVLight lights)
private

◆ buildProgramCode()

void SLGLProgramGenerated::buildProgramCode ( SLMaterial mat,
SLVLight lights 
)

Builds the GLSL program code for the vertex and fragment shaders. The code is only assembled but not compiled and linked. This happens within the before the first draw call from within SLMesh::draw.

Parameters
matParent material pointer
lightsPointer of vector of lights

◆ buildProgramCodePS()

void SLGLProgramGenerated::buildProgramCodePS ( SLMaterial mat,
bool  isDrawProg 
)

Builds the GLSL program code for the vertex, geometry and fragment shaders (for particle system drawing). The code is only assembled but not compiled and linked. This happens within the before the first draw call from within SLMesh::draw.

Parameters
matParent material pointer
isDrawProgFlag if program is for drawing instead of update

◆ buildProgramName()

void SLGLProgramGenerated::buildProgramName ( SLMaterial mat,
SLVLight lights,
string &  programName 
)
static

Builds unique program name that identifies shader program.

See the class information for more insights of the generated name. This function is used in advance of the code generation to check if the program already exists in the asset manager. See SLMaterial::activate.

Parameters
matParent material pointer
lightsPointer of vector of lights
programNameReference to program name string that gets built

The shader program gets a unique name with the following pattern:

genCook-D00-N00-E00-O01-RM00-Sky-C4s
   |    |   |   |   |   |    |   |
   |    |   |   |   |   |    |   + Directional light w. 4 shadow cascades
   |    |   |   |   |   |    + Ambient light from skybox
   |    |   |   |   |   + Roughness-metallic map with index 0 and uv 0
   |    |   |   |   + Ambient Occlusion map with index 0 and uv 1
   |    |   |   + Emissive Map with index 0 and uv 0
   |    |   + Normal Map with index 0 and uv 0
   |    + Diffuse Texture Mapping with index 0 and uv 0
   + Cook-Torrance or Blinn-Phong reflection model

◆ buildProgramNamePS()

void SLGLProgramGenerated::buildProgramNamePS ( SLMaterial mat,
string &  programName,
bool  isDrawProg 
)
static

See the class information for more insights of the generated name. This function is used in advance of the code generation to check if the program already exists in the asset manager. See SLMaterial::activate.

Parameters
matParent material pointer
programNameReference to program name string that gets built
isDrawProgFlag if program is for drawing instead of updating

The shader program gets a unique name with the following pattern:

genCook-D00-N00-E00-O01-RM00-Sky-C4s
   |    |   |   |   |   |    |   |
   |    |   |   |   |   |    |   + Directional light w. 4 shadow cascades
   |    |   |   |   |   |    + Ambient light from skybox
   |    |   |   |   |   + Roughness-metallic map with index 0 and uv 0
   |    |   |   |   + Ambient Occlusion map with index 0 and uv 1
   |    |   |   + Emissive Map with index 0 and uv 0
   |    |   + Normal Map with index 0 and uv 0
   |    + Diffuse Texture Mapping with index 0 and uv 0
   + Cook-Torrance or Blinn-Phong reflection model

◆ endShader()

void SLGLProgramGenerated::endShader ( )
inlineoverridevirtual

Implements SLGLProgram.

◆ fragFunctionShadowTest()

string SLGLProgramGenerated::fragFunctionShadowTest ( SLVLight lights)
staticprivate

Adds the core shadow mapping test routine depending on the lights.

◆ fragInput_u_lightSm()

string SLGLProgramGenerated::fragInput_u_lightSm ( SLVLight lights)
staticprivate

◆ fragInput_u_shadowMaps()

string SLGLProgramGenerated::fragInput_u_shadowMaps ( SLVLight lights)
staticprivate

◆ lightsDoShadowMapping()

bool SLGLProgramGenerated::lightsDoShadowMapping ( SLVLight lights)
static

Returns true if at least one of the light does shadow mapping.

◆ shaderHeader() [1/2]

string SLGLProgramGenerated::shaderHeader ( )
staticprivate

Adds shader header code.

◆ shaderHeader() [2/2]

string SLGLProgramGenerated::shaderHeader ( int  numLights)
staticprivate

Adds shader header code.

Member Data Documentation

◆ generatedShaderPath

string SLGLProgramGenerated::generatedShaderPath
staticprivate

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