-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathShader.h
More file actions
67 lines (56 loc) · 1.79 KB
/
Copy pathShader.h
File metadata and controls
67 lines (56 loc) · 1.79 KB
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
#ifndef SHADER_H
#define SHADER_H
#include "Framework.h"
#include <string>
#include <vector>
class Shader {
public:
/**
* Loads a vertex shader and fragment shader, compiles them, and links
* them into a single GPU program. The vertex shader file should be
* at <path>.frag.glsl, and the fragment shader file should be at
* <path>.vert.glsl. If the program fails to compile, then the loaded()
* function will return false.
* @param path the path to the vertex/fragment shader files
*/
Shader(const std::string& path);
/**
* This function deallocates the shader.
*/
~Shader();
/**
* Returns the path used to load this shader (without the file extensions)
* @return the shader path
*/
const std::string& path() const;
/**
* Returns the OpenGL handle for the GPU program. You can use the handle
* with OpenGL like this: glUseProgram(shader->programID());
* Calling glUseProgram() will replace OpenGL's fixed pipeline with your
* vertex/fragment shader. You can also use the program handle to
* get/set uniform values and attributes using glUniformLocation(),
* glUniform(), glAttributeLocation(), and glAttribute().
* @return OpenGL handle to the GPU program
*/
GLuint programID() const;
/**
* If the shader loaded successfully, then this function will return true.
* If the shader didn't load successfully, the error messages can be
* retrieved from the errors() function.
*/
bool loaded() const;
/**
* Returns a string containing all the shader compile errors.
* @return shader compilation errors
*/
const std::string& errors() const;
private:
std::vector<char> readSource(const std::string& path);
std::string path_;
std::string errors_;
GLuint vertexShaderID_;
GLuint fragmentShaderID_;
GLuint programID_;
bool loaded_;
};
#endif