-
Notifications
You must be signed in to change notification settings - Fork 2
/
shader.h
56 lines (38 loc) · 1.22 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
#ifndef SHADER_H
#define SHADER_H
#include <QOpenGLFunctions>
#include <QString>
enum ShaderType { kVertex, kFragment };
class Shader {
public:
Shader(QString path, ShaderType type);
~Shader();
ShaderType Type() const { return type_; }
unsigned int Id() const { return shader_id_; }
bool Compile();
std::unique_ptr<std::string> Log() { return std::move(log_); }
protected:
std::unique_ptr<std::string> ReadSource_();
std::unique_ptr<std::string> FetchLog_() const;
unsigned int shader_id_;
ShaderType type_;
std::string file_path_;
std::unique_ptr<std::string> log_ = nullptr;
QOpenGLFunctions* gl_functions_ = nullptr;
};
class ShaderProgram {
public:
ShaderProgram(std::shared_ptr<Shader> vert, std::shared_ptr<Shader> frag);
~ShaderProgram();
bool Link();
std::unique_ptr<std::string> Log() { return std::move(log_); }
unsigned int Id() const { return program_id_; }
private:
std::unique_ptr<std::string> FetchLog_() const;
unsigned int program_id_;
std::shared_ptr<Shader> vertex_;
std::shared_ptr<Shader> fragment_;
std::unique_ptr<std::string> log_ = nullptr;
QOpenGLFunctions* gl_functions_ = nullptr;
};
#endif // SHADER_H