| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- #ifndef __SHADER_H__
- #define __SHADER_H__
- #include <QOpenGLFunctions_3_3_Core>
- #include <QOpenGLFunctions>
- #include <qchar.h>
- #include <qglobal.h>
- class Shader
- {
- public:
- Shader(const QString vertexPath, const QString fragmentPath);
- ~Shader();
- void use();
- GLuint getProgramID() const;
- /* 设置uniform工具 */
- void setBool(const QString &name, bool value);
- void setInt(const QString &name, int value);
- void setFloat(const QString &name, float value);
- private:
- /* 打开着色器文件,加载着色器代码 */
- bool loadShaderSourceFromFile(const QString &filePath, QByteArray &outShaderSource);
- /* 编译着色器 */
- GLuint compileShader(const QByteArray &shaderSource, GLenum shaderType);
- /* 打印编译错误 */
- void printOpenGLCompileError(GLuint errorCode);
- /* 打印着色器链接错误 */
- void printOpenGLLinkError(GLuint errorCode);
- private:
- GLuint m_programID = 0;
- QOpenGLFunctions* m_glFuncs = nullptr;
- };
- #endif // __SHADER_H__
|