src/gl/partrenderer.h

Mon, 20 Jun 2022 16:43:56 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Mon, 20 Jun 2022 16:43:56 +0300
changeset 233
5509bec02c81
parent 232
8efa3a33172e
child 237
10a6298f636f
permissions
-rw-r--r--

fix various things

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

mercurial