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