src/gl/partrenderer.h

Wed, 22 Jun 2022 23:32:34 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Wed, 22 Jun 2022 23:32:34 +0300
changeset 257
afdab56e8210
parent 237
10a6298f636f
child 264
76a025db4948
permissions
-rw-r--r--

Fix appearance of ColorButton

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>
237
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
3 #include <QOpenGLDebugLogger>
206
654661eab7f3 More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents: 205
diff changeset
4 #include "basics.h"
18
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
5 #include "gl/common.h"
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
6 #include "gl/compiler.h"
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 199
diff changeset
7 #include "documentmanager.h"
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 199
diff changeset
8 #include "types/boundingbox.h"
17
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9
217
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
10 class PartRenderer final : public QOpenGLWidget
17
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 {
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
12 Q_OBJECT
217
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
13 Model* const model;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
14 DocumentManager* const documents;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
15 const ColorTable& colorTable;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
16 BoundingBox boundingBox;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
17 gl::ModelShaders shaders;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
18 ModelId highlighted = {0};
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
19 glm::mat4 projectionMatrix;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
20 glm::mat4 viewMatrix;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
21 glm::mat4 modelMatrix;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
22 glm::vec4 viewportVector;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
23 glm::quat modelQuaternion;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
24 QPoint lastMousePosition;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
25 int totalMouseMove = 0;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
26 gl::RenderPreferences renderPreferences;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
27 double zoom = 1.0;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
28 bool initialized = false;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
29 bool needBuild = true;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
30 std::vector<RenderLayer*> activeRenderLayers;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
31 std::vector<RenderLayer*> inactiveRenderLayers;
232
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
32 bool frozen = false;
237
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
33 QOpenGLDebugLogger logger;
17
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 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
35 PartRenderer(
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 34
diff changeset
36 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
37 DocumentManager* documents,
205
1a4342d80de7 Refactor colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
38 const ColorTable& colorTable,
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 34
diff changeset
39 QWidget* parent = nullptr);
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
40 ~PartRenderer() override;
39
caac957e9834 Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents: 37
diff changeset
41 void setRenderPreferences(const gl::RenderPreferences& newPreferences);
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 199
diff changeset
42 ModelId getHighlightedObject() const;
215
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
43 void addRenderLayer(RenderLayer* layer);
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
44 void setLayerEnabled(RenderLayer* layer, bool enabled);
217
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
45 std::optional<glm::vec3> screenToModelCoordinates(const QPointF& point, const Plane& plane) const;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
46 QPointF modelToScreenCoordinates(const glm::vec3& point) const;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
47 bool isDark() const;
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 199
diff changeset
48 ModelId pick(QPoint where);
217
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
49 void setSelection(const QSet<ModelId>& selectedIds);
112
5760cbb32bc0 use QT_NO_KEYWORDS
Teemu Piippo <teemu@hecknology.net>
parents: 107
diff changeset
50 Q_SIGNALS:
70
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents: 66
diff changeset
51 void projectionMatrixChanged(const glm::mat4& newMatrix);
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents: 66
diff changeset
52 void modelMatrixChanged(const glm::mat4& newMatrix);
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents: 66
diff changeset
53 void viewMatrixChanged(const glm::mat4& newMatrix);
61
4585d8d7a7ec moved GridProgram to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 58
diff changeset
54 void renderPreferencesChanged();
237
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
55 void message(const Message& message);
17
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
56 private:
217
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
57 void initializeGL() override;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
58 void resizeGL(int width, int height) override;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
59 void paintGL() override;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
60 void mouseMoveEvent(QMouseEvent* event) override;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
61 void mousePressEvent(QMouseEvent* event) override;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
62 void mouseReleaseEvent(QMouseEvent* event) override;
232
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
63 void keyReleaseEvent(QKeyEvent* event) override;
217
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
64 void wheelEvent(QWheelEvent* event) override;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
65 Line<3> cameraLine(const QPointF& point) const;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
66 glm::vec3 unproject(const glm::vec3& win) const;
37
90443fb328ea wired renderstyle up
Teemu Piippo <teemu@hecknology.net>
parents: 36
diff changeset
67 void setFragmentStyle(gl::FragmentStyle fragStyle);
22
6da867fa5429 commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
68 void renderScene();
31
b6df269a2c6b fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents: 30
diff changeset
69 void updateViewMatrix();
55
cb81ecb5fb23 grid stuff
Teemu Piippo <teemu@hecknology.net>
parents: 53
diff changeset
70 void updateModelMatrix();
86
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
71 Q_SLOT void build();
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
72 void renderVao(const gl::ArrayClass arrayClass);
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
73 void checkForGLErrors();
17
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
74 };

mercurial