-
Notifications
You must be signed in to change notification settings - Fork 1
/
Shader.h
66 lines (55 loc) · 2.05 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
#ifndef SHADER_H
#define SHADER_H
#include <QOpenGLShaderProgram>
#include <QString>
class Shader
{
friend class ResourceManager;
public:
Shader(){}
//Shader(const QString& vertexSourcePath,const QString& fragmentSourcePath);
void compile(const QString& vertexSource, const QString& fragmentSource, const QString& geometrySource = nullptr);
~Shader();
QOpenGLShaderProgram* shaderProgram;
Shader& use(){
shaderProgram->bind();
return *this;
}
inline void setMatrix4f(const QString& name,const QMatrix4x4& value);
inline void setInteger(const QString& name,const GLint value);
inline void setVector3f(const QString& name, const GLfloat& x, const GLfloat& y, const GLfloat& z);
inline void setVector3f(const QString& name, const QVector3D& value);
inline void setFloat(const QString& name,const GLfloat value);
inline void setBool(const QString& name,const GLboolean value);
};
inline void Shader::setMatrix4f(const QString &name, const QMatrix4x4 &value)
{
GLint loc = shaderProgram->uniformLocation(name);
shaderProgram->setUniformValue(loc,value);
}
inline void Shader::setInteger(const QString &name, const GLint value)
{
GLint loc = shaderProgram->uniformLocation(name);
shaderProgram->setUniformValue(loc,value);
}
inline void Shader::setVector3f(const QString& name, const GLfloat& x, const GLfloat& y, const GLfloat& z)
{
GLint loc = shaderProgram->uniformLocation(name);
shaderProgram->setUniformValue(loc,QVector3D(x,y,z));
}
inline void Shader::setVector3f(const QString &name, const QVector3D &value)
{
GLint loc = shaderProgram->uniformLocation(name);
shaderProgram->setUniformValue(loc, value);
}
inline void Shader::setFloat(const QString &name, const GLfloat value)
{
GLint loc = shaderProgram->uniformLocation(name);
shaderProgram->setUniformValue(loc,value);
}
inline void Shader::setBool(const QString &name, const GLboolean value)
{
GLint loc = shaderProgram->uniformLocation(name);
shaderProgram->setUniformValue(loc,value);
}
#endif // SHADER_H