1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4//
5// W A R N I N G
6// -------------
7//
8// This file is not part of the QtDataVisualization API. It exists purely as an
9// implementation detail. This header file may change from version to
10// version without notice, or even be removed.
11//
12// We mean it.
13
14#ifndef Q3DSCATTERRENDERER_P_H
15#define Q3DSCATTERRENDERER_P_H
16
17#include "datavisualizationglobal_p.h"
18#include "scatter3dcontroller_p.h"
19#include "abstract3drenderer_p.h"
20#include "scatterrenderitem_p.h"
21
22QT_FORWARD_DECLARE_CLASS(QSizeF)
23
24QT_BEGIN_NAMESPACE
25
26class ShaderHelper;
27class Q3DScene;
28class ScatterSeriesRenderCache;
29class QScatterDataItem;
30
31class Q_DATAVISUALIZATION_EXPORT Scatter3DRenderer : public Abstract3DRenderer
32{
33 Q_OBJECT
34
35private:
36 // Internal state
37 ScatterRenderItem *m_selectedItem; // points to renderitem array
38 bool m_updateLabels;
39 ShaderHelper *m_dotShader;
40 ShaderHelper *m_dotGradientShader;
41 ShaderHelper *m_staticSelectedItemGradientShader;
42 ShaderHelper *m_staticSelectedItemShader;
43 ShaderHelper *m_pointShader;
44 ShaderHelper *m_depthShader;
45 ShaderHelper *m_selectionShader;
46 ShaderHelper *m_backgroundShader;
47 ShaderHelper *m_staticGradientPointShader;
48 GLuint m_bgrTexture;
49 GLuint m_selectionTexture;
50 GLuint m_depthFrameBuffer;
51 GLuint m_selectionFrameBuffer;
52 GLuint m_selectionDepthBuffer;
53 GLfloat m_shadowQualityToShader;
54 GLint m_shadowQualityMultiplier;
55 float m_scaleX;
56 float m_scaleY;
57 float m_scaleZ;
58 int m_selectedItemIndex;
59 ScatterSeriesRenderCache *m_selectedSeriesCache;
60 ScatterSeriesRenderCache *m_oldSelectedSeriesCache;
61 GLfloat m_dotSizeScale;
62 ScatterRenderItem m_dummyRenderItem;
63 GLfloat m_maxItemSize;
64 int m_clickedIndex;
65 bool m_havePointSeries;
66 bool m_haveMeshSeries;
67 bool m_haveUniformColorMeshSeries;
68 bool m_haveGradientMeshSeries;
69
70public:
71 explicit Scatter3DRenderer(Scatter3DController *controller);
72 ~Scatter3DRenderer();
73
74 void updateData() override;
75 void updateSeries(const QList<QAbstract3DSeries *> &seriesList) override;
76 SeriesRenderCache *createNewCache(QAbstract3DSeries *series) override;
77 void updateItems(const QList<Scatter3DController::ChangeItem> &items);
78 void updateScene(Q3DScene *scene) override;
79 void updateAxisLabels(QAbstract3DAxis::AxisOrientation orientation,
80 const QStringList &labels) override;
81 void updateAxisTitleVisibility(QAbstract3DAxis::AxisOrientation orientation,
82 bool visible) override;
83 void updateOptimizationHint(QAbstract3DGraph::OptimizationHints hint) override;
84 void updateMargin(float margin) override;
85
86 QVector3D convertPositionToTranslation(const QVector3D &position, bool isAbsolute) override;
87
88 inline int clickedIndex() const { return m_clickedIndex; }
89 void resetClickedStatus();
90
91 void render(GLuint defaultFboHandle) override;
92
93public Q_SLOTS:
94 void updateSelectedItem(int index, QScatter3DSeries *series);
95
96protected:
97 void contextCleanup() override;
98 void initializeOpenGL() override;
99 void fixCameraTarget(QVector3D &target) override;
100 void getVisibleItemBounds(QVector3D &minBounds, QVector3D &maxBounds) override;
101
102private:
103 void initShaders(const QString &vertexShader, const QString &fragmentShader) override;
104 void initGradientShaders(const QString &vertexShader, const QString &fragmentShader) override;
105 void initStaticSelectedItemShaders(const QString &vertexShader,
106 const QString &fragmentShader,
107 const QString &gradientVertexShader,
108 const QString &gradientFragmentShader) override;
109 void updateShadowQuality(QAbstract3DGraph::ShadowQuality quality) override;
110 void updateTextures() override;
111 void fixMeshFileName(QString &fileName, QAbstract3DSeries::Mesh mesh) override;
112
113 void drawScene(GLuint defaultFboHandle);
114 void drawLabels(bool drawSelection, const Q3DCamera *activeCamera,
115 const QMatrix4x4 &viewMatrix, const QMatrix4x4 &projectionMatrix);
116
117 void loadBackgroundMesh();
118 void initSelectionShader();
119 void initBackgroundShaders(const QString &vertexShader, const QString &fragmentShader) override;
120 void initStaticPointShaders(const QString &vertexShader, const QString &fragmentShader);
121 void initSelectionBuffer() override;
122 void initDepthShader();
123 void updateDepthBuffer() override;
124 void initPointShader();
125 void calculateTranslation(ScatterRenderItem &item);
126 void calculateSceneScalingFactors();
127
128 void selectionColorToSeriesAndIndex(const QVector4D &color, int &index,
129 QAbstract3DSeries *&series);
130 inline void updateRenderItem(const QScatterDataItem &dataItem, ScatterRenderItem &renderItem);
131
132 Q_DISABLE_COPY(Scatter3DRenderer)
133};
134
135QT_END_NAMESPACE
136
137#endif
138

source code of qtdatavis3d/src/datavisualization/engine/scatter3drenderer_p.h