jubilant-funicular
GLSLProgram.h
1 #ifndef NTA_GLSLPROGRAM_H_INCLUDED
2 #define NTA_GLSLPROGRAM_H_INCLUDED
3 
4 #include "nta/MyEngine.h"
5 #include "nta/Path.h"
6 
7 typedef unsigned int GLuint;
8 typedef unsigned int GLenum;
9 typedef int GLint;
10 
11 namespace nta {
12  class ContextData;
14  class GLSLProgram {
15  private:
17  void compileShaders(crstring shaderProgName);
18  void compileShaders(crstring vert, crstring frag);
20  GLuint compileShader(crstring shaderFileName, GLenum shaderType) const;
22  GLuint m_programID = 0;
24  GLuint m_vertShaderID = 0, m_fragShaderID = 0;
28  int m_numAttributes = 0;
30  bool m_isLinked = false;
31  public:
33  GLSLProgram();
34  ~GLSLProgram();
36  GLint getUniformLocation(crstring uniformName) const;
38  bool isLinked() const;
40  void addAttribute(crstring attributeName);
42  void linkShaders();
44  void use() const;
46  void unuse() const;
48  void destroy();
50  void reload();
51  friend class ContextData;
52  };
53 }
54 
55 #endif // NTA_GLSLPROGRAM_H_INCLUDED
nta::GLSLProgram::reload
void reload()
Reloads the program.
Definition: GLSLProgram.cpp:130
nta::GLSLProgram
represents a program written in GLSL comprised of a vertex shader and a fragment shader
Definition: GLSLProgram.h:14
nta::GLSLProgram::m_numAttributes
int m_numAttributes
the number of attributes used by the vertex shader
Definition: GLSLProgram.h:28
nta::ContextData
Definition: ContextData.h:17
utils::Path
A (case-sensitive) Path in a file system.
Definition: Path.h:16
nta::GLSLProgram::compileShaders
void compileShaders(crstring shaderProgName)
compiles both the vertex and fragment shaders given their name
Definition: GLSLProgram.cpp:64
nta::GLSLProgram::linkShaders
void linkShaders()
links the compiled shaders to this program
Definition: GLSLProgram.cpp:85
nta::GLSLProgram::m_isLinked
bool m_isLinked
keeps track of whether or not the shaders have been linked
Definition: GLSLProgram.h:30
nta
Definition: Animation2D.h:6
nta::GLSLProgram::m_vert
utils::Path m_vert
The files containing the vertex and fragment shaders.
Definition: GLSLProgram.h:26
nta::GLSLProgram::destroy
void destroy()
deletes this program
Definition: GLSLProgram.cpp:124
nta::GLSLProgram::addAttribute
void addAttribute(crstring attributeName)
makes an attribute useful and assigns it the next available location
Definition: GLSLProgram.cpp:81
nta::GLSLProgram::GLSLProgram
GLSLProgram()
constructor and destructor
Definition: GLSLProgram.cpp:10
nta::GLSLProgram::isLinked
bool isLinked() const
returns whether or not the shaders have been linked
Definition: GLSLProgram.cpp:61
nta::GLSLProgram::unuse
void unuse() const
unbinds this program
Definition: GLSLProgram.cpp:118
nta::GLSLProgram::getUniformLocation
GLint getUniformLocation(crstring uniformName) const
returns the location of a uniform in the shaders
Definition: GLSLProgram.cpp:53
nta::GLSLProgram::m_programID
GLuint m_programID
the id for the program
Definition: GLSLProgram.h:22
nta::GLSLProgram::m_vertShaderID
GLuint m_vertShaderID
the ids for the vertex and fragment shaders
Definition: GLSLProgram.h:24
nta::GLSLProgram::use
void use() const
binds this program
Definition: GLSLProgram.cpp:112
nta::GLSLProgram::compileShader
GLuint compileShader(crstring shaderFileName, GLenum shaderType) const
compiles a shader from a file and returns its id
Definition: GLSLProgram.cpp:18