SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLGLProgramManager Class Reference

Static container for standard shader programs. More...

#include <SLGLProgramManager.h>

Static Public Member Functions

static void init (string shaderPath, string configPath)
 Init by providing path to standard shader files. More...
 
static SLGLProgramGenericget (SLStdShaderProg id)
 Get program reference for given id. More...
 
static void loadPrograms ()
 Instantiate and load all programs. More...
 
static void deletePrograms ()
 Delete all instantiated programs. More...
 
static size_t size ()
 Returns the size of the program map. More...
 

Static Public Attributes

static string shaderPath
 Contains the global shader path. More...
 
static string configPath
 Contains the global writable configuration path. More...
 

Static Private Member Functions

static SLGLProgramGenericloadProgram (SLStdShaderProg id, string vertShaderFilename, string fragShaderFilename)
 Make a new program and insert it into _programs. More...
 

Static Private Attributes

static std::map< SLStdShaderProg, SLGLProgramGeneric * > _programs
 Instantiated programs. More...
 

Detailed Description

Static container for standard shader programs.

Static container for standard shader programs that are not deleted after scene deallocation. The shader program allocation and compilation will be done at the first use. ONLY shader programs that are scene independent should be stored here. Shader programs that depend e.g. on the number of lights must be created at scene loading time and deallocation at scene destruction.

Definition at line 45 of file SLGLProgramManager.h.

Member Function Documentation

◆ deletePrograms()

void SLGLProgramManager::deletePrograms ( )
static

Delete all instantiated programs.

Definition at line 63 of file SLGLProgramManager.cpp.

64 {
65  for (auto it : _programs)
66  delete it.second;
67  _programs.clear();
68 }
static std::map< SLStdShaderProg, SLGLProgramGeneric * > _programs
Instantiated programs.

◆ get()

static SLGLProgramGeneric* SLGLProgramManager::get ( SLStdShaderProg  id)
inlinestatic

Get program reference for given id.

Definition at line 52 of file SLGLProgramManager.h.

52 { return _programs[id]; }

◆ init()

void SLGLProgramManager::init ( string  shaderPath,
string  configPath 
)
static

Init by providing path to standard shader files.

Parameters
shdrPathPath to the shader files
confPathPath to the writable config directory

Definition at line 22 of file SLGLProgramManager.cpp.

23 {
26 }
static string configPath
Contains the global writable configuration path.
static string shaderPath
Contains the global shader path.

◆ loadProgram()

SLGLProgramGeneric * SLGLProgramManager::loadProgram ( SLStdShaderProg  id,
string  vertShaderFilename,
string  fragShaderFilename 
)
staticprivate

Make a new program and insert it into _programs.

Definition at line 70 of file SLGLProgramManager.cpp.

73 {
74  SLstring vertShaderPath = shaderPath + vertShaderFilename;
75  SLstring fragShaderPath = shaderPath + fragShaderFilename;
76 
77  SLGLProgramGeneric* program = new SLGLProgramGeneric(nullptr,
78  vertShaderPath,
79  fragShaderPath);
80  _programs.insert({id, program});
81  return program;
82 }
string SLstring
Definition: SL.h:158
Generic Shader Program class inherited from SLGLProgram.

◆ loadPrograms()

void SLGLProgramManager::loadPrograms ( )
static

Instantiate and load all programs.

Definition at line 28 of file SLGLProgramManager.cpp.

29 {
30  assert(!shaderPath.empty() &&
31  "Error in SLGLProgramManager: shader path is empty!");
32 
34  "ColorAttribute.vert",
35  "Color.frag");
37  "ColorUniform.vert",
38  "Color.frag");
40  "TextureOnly.vert",
41  "TextureOnly.frag");
43  "TextureOnlyExternal.vert",
44  "TextureOnlyExternal.frag");
46  "FontTex.vert",
47  "FontTex.frag");
49  "ErrorTex.vert",
50  "ErrorTex.frag");
52  "Depth.vert",
53  "Depth.frag");
54 
55  SLGLProgram* colorUniformPoint = loadProgram(SP_colorUniformPoint,
56  "ColorUniformPoint.vert",
57  "Color.frag");
58  colorUniformPoint->addUniform1f(new SLGLUniform1f(UT_const,
59  "u_pointSize",
60  3.0f));
61 }
@ UT_const
constant value
Definition: SLEnums.h:233
@ SP_colorUniform
@ SP_colorUniformPoint
@ SP_colorAttribute
@ SP_textureOnly
@ SP_errorTex
@ SP_fontTex
@ SP_textureOnlyExternal
@ SP_depth
SLGLUniform< SLfloat > SLGLUniform1f
Definition: SLGLUniform.h:149
Encapsulation of an OpenGL shader program object.
Definition: SLGLProgram.h:56
void addUniform1f(SLGLUniform1f *u)
add float uniform
static SLGLProgramGeneric * loadProgram(SLStdShaderProg id, string vertShaderFilename, string fragShaderFilename)
Make a new program and insert it into _programs.

◆ size()

static size_t SLGLProgramManager::size ( )
inlinestatic

Returns the size of the program map.

Definition at line 61 of file SLGLProgramManager.h.

61 { return _programs.size(); }

Member Data Documentation

◆ _programs

std::map< SLStdShaderProg, SLGLProgramGeneric * > SLGLProgramManager::_programs
staticprivate

Instantiated programs.

Definition at line 76 of file SLGLProgramManager.h.

◆ configPath

string SLGLProgramManager::configPath
static

Contains the global writable configuration path.

Definition at line 67 of file SLGLProgramManager.h.

◆ shaderPath

string SLGLProgramManager::shaderPath
static

Contains the global shader path.

Definition at line 64 of file SLGLProgramManager.h.


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