Fireworks Engine  v2.0
Lightweight Sandbox Game Engine using OpenGL for additional Customisation and Quick Prototyping
Shader.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <iostream>
4 #include <unordered_map>
5 // GLEW
6 #include <GL/glew.h>
7 #include <src/utils/fileutils.h>
8 #include <glm/glm.hpp>
9 // GLM
10 #include <glm/glm.hpp>
11 #include <glm/gtc/matrix_transform.hpp>
12 #include <glm/gtc/type_ptr.hpp>
13 
14 namespace fireworks { namespace graphics {
15 
16 #define SHADER_VERTEX_INDEX 0
17 #define SHADER_UV_INDEX 1
18 #define SHADER_TID_INDEX 2
19 #define SHADER_COLOR_INDEX 3
20 
22  class Shader
23  {
24  public:
26  GLuint m_ShaderID;
28  const char* m_VertPath;
30  const char* m_FragPath;
31  private:
32  std::unordered_map<std::string, GLint> m_ShaderLocationCache;
33  public:
38  Shader(const char* vertexPath, const char* fragmentPath);
39  ~Shader();
40 
41  void setUniform1f(const GLchar* name, float value);
42  void setUniform1fv(const GLchar* name, float* value, GLsizei count);
43  void setUniform1i(const GLchar* name, int value);
44  void setUniform1iv(const GLchar* name, int* value, GLsizei count);
45  void setUniform2f(const GLchar* name, const glm::vec2& vector);
46  void setUniform3f(const GLchar* name, const glm::vec3& vector);
47  void setUniform4f(const GLchar* name, const glm::vec4& vector);
48  void setUniformMat4(const GLchar* name, const glm::mat4& matrix);
49 
51  void enable();
53  void disable();
54 
56  inline GLint getShaderProgram() const { return m_ShaderID; }
57  private:
58  GLuint load();
59  GLint getUniformLocation(const std::string& name);
60  };
61 
62 } }
Shader(const char *vertexPath, const char *fragmentPath)
Creates the shader by taking in the vertex and fragment shader files.
Definition: Shader.cpp:5
void setUniform2f(const GLchar *name, const glm::vec2 &vector)
Definition: Shader.cpp:99
GLuint m_ShaderID
The ID of the shader.
Definition: Shader.h:26
const char * m_VertPath
Path to the vertex shader file.
Definition: Shader.h:28
Definition: audioclip.cpp:3
void setUniform1i(const GLchar *name, int value)
Definition: Shader.cpp:89
The class responsible for creating amazing shaders.
Definition: Shader.h:22
void setUniformMat4(const GLchar *name, const glm::mat4 &matrix)
Definition: Shader.cpp:114
void enable()
Enables the shader.
Definition: Shader.cpp:119
void setUniform4f(const GLchar *name, const glm::vec4 &vector)
Definition: Shader.cpp:109
void disable()
Disables the shader.
Definition: Shader.cpp:124
void setUniform1f(const GLchar *name, float value)
Definition: Shader.cpp:79
void setUniform3f(const GLchar *name, const glm::vec3 &vector)
Definition: Shader.cpp:104
const char * m_FragPath
Path to the fragment shader file.
Definition: Shader.h:30
void setUniform1fv(const GLchar *name, float *value, GLsizei count)
Definition: Shader.cpp:84
~Shader()
Definition: Shader.cpp:10
void setUniform1iv(const GLchar *name, int *value, GLsizei count)
Definition: Shader.cpp:94
GLint getShaderProgram() const
Gets the shaders Program.
Definition: Shader.h:56