| 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 Charts 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 | // W A R N I N G |
| 31 | // ------------- |
| 32 | // |
| 33 | // This file is not part of the Qt Chart API. It exists purely as an |
| 34 | // implementation detail. This header file may change from version to |
| 35 | // version without notice, or even be removed. |
| 36 | // |
| 37 | // We mean it. |
| 38 | |
| 39 | #ifndef DECLARATIVEOPENGLRENDERNODE_P_H |
| 40 | #define DECLARATIVEOPENGLRENDERNODE_P_H |
| 41 | |
| 42 | #include <private/declarativeabstractrendernode_p.h> |
| 43 | |
| 44 | #include <QtCharts/QChartGlobal> |
| 45 | #include <private/glxyseriesdata_p.h> |
| 46 | #include <QtQuick/QSGImageNode> |
| 47 | #include <QtQuick/QQuickWindow> |
| 48 | #include <QtGui/QOpenGLShaderProgram> |
| 49 | #include <QtGui/QOpenGLVertexArrayObject> |
| 50 | #include <QtGui/QOpenGLFunctions> |
| 51 | #include <QtGui/QOpenGLFramebufferObject> |
| 52 | #include <QtGui/QOpenGLBuffer> |
| 53 | |
| 54 | QT_CHARTS_BEGIN_NAMESPACE |
| 55 | |
| 56 | class DeclarativeOpenGLRenderNode : public QObject, public DeclarativeAbstractRenderNode, QOpenGLFunctions |
| 57 | { |
| 58 | Q_OBJECT |
| 59 | public: |
| 60 | DeclarativeOpenGLRenderNode(QQuickWindow *window); |
| 61 | ~DeclarativeOpenGLRenderNode(); |
| 62 | |
| 63 | void initGL(); |
| 64 | QSize textureSize() const override { return m_textureSize; } |
| 65 | void setTextureSize(const QSize &size) override; |
| 66 | |
| 67 | void setSeriesData(bool mapDirty, const GLXYDataMap &dataMap) override; |
| 68 | void setRect(const QRectF &rect) override; |
| 69 | void setAntialiasing(bool enable) override; |
| 70 | void addMouseEvents(const QVector<QMouseEvent *> &events) override; |
| 71 | void takeMouseEventResponses(QVector<MouseEventResponse> &responses) override; |
| 72 | |
| 73 | public Q_SLOTS: |
| 74 | void render(); |
| 75 | |
| 76 | private: |
| 77 | void renderGL(bool selection); |
| 78 | void renderSelection(); |
| 79 | void renderVisual(); |
| 80 | void recreateFBO(); |
| 81 | void cleanXYSeriesResources(const QXYSeries *series); |
| 82 | void handleMouseEvents(); |
| 83 | const QXYSeries *findSeriesAtEvent(QMouseEvent *event); |
| 84 | |
| 85 | QSGTexture *m_texture; |
| 86 | QSGImageNode *m_imageNode; |
| 87 | QQuickWindow *m_window; |
| 88 | QQuickWindow::CreateTextureOptions m_textureOptions; |
| 89 | QSize m_textureSize; |
| 90 | bool m_recreateFbo; |
| 91 | GLXYDataMap m_xyDataMap; |
| 92 | QOpenGLFramebufferObject *m_fbo; |
| 93 | QOpenGLFramebufferObject *m_resolvedFbo; |
| 94 | QOpenGLFramebufferObject *m_selectionFbo; |
| 95 | QOpenGLShaderProgram *m_program; |
| 96 | int m_shaderAttribLoc; |
| 97 | int m_colorUniformLoc; |
| 98 | int m_minUniformLoc; |
| 99 | int m_deltaUniformLoc; |
| 100 | int m_pointSizeUniformLoc; |
| 101 | int m_matrixUniformLoc; |
| 102 | QOpenGLVertexArrayObject m_vao; |
| 103 | QHash<const QAbstractSeries *, QOpenGLBuffer *> m_seriesBufferMap; |
| 104 | bool m_renderNeeded; |
| 105 | QRectF m_rect; |
| 106 | bool m_antialiasing; |
| 107 | QVector<QMouseEvent *> m_mouseEvents; |
| 108 | QVector<MouseEventResponse> m_mouseEventResponses; |
| 109 | bool m_selectionRenderNeeded; |
| 110 | QVector<const QXYSeries *> m_selectionVector; |
| 111 | QPoint m_mousePressPos; |
| 112 | bool m_mousePressed; |
| 113 | const QXYSeries *m_lastPressSeries; |
| 114 | const QXYSeries *m_lastHoverSeries; |
| 115 | }; |
| 116 | |
| 117 | QT_CHARTS_END_NAMESPACE |
| 118 | |
| 119 | #endif // DECLARATIVEOPENGLRENDERNODE_P_H |
| 120 |
