Mon, 19 Jul 2021 19:28:16 +0300
Add connections
70 | 1 | #pragma once |
2 | #include "common.h" | |
3 | ||
75
204dc77e5654
document AbstractBasicShaderProgram
Teemu Piippo <teemu@hecknology.net>
parents:
70
diff
changeset
|
4 | /** |
204dc77e5654
document AbstractBasicShaderProgram
Teemu Piippo <teemu@hecknology.net>
parents:
70
diff
changeset
|
5 | * @brief Base class for basic shader programs |
204dc77e5654
document AbstractBasicShaderProgram
Teemu Piippo <teemu@hecknology.net>
parents:
70
diff
changeset
|
6 | * |
204dc77e5654
document AbstractBasicShaderProgram
Teemu Piippo <teemu@hecknology.net>
parents:
70
diff
changeset
|
7 | * A basic program is a collection of a single VAO with a single VBO, |
204dc77e5654
document AbstractBasicShaderProgram
Teemu Piippo <teemu@hecknology.net>
parents:
70
diff
changeset
|
8 | * a vertex shader and a fragment shader. This program deals with these |
204dc77e5654
document AbstractBasicShaderProgram
Teemu Piippo <teemu@hecknology.net>
parents:
70
diff
changeset
|
9 | * components, leaving the program-specific details to the subclasses. |
204dc77e5654
document AbstractBasicShaderProgram
Teemu Piippo <teemu@hecknology.net>
parents:
70
diff
changeset
|
10 | */ |
70 | 11 | class AbstractBasicShaderProgram : public QObject, protected QOpenGLFunctions |
12 | { | |
13 | Q_OBJECT | |
14 | public: | |
15 | AbstractBasicShaderProgram(QObject* parent = nullptr); | |
16 | ~AbstractBasicShaderProgram() = default; | |
17 | void initialize(); | |
18 | Q_SLOT void setViewMatrix(const glm::mat4& newViewMatrix); | |
19 | Q_SLOT void setProjectionMatrix(const glm::mat4& newProjectionMatrix); | |
20 | Q_SLOT void setModelMatrix(const glm::mat4& newModelMatrix); | |
21 | void draw(); | |
22 | void teardown(); | |
23 | protected: | |
24 | void setMatrix(const char* name, const glm::mat4& matrix); | |
25 | void checkForGLErrors(); | |
75
204dc77e5654
document AbstractBasicShaderProgram
Teemu Piippo <teemu@hecknology.net>
parents:
70
diff
changeset
|
26 | /// \returns the source code of the vertex shader |
70 | 27 | virtual const char* vertexShaderSource() const = 0; |
75
204dc77e5654
document AbstractBasicShaderProgram
Teemu Piippo <teemu@hecknology.net>
parents:
70
diff
changeset
|
28 | /// \returns the source code of the fragment shader |
70 | 29 | virtual const char* fragmentShaderSource() const = 0; |
75
204dc77e5654
document AbstractBasicShaderProgram
Teemu Piippo <teemu@hecknology.net>
parents:
70
diff
changeset
|
30 | /// \returns the vertex data for the VBO |
70 | 31 | virtual const void* vertexData() const = 0; |
75
204dc77e5654
document AbstractBasicShaderProgram
Teemu Piippo <teemu@hecknology.net>
parents:
70
diff
changeset
|
32 | /// \returns the size of a single vertex in bytes |
70 | 33 | virtual int vertexSize() const = 0; |
75
204dc77e5654
document AbstractBasicShaderProgram
Teemu Piippo <teemu@hecknology.net>
parents:
70
diff
changeset
|
34 | /// \returns the amount of vertices in the data |
70 | 35 | virtual int vertexCount() const = 0; |
75
204dc77e5654
document AbstractBasicShaderProgram
Teemu Piippo <teemu@hecknology.net>
parents:
70
diff
changeset
|
36 | /// Called during initialization to set up the VAO. Set up your vertex array attributes here. |
70 | 37 | virtual void setupVertexArrays() = 0; |
75
204dc77e5654
document AbstractBasicShaderProgram
Teemu Piippo <teemu@hecknology.net>
parents:
70
diff
changeset
|
38 | // \returns what kind of elements are drawn (GL_QUADS, GL_TRIANGLES, GL_LINES, etc) |
70 | 39 | virtual GLenum drawMode() const = 0; |
40 | bool isInitialized = false; | |
41 | QOpenGLBuffer buffer; | |
42 | QOpenGLShader vertexShader; | |
43 | QOpenGLShader fragmentShader; | |
44 | std::optional<gl::ShaderProgram> program{std::nullopt}; | |
45 | QOpenGLVertexArrayObject vertexArrayObject; | |
46 | }; |