src/gl/partrenderer.h

changeset 217
6d95c1a41e6e
parent 215
34c6e7bc4ee1
child 232
8efa3a33172e
equal deleted inserted replaced
216:c7241f504117 217:6d95c1a41e6e
4 #include "gl/common.h" 4 #include "gl/common.h"
5 #include "gl/compiler.h" 5 #include "gl/compiler.h"
6 #include "documentmanager.h" 6 #include "documentmanager.h"
7 #include "types/boundingbox.h" 7 #include "types/boundingbox.h"
8 8
9 class PartRenderer : public QOpenGLWidget 9 class PartRenderer final : public QOpenGLWidget
10 { 10 {
11 Q_OBJECT 11 Q_OBJECT
12 Model* const model;
13 DocumentManager* const documents;
14 const ColorTable& colorTable;
15 BoundingBox boundingBox;
16 gl::ModelShaders shaders;
17 ModelId highlighted = {0};
18 glm::mat4 projectionMatrix;
19 glm::mat4 viewMatrix;
20 glm::mat4 modelMatrix;
21 glm::vec4 viewportVector;
22 glm::quat modelQuaternion;
23 QPoint lastMousePosition;
24 int totalMouseMove = 0;
25 gl::RenderPreferences renderPreferences;
26 double zoom = 1.0;
27 bool initialized = false;
28 bool needBuild = true;
29 std::vector<RenderLayer*> activeRenderLayers;
30 std::vector<RenderLayer*> inactiveRenderLayers;
12 public: 31 public:
13 PartRenderer( 32 PartRenderer(
14 Model* model, 33 Model* model,
15 DocumentManager* documents, 34 DocumentManager* documents,
16 const ColorTable& colorTable, 35 const ColorTable& colorTable,
18 ~PartRenderer() override; 37 ~PartRenderer() override;
19 void setRenderPreferences(const gl::RenderPreferences& newPreferences); 38 void setRenderPreferences(const gl::RenderPreferences& newPreferences);
20 ModelId getHighlightedObject() const; 39 ModelId getHighlightedObject() const;
21 void addRenderLayer(RenderLayer* layer); 40 void addRenderLayer(RenderLayer* layer);
22 void setLayerEnabled(RenderLayer* layer, bool enabled); 41 void setLayerEnabled(RenderLayer* layer, bool enabled);
23 protected: 42 std::optional<glm::vec3> screenToModelCoordinates(const QPointF& point, const Plane& plane) const;
43 QPointF modelToScreenCoordinates(const glm::vec3& point) const;
44 bool isDark() const;
24 ModelId pick(QPoint where); 45 ModelId pick(QPoint where);
25 void initializeGL() override; 46 void setSelection(const QSet<ModelId>& selectedIds);
26 void resizeGL(int width, int height) override;
27 void paintGL() override;
28 void mouseMoveEvent(QMouseEvent* event) override;
29 void wheelEvent(QWheelEvent* event) override;
30 Model* const model;
31 DocumentManager* const documents;
32 const ColorTable& colorTable;
33 BoundingBox boundingBox;
34 gl::ModelShaders shaders;
35 ModelId highlighted = {0};
36 std::optional<glm::vec3> screenToModelCoordinates(const QPointF &point, const Plane& plane) const;
37 QPointF modelToScreenCoordinates(const glm::vec3& point) const;
38 Line<3> cameraLine(const QPointF& point) const;
39 glm::vec3 unproject(const glm::vec3& win) const;
40 glm::mat4 projectionMatrix;
41 glm::mat4 viewMatrix;
42 glm::mat4 modelMatrix;
43 glm::vec4 viewportVector;
44 glm::quat modelQuaternion;
45 QPoint lastMousePosition;
46 gl::RenderPreferences renderPreferences;
47 Q_SIGNALS: 47 Q_SIGNALS:
48 void projectionMatrixChanged(const glm::mat4& newMatrix); 48 void projectionMatrixChanged(const glm::mat4& newMatrix);
49 void modelMatrixChanged(const glm::mat4& newMatrix); 49 void modelMatrixChanged(const glm::mat4& newMatrix);
50 void viewMatrixChanged(const glm::mat4& newMatrix); 50 void viewMatrixChanged(const glm::mat4& newMatrix);
51 void renderPreferencesChanged(); 51 void renderPreferencesChanged();
52 private: 52 private:
53 void initializeGL() override;
54 void resizeGL(int width, int height) override;
55 void paintGL() override;
56 void mouseMoveEvent(QMouseEvent* event) override;
57 void mousePressEvent(QMouseEvent* event) override;
58 void mouseReleaseEvent(QMouseEvent* event) override;
59 void wheelEvent(QWheelEvent* event) override;
60 Line<3> cameraLine(const QPointF& point) const;
61 glm::vec3 unproject(const glm::vec3& win) const;
53 void setFragmentStyle(gl::FragmentStyle fragStyle); 62 void setFragmentStyle(gl::FragmentStyle fragStyle);
54 void renderScene(); 63 void renderScene();
55 void updateViewMatrix(); 64 void updateViewMatrix();
56 void updateModelMatrix(); 65 void updateModelMatrix();
57 Q_SLOT void build(); 66 Q_SLOT void build();
58 double zoom = 1.0;
59 bool initialized = false;
60 bool needBuild = true;
61 void renderVao(const gl::ArrayClass arrayClass); 67 void renderVao(const gl::ArrayClass arrayClass);
62 void checkForGLErrors(); 68 void checkForGLErrors();
63 std::vector<RenderLayer*> activeRenderLayers;
64 std::vector<RenderLayer*> inactiveRenderLayers;
65 }; 69 };

mercurial