1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Data Visualization module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 or (at your option) any later version
20** approved by the KDE Free Qt Foundation. The licenses are as published by
21** the Free Software Foundation and appearing in the file LICENSE.GPL3
22** included in the packaging of this file. Please review the following
23** information to ensure the GNU General Public License requirements will
24** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25**
26** $QT_END_LICENSE$
27**
28****************************************************************************/
29
30//
31// W A R N I N G
32// -------------
33//
34// This file is not part of the QtDataVisualization API. It exists purely as an
35// implementation detail. This header file may change from version to
36// version without notice, or even be removed.
37//
38// We mean it.
39
40#ifndef Q3DSCATTERRENDERER_P_H
41#define Q3DSCATTERRENDERER_P_H
42
43#include "datavisualizationglobal_p.h"
44#include "scatter3dcontroller_p.h"
45#include "abstract3drenderer_p.h"
46#include "scatterrenderitem_p.h"
47
48QT_FORWARD_DECLARE_CLASS(QSizeF)
49
50QT_BEGIN_NAMESPACE_DATAVISUALIZATION
51
52class ShaderHelper;
53class Q3DScene;
54class ScatterSeriesRenderCache;
55class QScatterDataItem;
56
57class QT_DATAVISUALIZATION_EXPORT Scatter3DRenderer : public Abstract3DRenderer
58{
59 Q_OBJECT
60
61private:
62 // Internal state
63 ScatterRenderItem *m_selectedItem; // points to renderitem array
64 bool m_updateLabels;
65 ShaderHelper *m_dotShader;
66 ShaderHelper *m_dotGradientShader;
67 ShaderHelper *m_staticSelectedItemGradientShader;
68 ShaderHelper *m_staticSelectedItemShader;
69 ShaderHelper *m_pointShader;
70 ShaderHelper *m_depthShader;
71 ShaderHelper *m_selectionShader;
72 ShaderHelper *m_backgroundShader;
73 ShaderHelper *m_staticGradientPointShader;
74 GLuint m_bgrTexture;
75 GLuint m_selectionTexture;
76 GLuint m_depthFrameBuffer;
77 GLuint m_selectionFrameBuffer;
78 GLuint m_selectionDepthBuffer;
79 GLfloat m_shadowQualityToShader;
80 GLint m_shadowQualityMultiplier;
81 float m_scaleX;
82 float m_scaleY;
83 float m_scaleZ;
84 int m_selectedItemIndex;
85 ScatterSeriesRenderCache *m_selectedSeriesCache;
86 ScatterSeriesRenderCache *m_oldSelectedSeriesCache;
87 GLfloat m_dotSizeScale;
88 ScatterRenderItem m_dummyRenderItem;
89 GLfloat m_maxItemSize;
90 int m_clickedIndex;
91 bool m_havePointSeries;
92 bool m_haveMeshSeries;
93 bool m_haveUniformColorMeshSeries;
94 bool m_haveGradientMeshSeries;
95
96public:
97 explicit Scatter3DRenderer(Scatter3DController *controller);
98 ~Scatter3DRenderer();
99
100 void updateData();
101 void updateSeries(const QList<QAbstract3DSeries *> &seriesList);
102 SeriesRenderCache *createNewCache(QAbstract3DSeries *series);
103 void updateItems(const QVector<Scatter3DController::ChangeItem> &items);
104 void updateScene(Q3DScene *scene);
105 void updateAxisLabels(QAbstract3DAxis::AxisOrientation orientation,
106 const QStringList &labels);
107 void updateAxisTitleVisibility(QAbstract3DAxis::AxisOrientation orientation,
108 bool visible);
109 void updateOptimizationHint(QAbstract3DGraph::OptimizationHints hint);
110 void updateMargin(float margin);
111
112 QVector3D convertPositionToTranslation(const QVector3D &position, bool isAbsolute);
113
114 inline int clickedIndex() const { return m_clickedIndex; }
115 void resetClickedStatus();
116
117 void render(GLuint defaultFboHandle);
118
119public Q_SLOTS:
120 void updateSelectedItem(int index, QScatter3DSeries *series);
121
122protected:
123 void contextCleanup();
124 virtual void initializeOpenGL();
125 virtual void fixCameraTarget(QVector3D &target);
126 virtual void getVisibleItemBounds(QVector3D &minBounds, QVector3D &maxBounds);
127
128private:
129 virtual void initShaders(const QString &vertexShader, const QString &fragmentShader);
130 virtual void initGradientShaders(const QString &vertexShader, const QString &fragmentShader);
131 virtual void initStaticSelectedItemShaders(const QString &vertexShader,
132 const QString &fragmentShader,
133 const QString &gradientVertexShader,
134 const QString &gradientFragmentShader);
135 virtual void updateShadowQuality(QAbstract3DGraph::ShadowQuality quality);
136 virtual void updateTextures();
137 virtual void fixMeshFileName(QString &fileName, QAbstract3DSeries::Mesh mesh);
138
139 void drawScene(GLuint defaultFboHandle);
140 void drawLabels(bool drawSelection, const Q3DCamera *activeCamera,
141 const QMatrix4x4 &viewMatrix, const QMatrix4x4 &projectionMatrix);
142
143 void loadBackgroundMesh();
144 void initSelectionShader();
145 void initBackgroundShaders(const QString &vertexShader, const QString &fragmentShader);
146 void initStaticPointShaders(const QString &vertexShader, const QString &fragmentShader);
147 void initSelectionBuffer();
148 void initDepthShader();
149 void updateDepthBuffer();
150 void initPointShader();
151 void calculateTranslation(ScatterRenderItem &item);
152 void calculateSceneScalingFactors();
153
154 void selectionColorToSeriesAndIndex(const QVector4D &color, int &index,
155 QAbstract3DSeries *&series);
156 inline void updateRenderItem(const QScatterDataItem &dataItem, ScatterRenderItem &renderItem);
157
158 Q_DISABLE_COPY(Scatter3DRenderer)
159};
160
161QT_END_NAMESPACE_DATAVISUALIZATION
162
163#endif
164

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