-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshader.h
91 lines (78 loc) · 2.93 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# pragma once
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <filesystem>
#include <cstring>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <GL/gl.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
/**
* @brief Class Shader handles all shader program operations such as reading shaders from files, compiling shaders, and creating new shader program.
*/
class Shader
{
public:
/**
* @brief Costructor to build Shader object from shader files.
* @param vertexLocation Path to vertex shader file.
* @param fragmentLocation Path to fragment shader file.
*/
Shader(const char* vertexLocation, const char* fragmentLocation);
/**
* @brief Destructor
*/
~Shader();
/**
* @brief Read file from filesystem.
* @param filename Path to file.
*/
std::string readFile(std::string filename);
/**
* @brief Load texture from image in local storage
* @param filename Path to image file.
* @param texture Pointer to texture variable to bind texture image to.
* @param target Specifies which target to apply operations (GL_TEXTURE_2D, GL_ARRAY_BUFFER, etc.).
* @param level Specifies level of detail, level 0 is base image and level n is nth mimap image reduction.
* @param internalFormat Specifies number of colors components in texture.
* @param border This value must be 0.
* @param format Specifies the format of pixel data from texture image.
* @param type Specifies the data type of pixel data from texture image.
*/
void loadTexture(std::string filename, GLuint *texture, GLenum target, GLenum textureParam, GLenum filterParam, GLint level, GLint internalFormat, GLint border, GLint format, GLenum type);
/**
* @brief Use this object's shader program.
*/
void use();
void unbind();
/**
* @brief Clear shader program.
*/
void clear();
void enableDepth();
GLuint getID() const { return ID; }
// Utility uniform functions
void setBool(const std::string& name, bool value) const;
void setInt(const std::string& name, int value) const;
void setFloat(const std::string& name, float value) const;
void setMatrix4fv(const std::string &name, GLsizei count, GLboolean transpose, const GLfloat *value) const;
private:
GLuint ID; // Holds shader program ID
/**
* @brief Compile vertex and fragment shaders.
* @param vertexCode Vertex shader source code.
* @param fragmentCode Fragment shader source code.
*/
void compileShader(const char* vertexCode, const char* fragmentCode);
/**
* @brief Add shader to shader program.
* @param program Shader program to add shader to.
* @param shaderCode Shader source code to add.
* @param shaderType Specifies if it's vertex or fragment shader.
*/
void addShader(GLuint program, const char* shaderCode, GLenum shaderType);
};