SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLGLProgramManager.cpp
Go to the documentation of this file.
1 /**
2  * \file SLGLProgramManager.cpp
3  * \date March 2020
4  * \remarks Please use clangformat to format the code. See more code style on
5  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
6  * \authors Michael Goettlicher, Marcus Hudritsch
7  * \copyright http://opensource.org/licenses/GPL-3.0
8  */
9 
10 #include <SLGLProgramManager.h>
11 #include <SLGLProgramGeneric.h>
12 
13 //-----------------------------------------------------------------------------
16 std::map<SLStdShaderProg, SLGLProgramGeneric*> SLGLProgramManager::_programs;
17 //-----------------------------------------------------------------------------
18 /*!
19  * \param shdrPath Path to the shader files
20  * \param confPath Path to the writable config directory
21  */
22 void SLGLProgramManager::init(string shaderPath, string configPath)
23 {
26 }
27 //-----------------------------------------------------------------------------
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 }
62 //-----------------------------------------------------------------------------
64 {
65  for (auto it : _programs)
66  delete it.second;
67  _programs.clear();
68 }
69 //-----------------------------------------------------------------------------
71  string vertShaderFilename,
72  string fragShaderFilename)
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 }
83 //-----------------------------------------------------------------------------
string SLstring
Definition: SL.h:158
@ UT_const
constant value
Definition: SLEnums.h:233
SLStdShaderProg
Enumeration for standard shader programs.
@ SP_colorUniform
@ SP_colorUniformPoint
@ SP_colorAttribute
@ SP_textureOnly
@ SP_errorTex
@ SP_fontTex
@ SP_textureOnlyExternal
@ SP_depth
SLGLUniform< SLfloat > SLGLUniform1f
Definition: SLGLUniform.h:149
Generic Shader Program class inherited from SLGLProgram.
Encapsulation of an OpenGL shader program object.
Definition: SLGLProgram.h:56
void addUniform1f(SLGLUniform1f *u)
add float uniform
static string configPath
Contains the global writable configuration path.
static void init(string shaderPath, string configPath)
Init by providing path to standard shader files.
static string shaderPath
Contains the global shader path.
static SLGLProgramGeneric * loadProgram(SLStdShaderProg id, string vertShaderFilename, string fragShaderFilename)
Make a new program and insert it into _programs.
static std::map< SLStdShaderProg, SLGLProgramGeneric * > _programs
Instantiated programs.
static void deletePrograms()
Delete all instantiated programs.
static void loadPrograms()
Instantiate and load all programs.