Shader.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #ifndef __SHADER_H__
  2. #define __SHADER_H__
  3. #include <QOpenGLFunctions_3_3_Core>
  4. #include <QOpenGLFunctions>
  5. #include <qchar.h>
  6. #include <qglobal.h>
  7. class Shader
  8. {
  9. public:
  10. Shader(const QString vertexPath, const QString fragmentPath);
  11. ~Shader();
  12. void use();
  13. GLuint getProgramID() const;
  14. /* 设置uniform工具 */
  15. void setBool(const QString &name, bool value);
  16. void setInt(const QString &name, int value);
  17. void setFloat(const QString &name, float value);
  18. private:
  19. /* 打开着色器文件,加载着色器代码 */
  20. bool loadShaderSourceFromFile(const QString &filePath, QByteArray &outShaderSource);
  21. /* 编译着色器 */
  22. GLuint compileShader(const QByteArray &shaderSource, GLenum shaderType);
  23. /* 打印编译错误 */
  24. void printOpenGLCompileError(GLuint errorCode);
  25. /* 打印着色器链接错误 */
  26. void printOpenGLLinkError(GLuint errorCode);
  27. private:
  28. GLuint m_programID = 0;
  29. QOpenGLFunctions* m_glFuncs = nullptr;
  30. };
  31. #endif // __SHADER_H__