SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLGLShader.h
Go to the documentation of this file.
1 /**
2  * \file SLGLShader.h
3  * \authors Marcus Hudritsch, Martin Christens, http://www.clockworkcoders.com
4  * \date July 2014
5  * \copyright http://opensource.org/licenses/GPL-3.0
6  * \remarks Please use clangformat to format the code. See more code style on
7  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
8 */
9 
10 #ifndef SLGLSHADER_H
11 #define SLGLSHADER_H
12 
13 #include <SLEnums.h>
14 #include <SLObject.h>
15 
16 //-----------------------------------------------------------------------------
17 //! Encapsulation of an OpenGL shader object
18 /*!
19  The SLGLShader class represents a shader object of the OpenGL Shading Language
20  (GLSL). It can load & compile an GLSL shader file and is later on attached
21  to an OpenGL program (SLGLProgram). Instances of SLShader are owned and
22  deleted by their program (SLGLProgram).
23 */
24 class SLGLShader : public SLObject
25 {
26  friend class SLGLProgram;
27 
28 public:
29  SLGLShader();
30  SLGLShader(const SLstring& filename,
32  ~SLGLShader() override;
33 
34  void load(const SLstring& filename);
35  void loadFromMemory(const SLstring& program);
37  static SLstring removeComments(SLstring src);
38 
39  // Getters
40  SLShaderType type() { return _type; }
41  SLuint shaderID() const { return _shaderID; }
42  SLstring code() { return _code; }
43 
44  // Setters
45  void code(SLstring strCode) { _code = strCode; }
46  void file(SLstring strFile) { _file = strFile; }
47 
48 private:
52 
53 protected:
54  SLShaderType _type; //!< Shader type enumeration
55  SLuint _shaderID; //!< Program Object
56  SLstring _code; //!< ASCII Source-Code
57  SLstring _file; //!< Path & filename of shader
58 };
59 //-----------------------------------------------------------------------------
60 #endif // SLGLSHADER_H
unsigned int SLuint
Definition: SL.h:171
bool SLbool
Definition: SL.h:175
string SLstring
Definition: SL.h:158
SLShaderType
Shader type enumeration for vertex or fragment (pixel) shader.
Definition: SLEnums.h:222
vector< SLLight * > SLVLight
STL vector of light pointers.
Definition: SLLight.h:232
Encapsulation of an OpenGL shader program object.
Definition: SLGLProgram.h:56
Encapsulation of an OpenGL shader object.
Definition: SLGLShader.h:25
SLstring preprocessIncludePragmas(SLstring inCode)
Replaces our custom pragma include directives in GLSL code.
Definition: SLGLShader.cpp:254
SLuint _shaderID
Program Object.
Definition: SLGLShader.h:55
SLstring code()
Definition: SLGLShader.h:42
SLuint shaderID() const
Definition: SLGLShader.h:41
void load(const SLstring &filename)
SLGLShader::load loads a shader file into string _shaderSource.
Definition: SLGLShader.cpp:54
SLShaderType _type
Shader type enumeration.
Definition: SLGLShader.h:54
SLstring _file
Path & filename of shader.
Definition: SLGLShader.h:57
void code(SLstring strCode)
Definition: SLGLShader.h:45
SLstring typeName()
Returns the shader type as string.
Definition: SLGLShader.cpp:241
void file(SLstring strFile)
Definition: SLGLShader.h:46
SLstring _code
ASCII Source-Code.
Definition: SLGLShader.h:56
SLbool createAndCompile(SLVLight *lights)
SLGLShader::createAndCompile creates & compiles the OpenGL shader object.
Definition: SLGLShader.cpp:86
void loadFromMemory(const SLstring &program)
SLGLShader::load loads a shader file from memory into memory.
Definition: SLGLShader.cpp:69
SLstring preprocessDefinePragmas(SLstring inCode, SLVLight *lights)
Replaces our custom pragma define directives in GLSL code.
Definition: SLGLShader.cpp:304
~SLGLShader() override
Definition: SLGLShader.cpp:74
SLShaderType type()
Definition: SLGLShader.h:40
static SLstring removeComments(SLstring src)
SLGLShader::removeComments for C/C++ comments removal from shader code.
Definition: SLGLShader.cpp:201
SLGLShader()
Default constructor.
Definition: SLGLShader.cpp:26
Base class for all other classes.
Definition: SLObject.h:23