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 Q3DBARSRENDERER_P_H |
41 | #define Q3DBARSRENDERER_P_H |
42 | |
43 | #include "datavisualizationglobal_p.h" |
44 | #include "bars3dcontroller_p.h" |
45 | #include "abstract3drenderer_p.h" |
46 | #include "barrenderitem_p.h" |
47 | |
48 | QT_BEGIN_NAMESPACE |
49 | class QPoint; |
50 | class QSizeF; |
51 | QT_END_NAMESPACE |
52 | |
53 | QT_BEGIN_NAMESPACE_DATAVISUALIZATION |
54 | |
55 | class ShaderHelper; |
56 | class LabelItem; |
57 | class Q3DScene; |
58 | class BarSeriesRenderCache; |
59 | |
60 | class QT_DATAVISUALIZATION_EXPORT Bars3DRenderer : public Abstract3DRenderer |
61 | { |
62 | Q_OBJECT |
63 | |
64 | private: |
65 | // Cached state based on emitted signals from the controller |
66 | QSizeF m_cachedBarThickness; |
67 | QSizeF m_cachedBarSpacing; |
68 | bool m_cachedIsSlicingActivated; |
69 | int m_cachedRowCount; |
70 | int m_cachedColumnCount; |
71 | |
72 | // Internal state |
73 | BarRenderItem *m_selectedBar; // points to renderitem array |
74 | AxisRenderCache *m_sliceCache; // not owned |
75 | const LabelItem *m_sliceTitleItem; // not owned |
76 | bool m_updateLabels; |
77 | ShaderHelper *m_barShader; |
78 | ShaderHelper *m_barGradientShader; |
79 | ShaderHelper *m_depthShader; |
80 | ShaderHelper *m_selectionShader; |
81 | ShaderHelper *m_backgroundShader; |
82 | GLuint m_bgrTexture; |
83 | GLuint m_selectionTexture; |
84 | GLuint m_depthFrameBuffer; |
85 | GLuint m_selectionFrameBuffer; |
86 | GLuint m_selectionDepthBuffer; |
87 | GLfloat m_shadowQualityToShader; |
88 | GLint m_shadowQualityMultiplier; |
89 | GLfloat m_heightNormalizer; |
90 | GLfloat m_gradientFraction; |
91 | GLfloat m_backgroundAdjustment; |
92 | GLfloat m_rowWidth; |
93 | GLfloat m_columnDepth; |
94 | GLfloat m_maxDimension; |
95 | GLfloat m_scaleX; |
96 | GLfloat m_scaleZ; |
97 | GLfloat m_scaleFactor; |
98 | GLfloat m_maxSceneSize; |
99 | QPoint m_visualSelectedBarPos; |
100 | QPoint m_selectedBarPos; |
101 | BarSeriesRenderCache *m_selectedSeriesCache; |
102 | BarRenderItem m_dummyBarRenderItem; |
103 | bool m_noZeroInRange; |
104 | float m_seriesScaleX; |
105 | float m_seriesScaleZ; |
106 | float m_seriesStep; |
107 | float m_seriesStart; |
108 | QPoint m_clickedPosition; |
109 | bool m_keepSeriesUniform; |
110 | bool m_haveUniformColorSeries; |
111 | bool m_haveGradientSeries; |
112 | float m_zeroPosition; |
113 | float m_xScaleFactor; |
114 | float m_zScaleFactor; |
115 | float m_floorLevel; |
116 | float m_actualFloorLevel; |
117 | |
118 | public: |
119 | explicit Bars3DRenderer(Bars3DController *controller); |
120 | ~Bars3DRenderer(); |
121 | |
122 | void updateData(); |
123 | void updateSeries(const QList<QAbstract3DSeries *> &seriesList); |
124 | SeriesRenderCache *createNewCache(QAbstract3DSeries *series); |
125 | void updateRows(const QVector<Bars3DController::ChangeRow> &rows); |
126 | void updateItems(const QVector<Bars3DController::ChangeItem> &items); |
127 | void updateScene(Q3DScene *scene); |
128 | void render(GLuint defaultFboHandle = 0); |
129 | |
130 | QVector3D convertPositionToTranslation(const QVector3D &position, bool isAbsolute); |
131 | |
132 | void updateAspectRatio(float ratio); |
133 | void updateFloorLevel(float level); |
134 | void updateMargin(float margin); |
135 | |
136 | protected: |
137 | void contextCleanup(); |
138 | virtual void initializeOpenGL(); |
139 | virtual void fixCameraTarget(QVector3D &target); |
140 | virtual void getVisibleItemBounds(QVector3D &minBounds, QVector3D &maxBounds); |
141 | |
142 | public Q_SLOTS: |
143 | void updateMultiSeriesScaling(bool uniform); |
144 | void updateBarSpecs(GLfloat thicknessRatio = 1.0f, |
145 | const QSizeF &spacing = QSizeF(1.0, 1.0), |
146 | bool relative = true); |
147 | void updateSlicingActive(bool isSlicing); |
148 | void updateSelectedBar(const QPoint &position, QBar3DSeries *series); |
149 | inline QPoint clickedPosition() const { return m_clickedPosition; } |
150 | void resetClickedStatus(); |
151 | |
152 | // Overloaded from abstract renderer |
153 | virtual void updateAxisRange(QAbstract3DAxis::AxisOrientation orientation, float min, |
154 | float max); |
155 | virtual void updateAxisReversed(QAbstract3DAxis::AxisOrientation orientation, |
156 | bool enable); |
157 | |
158 | private: |
159 | virtual void initShaders(const QString &vertexShader, const QString &fragmentShader); |
160 | virtual void initGradientShaders(const QString &vertexShader, const QString &fragmentShader); |
161 | virtual void updateShadowQuality(QAbstract3DGraph::ShadowQuality quality); |
162 | virtual void updateTextures(); |
163 | virtual void fixMeshFileName(QString &fileName, QAbstract3DSeries::Mesh mesh); |
164 | |
165 | void drawSlicedScene(); |
166 | void drawScene(GLuint defaultFboHandle); |
167 | void drawLabels(bool drawSelection, const Q3DCamera *activeCamera, |
168 | const QMatrix4x4 &viewMatrix, const QMatrix4x4 &projectionMatrix); |
169 | |
170 | bool drawBars(BarRenderItem **selectedBar, const QMatrix4x4 &depthProjectionViewMatrix, |
171 | const QMatrix4x4 &projectionViewMatrix, const QMatrix4x4 &viewMatrix, |
172 | GLint startRow, GLint stopRow, GLint stepRow, |
173 | GLint startBar, GLint stopBar, GLint stepBar, GLfloat reflection = 1.0f); |
174 | void drawBackground(GLfloat backgroundRotation, const QMatrix4x4 &depthProjectionViewMatrix, |
175 | const QMatrix4x4 &projectionViewMatrix, const QMatrix4x4 &viewMatrix, |
176 | bool reflectingDraw = false, bool drawingSelectionBuffer = false); |
177 | void drawGridLines(const QMatrix4x4 &depthProjectionViewMatrix, |
178 | const QMatrix4x4 &projectionViewMatrix, |
179 | const QMatrix4x4 &viewMatrix); |
180 | |
181 | void loadBackgroundMesh(); |
182 | void initSelectionShader(); |
183 | void initBackgroundShaders(const QString &vertexShader, const QString &fragmentShader); |
184 | void initSelectionBuffer(); |
185 | void initDepthShader(); |
186 | void updateDepthBuffer(); |
187 | void calculateSceneScalingFactors(); |
188 | void calculateHeightAdjustment(); |
189 | Abstract3DController::SelectionType isSelected(int row, int bar, |
190 | const BarSeriesRenderCache *cache); |
191 | QPoint selectionColorToArrayPosition(const QVector4D &selectionColor); |
192 | QBar3DSeries *selectionColorToSeries(const QVector4D &selectionColor); |
193 | |
194 | inline void updateRenderRow(const QBarDataRow *dataRow, BarRenderItemRow &renderRow); |
195 | inline void updateRenderItem(const QBarDataItem &dataItem, BarRenderItem &renderItem); |
196 | |
197 | Q_DISABLE_COPY(Bars3DRenderer) |
198 | }; |
199 | |
200 | QT_END_NAMESPACE_DATAVISUALIZATION |
201 | |
202 | #endif |
203 | |