src/gl/partrenderer.h

Sat, 29 Feb 2020 23:51:03 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 29 Feb 2020 23:51:03 +0200
changeset 65
87c906545fc3
parent 61
4585d8d7a7ec
child 66
77c819262b7a
permissions
-rw-r--r--

document the grid snapping transformations

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:
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 34
diff changeset
18 PartRenderer(
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 34
diff changeset
19 Model* model,
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 34
diff changeset
20 DocumentManager* documents,
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 34
diff changeset
21 const ldraw::ColorTable& colorTable,
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 34
diff changeset
22 QWidget* parent = nullptr);
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
23 ~PartRenderer() override;
39
caac957e9834 Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents: 37
diff changeset
24 void setRenderPreferences(const gl::RenderPreferences& newPreferences);
17
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25 protected:
47
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents: 39
diff changeset
26 ldraw::Id pick(const QPoint& where);
17
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27 void initializeGL() override;
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 void resizeGL(int width, int height) override;
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 void paintGL() override;
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 void mouseMoveEvent(QMouseEvent* event) override;
31
b6df269a2c6b fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents: 30
diff changeset
31 void wheelEvent(QWheelEvent* event) override;
51
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
32 Model* const model;
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
33 DocumentManager* const documents;
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
34 const ldraw::ColorTable& colorTable;
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
35 gl::Compiler* const compiler;
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
36 ldraw::Id highlighted = ldraw::NULL_ID;
58
b7841cd31fb7 use glm::project instead of figuring out the conversion manually...
Teemu Piippo <teemu@hecknology.net>
parents: 57
diff changeset
37 std::optional<glm::vec3> screenToModelCoordinates(const QPoint& point, const geom::Plane& plane);
56
fad4a5dd8dee PartRenderer::modelToScreenCoordinates FINALLY WORKS
Teemu Piippo <teemu@hecknology.net>
parents: 55
diff changeset
38 QPointF modelToScreenCoordinates(const glm::vec3& point);
57
5c0005f63319 use glm::unProject to implement screenToModelCoordinates
Teemu Piippo <teemu@hecknology.net>
parents: 56
diff changeset
39 glm::vec3 unproject(const glm::vec3& win);
61
4585d8d7a7ec moved GridProgram to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 58
diff changeset
40 glm::mat4 projectionMatrix;
4585d8d7a7ec moved GridProgram to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 58
diff changeset
41 glm::mat4 viewMatrix;
4585d8d7a7ec moved GridProgram to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 58
diff changeset
42 glm::mat4 modelMatrix;
4585d8d7a7ec moved GridProgram to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 58
diff changeset
43 glm::vec4 viewportVector;
4585d8d7a7ec moved GridProgram to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 58
diff changeset
44 glm::quat modelQuaternion;
4585d8d7a7ec moved GridProgram to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 58
diff changeset
45 QPoint lastMousePosition;
4585d8d7a7ec moved GridProgram to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 58
diff changeset
46 gl::RenderPreferences renderPreferences;
4585d8d7a7ec moved GridProgram to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 58
diff changeset
47 signals:
4585d8d7a7ec moved GridProgram to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 58
diff changeset
48 void projectionMatrixChanged();
4585d8d7a7ec moved GridProgram to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 58
diff changeset
49 void modelMatrixChanged();
4585d8d7a7ec moved GridProgram to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 58
diff changeset
50 void viewMatrixChanged();
4585d8d7a7ec moved GridProgram to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 58
diff changeset
51 void renderPreferencesChanged();
17
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
52 private:
37
90443fb328ea wired renderstyle up
Teemu Piippo <teemu@hecknology.net>
parents: 36
diff changeset
53 void setFragmentStyle(gl::FragmentStyle fragStyle);
90443fb328ea wired renderstyle up
Teemu Piippo <teemu@hecknology.net>
parents: 36
diff changeset
54 void renderAllArrays();
22
6da867fa5429 commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
55 void renderScene();
31
b6df269a2c6b fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents: 30
diff changeset
56 void updateViewMatrix();
55
cb81ecb5fb23 grid stuff
Teemu Piippo <teemu@hecknology.net>
parents: 53
diff changeset
57 void updateModelMatrix();
cb81ecb5fb23 grid stuff
Teemu Piippo <teemu@hecknology.net>
parents: 53
diff changeset
58 void setupBackgroundColor();
31
b6df269a2c6b fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents: 30
diff changeset
59 static constexpr double MIN_ZOOM = 0.0;
b6df269a2c6b fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents: 30
diff changeset
60 static constexpr double MAX_ZOOM = 3.0;
b6df269a2c6b fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents: 30
diff changeset
61 double zoom = 1.0;
22
6da867fa5429 commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
62 bool initialized = false;
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
63 void renderVao(const gl::ArrayClass arrayClass);
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
64 void checkForGLErrors();
17
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
65 };

mercurial