1 #pragma once |
1 #pragma once |
2 #include "common.h" |
2 #include "common.h" |
3 |
3 |
|
4 /** |
|
5 * @brief Base class for basic shader programs |
|
6 * |
|
7 * A basic program is a collection of a single VAO with a single VBO, |
|
8 * a vertex shader and a fragment shader. This program deals with these |
|
9 * components, leaving the program-specific details to the subclasses. |
|
10 */ |
4 class AbstractBasicShaderProgram : public QObject, protected QOpenGLFunctions |
11 class AbstractBasicShaderProgram : public QObject, protected QOpenGLFunctions |
5 { |
12 { |
6 Q_OBJECT |
13 Q_OBJECT |
7 public: |
14 public: |
8 AbstractBasicShaderProgram(QObject* parent = nullptr); |
15 AbstractBasicShaderProgram(QObject* parent = nullptr); |
14 void draw(); |
21 void draw(); |
15 void teardown(); |
22 void teardown(); |
16 protected: |
23 protected: |
17 void setMatrix(const char* name, const glm::mat4& matrix); |
24 void setMatrix(const char* name, const glm::mat4& matrix); |
18 void checkForGLErrors(); |
25 void checkForGLErrors(); |
|
26 /// \returns the source code of the vertex shader |
19 virtual const char* vertexShaderSource() const = 0; |
27 virtual const char* vertexShaderSource() const = 0; |
|
28 /// \returns the source code of the fragment shader |
20 virtual const char* fragmentShaderSource() const = 0; |
29 virtual const char* fragmentShaderSource() const = 0; |
|
30 /// \returns the vertex data for the VBO |
21 virtual const void* vertexData() const = 0; |
31 virtual const void* vertexData() const = 0; |
|
32 /// \returns the size of a single vertex in bytes |
22 virtual int vertexSize() const = 0; |
33 virtual int vertexSize() const = 0; |
|
34 /// \returns the amount of vertices in the data |
23 virtual int vertexCount() const = 0; |
35 virtual int vertexCount() const = 0; |
|
36 /// Called during initialization to set up the VAO. Set up your vertex array attributes here. |
24 virtual void setupVertexArrays() = 0; |
37 virtual void setupVertexArrays() = 0; |
|
38 // \returns what kind of elements are drawn (GL_QUADS, GL_TRIANGLES, GL_LINES, etc) |
25 virtual GLenum drawMode() const = 0; |
39 virtual GLenum drawMode() const = 0; |
26 bool isInitialized = false; |
40 bool isInitialized = false; |
27 QOpenGLBuffer buffer; |
41 QOpenGLBuffer buffer; |
28 QOpenGLShader vertexShader; |
42 QOpenGLShader vertexShader; |
29 QOpenGLShader fragmentShader; |
43 QOpenGLShader fragmentShader; |