src/gl/partrenderer.h

Tue, 28 Jun 2022 19:57:45 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Tue, 28 Jun 2022 19:57:45 +0300
changeset 302
d59cb01d8031
parent 291
42b4953dff85
child 309
d862721d19a3
permissions
-rw-r--r--

Enable cotire again

17
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 #pragma once
264
76a025db4948 Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 237
diff changeset
2 #include "src/basics.h"
76a025db4948 Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 237
diff changeset
3 #include "src/documentmanager.h"
76a025db4948 Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 237
diff changeset
4 #include "src/types/boundingbox.h"
76a025db4948 Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 237
diff changeset
5 #include "src/gl/common.h"
76a025db4948 Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 237
diff changeset
6 #include "src/gl/compiler.h"
291
42b4953dff85 Let's bring GLEW back after all
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 264
diff changeset
7 #include <QOpenGLWidget>
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();
237
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
53 void message(const Message& message);
17
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
54 private:
217
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
55 void initializeGL() override;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
56 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
57 void paintGL() override;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
58 void mouseMoveEvent(QMouseEvent* event) override;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
59 void mousePressEvent(QMouseEvent* event) override;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
60 void mouseReleaseEvent(QMouseEvent* event) override;
232
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
61 void keyReleaseEvent(QKeyEvent* event) override;
217
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
62 void wheelEvent(QWheelEvent* event) override;
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
63 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
64 glm::vec3 unproject(const glm::vec3& win) const;
37
90443fb328ea wired renderstyle up
Teemu Piippo <teemu@hecknology.net>
parents: 36
diff changeset
65 void setFragmentStyle(gl::FragmentStyle fragStyle);
22
6da867fa5429 commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
66 void renderScene();
31
b6df269a2c6b fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents: 30
diff changeset
67 void updateViewMatrix();
55
cb81ecb5fb23 grid stuff
Teemu Piippo <teemu@hecknology.net>
parents: 53
diff changeset
68 void updateModelMatrix();
86
4bec0525ef1b PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
69 Q_SLOT void build();
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
70 void renderVao(const gl::ArrayClass arrayClass);
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
71 void checkForGLErrors();
17
a5111f4e6412 added teapot rendering
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
72 };

mercurial