-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShader.h
58 lines (45 loc) · 1.76 KB
/
Shader.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
// Created by Garret on 12/28/2022.
//
#ifndef HEATMAP_SHADER_H
#define HEATMAP_SHADER_H
#include <string>
#include <glm/mat4x4.hpp>
/// Handles shader compilation in a very basic way, with error messages.
class Shader {
public:
/// The ID of the shader program after linking. Set to 0 for error.
unsigned int id;
/// Construct the shader. Prints error messages if there's a compilation error.
/// \param vertexPath Path to the vertex shader source file.
/// \param fragmentPath Path to the fragment shader source file.
Shader(const std::string &vertexPath, const std::string &fragmentPath);
/// Activates the shader for draw calls.
void use();
/// Sets a shader uniform for a boolean parameter.
/// \param name Shader uniform parameter name.
/// \param value Value to set.
void setBool(const std::string &name, bool value) const;
/// Sets a shader uniform for an integer parameter.
/// \param name Shader uniform parameter name.
/// \param value Value to set.
void setInt(const std::string &name, int value) const;
/// Sets a shader uniform for a float parameter.
/// \param name Shader uniform parameter name.
/// \param value Value to set.
void setFloat(const std::string &name, float value) const;
void setMat4(const std::string &name, const glm::mat4 &mat) const;
private:
enum class ShaderType {
Vertex,
Fragment,
Program
};
std::string vertexPath;
std::string fragmentPath;
/// Performs a check for compile-time errors, printing error messages if needed.
/// \param shader ID of the shader to check.
/// \param type Type of the shader program.
void checkCompileErrors(unsigned int shader, ShaderType shaderType);
};
#endif //HEATMAP_SHADER_H