src/gl/basicshaderprogram.h

Fri, 06 Mar 2020 20:13:10 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Fri, 06 Mar 2020 20:13:10 +0200
changeset 70
f21b800b02a4
child 75
204dc77e5654
permissions
-rw-r--r--

Added axes rendering

70
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 #pragma once
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
2 #include "common.h"
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
3
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
4 class AbstractBasicShaderProgram : public QObject, protected QOpenGLFunctions
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
5 {
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
6 Q_OBJECT
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
7 public:
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8 AbstractBasicShaderProgram(QObject* parent = nullptr);
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 ~AbstractBasicShaderProgram() = default;
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 void initialize();
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 Q_SLOT void setViewMatrix(const glm::mat4& newViewMatrix);
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 Q_SLOT void setProjectionMatrix(const glm::mat4& newProjectionMatrix);
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 Q_SLOT void setModelMatrix(const glm::mat4& newModelMatrix);
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14 void draw();
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 void teardown();
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 protected:
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 void setMatrix(const char* name, const glm::mat4& matrix);
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18 void checkForGLErrors();
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 virtual const char* vertexShaderSource() const = 0;
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20 virtual const char* fragmentShaderSource() const = 0;
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 virtual const void* vertexData() const = 0;
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 virtual int vertexSize() const = 0;
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23 virtual int vertexCount() const = 0;
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24 virtual void setupVertexArrays() = 0;
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25 virtual GLenum drawMode() const = 0;
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 bool isInitialized = false;
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27 QOpenGLBuffer buffer;
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 QOpenGLShader vertexShader;
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 QOpenGLShader fragmentShader;
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 std::optional<gl::ShaderProgram> program{std::nullopt};
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 QOpenGLVertexArrayObject vertexArrayObject;
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 };

mercurial