src/gl/partrenderer.h

Sun, 26 Jan 2020 14:29:30 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 26 Jan 2020 14:29:30 +0200
changeset 33
4c41bfe2ec6e
parent 31
b6df269a2c6b
child 34
1de2b8d64e9f
permissions
-rw-r--r--

replaced matrix and vertex classes with glm

17
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 #pragma once
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
2 #include <QOpenGLWidget>
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
3 #include <QOpenGLFunctions>
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
4 #include <QQuaternion>
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
5 #include <QOpenGLVertexArrayObject>
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
6 #include <QOpenGLBuffer>
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
7 #include <QOpenGLShader>
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
8 #include <QOpenGLShaderProgram>
28
c92c1daf735f modelview matrix set up
Teemu Piippo <teemu@hecknology.net>
parents: 27
diff changeset
9 #include <glm/glm.hpp>
17
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 #include "main.h"
18
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
11 #include "gl/common.h"
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
12 #include "gl/compiler.h"
17
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14 class PartRenderer : public QOpenGLWidget, protected QOpenGLFunctions
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 {
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
16 Q_OBJECT
17
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 public:
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
18 PartRenderer(Model* model, DocumentManager* documents, const ColorTable& colorTable, QWidget* parent = nullptr);
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
19 ~PartRenderer() override;
17
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20 protected:
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 void initializeGL() override;
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 void resizeGL(int width, int height) override;
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23 void paintGL() override;
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24 void mouseMoveEvent(QMouseEvent* event) override;
31
b6df269a2c6b fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents: 30
diff changeset
25 void wheelEvent(QWheelEvent* event) override;
18
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
26 private slots:
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
27 void setRenderStyle(const gl::RenderStyle newStyle);
17
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 private:
22
6da867fa5429 commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
29 void renderScene();
31
b6df269a2c6b fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents: 30
diff changeset
30 void updateViewMatrix();
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
31 Model* const model;
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
32 DocumentManager* const documents;
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
33 const ColorTable& colorTable;
17
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 QPointF lastMousePosition;
22
6da867fa5429 commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
35 gl::Compiler* compiler;
18
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
36 gl::RenderStyle renderStyle = gl::RenderStyle::Normal;
28
c92c1daf735f modelview matrix set up
Teemu Piippo <teemu@hecknology.net>
parents: 27
diff changeset
37 glm::mat4 projectionMatrix;
c92c1daf735f modelview matrix set up
Teemu Piippo <teemu@hecknology.net>
parents: 27
diff changeset
38 glm::mat4 viewMatrix;
31
b6df269a2c6b fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents: 30
diff changeset
39 glm::quat modelQuaternion;
b6df269a2c6b fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents: 30
diff changeset
40 static constexpr double MIN_ZOOM = 0.0;
b6df269a2c6b fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents: 30
diff changeset
41 static constexpr double MAX_ZOOM = 3.0;
b6df269a2c6b fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents: 30
diff changeset
42 double zoom = 1.0;
22
6da867fa5429 commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
43 bool initialized = false;
17
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44 void initializeLighting();
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
45 void renderVao(const gl::ArrayClass arrayClass);
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
46 void checkForGLErrors();
31
b6df269a2c6b fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents: 30
diff changeset
47 glm::mat4 modelMatrix() const;
17
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
48 };

mercurial