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