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 SURFACE3DRENDERER_P_H
15#define SURFACE3DRENDERER_P_H
16
17#include "datavisualizationglobal_p.h"
18#include "surface3dcontroller_p.h"
19#include "abstract3drenderer_p.h"
20#include "surfaceseriesrendercache_p.h"
21
22QT_BEGIN_NAMESPACE
23
24class ShaderHelper;
25class Q3DScene;
26
27class Q_DATAVISUALIZATION_EXPORT Surface3DRenderer : public Abstract3DRenderer
28{
29 Q_OBJECT
30
31private:
32 bool m_cachedIsSlicingActivated;
33
34 // Internal attributes purely related to how the scene is drawn with GL.
35 ShaderHelper *m_depthShader;
36 ShaderHelper *m_backgroundShader;
37 ShaderHelper *m_surfaceFlatShader;
38 ShaderHelper *m_surfaceSmoothShader;
39 ShaderHelper *m_surfaceTexturedSmoothShader;
40 ShaderHelper *m_surfaceTexturedFlatShader;
41 ShaderHelper *m_surfaceGridShader;
42 ShaderHelper *m_surfaceSliceFlatShader;
43 ShaderHelper *m_surfaceSliceSmoothShader;
44 ShaderHelper *m_selectionShader;
45 float m_heightNormalizer;
46 float m_scaleX;
47 float m_scaleY;
48 float m_scaleZ;
49 GLuint m_depthFrameBuffer;
50 GLuint m_selectionFrameBuffer;
51 GLuint m_selectionDepthBuffer;
52 GLuint m_selectionResultTexture;
53 GLfloat m_shadowQualityToShader;
54 bool m_flatSupported;
55 bool m_selectionActive;
56 AbstractRenderItem m_dummyRenderItem;
57 GLint m_shadowQualityMultiplier;
58 QPoint m_selectedPoint;
59 QSurface3DSeries *m_selectedSeries;
60 QPoint m_clickedPosition;
61 bool m_selectionTexturesDirty;
62 GLuint m_noShadowTexture;
63 bool m_flipHorizontalGrid;
64
65public:
66 explicit Surface3DRenderer(Surface3DController *controller);
67 ~Surface3DRenderer();
68
69 void updateData() override;
70 void updateSeries(const QList<QAbstract3DSeries *> &seriesList) override;
71 void updateSurfaceTextures(QList<QSurface3DSeries *> seriesList);
72 SeriesRenderCache *createNewCache(QAbstract3DSeries *series) override;
73 void cleanCache(SeriesRenderCache *cache) override;
74 void updateSelectionMode(QAbstract3DGraph::SelectionFlags mode) override;
75 void updateRows(const QList<Surface3DController::ChangeRow> &rows);
76 void updateItems(const QList<Surface3DController::ChangeItem> &points);
77 void updateScene(Q3DScene *scene) override;
78 void updateSlicingActive(bool isSlicing);
79 void updateSelectedPoint(const QPoint &position, QSurface3DSeries *series);
80 void updateFlipHorizontalGrid(bool flip);
81 inline QPoint clickedPosition() const { return m_clickedPosition; }
82 void resetClickedStatus();
83 QVector3D convertPositionToTranslation(const QVector3D &position, bool isAbsolute) override;
84 void updateAxisLabels(QAbstract3DAxis::AxisOrientation orientation,
85 const QStringList &labels) override;
86 void updateAxisTitleVisibility(QAbstract3DAxis::AxisOrientation orientation,
87 bool visible) override;
88 void updateMargin(float margin) override;
89
90 void render(GLuint defaultFboHandle = 0) override;
91
92protected:
93 void contextCleanup() override;
94 void initializeOpenGL() override;
95 virtual void fixCameraTarget(QVector3D &target) override;
96 virtual void getVisibleItemBounds(QVector3D &minBounds, QVector3D &maxBounds) override;
97
98Q_SIGNALS:
99 void flatShadingSupportedChanged(bool supported);
100
101private:
102 void checkFlatSupport(SurfaceSeriesRenderCache *cache);
103 void updateObjects(SurfaceSeriesRenderCache *cache, bool dimensionChanged);
104 void updateSliceDataModel(const QPoint &point);
105 QPoint mapCoordsToSampleSpace(SurfaceSeriesRenderCache *cache, const QPointF &coords);
106 void findMatchingRow(float z, int &sample, int direction, QSurfaceDataArray &dataArray);
107 void findMatchingColumn(float x, int &sample, int direction, QSurfaceDataArray &dataArray);
108 void updateSliceObject(SurfaceSeriesRenderCache *cache, const QPoint &point);
109 void updateShadowQuality(QAbstract3DGraph::ShadowQuality quality) override;
110 void updateTextures() override;
111 void initShaders(const QString &vertexShader, const QString &fragmentShader) override;
112 QRect calculateSampleRect(const QSurfaceDataArray &array);
113 void loadBackgroundMesh();
114
115 void drawSlicedScene();
116 void drawScene(GLuint defaultFboHandle);
117 void drawLabels(bool drawSelection, const Q3DCamera *activeCamera,
118 const QMatrix4x4 &viewMatrix, const QMatrix4x4 &projectionMatrix);
119
120 void calculateSceneScalingFactors();
121 void initBackgroundShaders(const QString &vertexShader, const QString &fragmentShader) override;
122 void initSelectionShaders();
123 void initSurfaceShaders();
124 void initSelectionBuffer() override;
125 void initDepthShader();
126 void updateSelectionTextures();
127 void createSelectionTexture(SurfaceSeriesRenderCache *cache, uint &lastSelectionId);
128 void idToRGBA(uint id, uchar *r, uchar *g, uchar *b, uchar *a);
129 void fillIdCorner(uchar *p, uchar r, uchar g, uchar b, uchar a);
130 void surfacePointSelected(const QPoint &point);
131 void updateSelectionPoint(SurfaceSeriesRenderCache *cache, const QPoint &point, bool label);
132 QPoint selectionIdToSurfacePoint(uint id);
133 void updateDepthBuffer() override;
134 void emitSelectedPointChanged(QPoint position);
135
136 Q_DISABLE_COPY(Surface3DRenderer)
137
138 friend class SurfaceObject;
139};
140
141QT_END_NAMESPACE
142
143#endif
144

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