1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include "seriesrendercache_p.h" |
5 | #include "abstract3drenderer_p.h" |
6 | #include "texturehelper_p.h" |
7 | #include "utils_p.h" |
8 | |
9 | QT_BEGIN_NAMESPACE |
10 | |
11 | const QString smoothString(QStringLiteral("Smooth" )); |
12 | |
13 | SeriesRenderCache::SeriesRenderCache(QAbstract3DSeries *series, Abstract3DRenderer *renderer) |
14 | : m_series(series), |
15 | m_object(0), |
16 | m_mesh(QAbstract3DSeries::MeshCube), |
17 | m_baseUniformTexture(0), |
18 | m_baseGradientTexture(0), |
19 | m_gradientImage(0), |
20 | m_singleHighlightGradientTexture(0), |
21 | m_multiHighlightGradientTexture(0), |
22 | m_valid(false), |
23 | m_visible(false), |
24 | m_renderer(renderer), |
25 | m_objectDirty(true), |
26 | m_staticObjectUVDirty(false) |
27 | { |
28 | } |
29 | |
30 | SeriesRenderCache::~SeriesRenderCache() |
31 | { |
32 | } |
33 | |
34 | void SeriesRenderCache::populate(bool newSeries) |
35 | { |
36 | QAbstract3DSeriesChangeBitField &changeTracker = m_series->d_ptr->m_changeTracker; |
37 | |
38 | if (newSeries || changeTracker.meshChanged || changeTracker.meshSmoothChanged |
39 | || changeTracker.userDefinedMeshChanged) { |
40 | m_mesh = m_series->mesh(); |
41 | changeTracker.meshChanged = false; |
42 | changeTracker.meshSmoothChanged = false; |
43 | changeTracker.userDefinedMeshChanged = false; |
44 | |
45 | QString meshFileName; |
46 | |
47 | // Compose mesh filename |
48 | if (m_mesh == QAbstract3DSeries::MeshUserDefined) { |
49 | // Always use the supplied mesh directly |
50 | meshFileName = m_series->userDefinedMesh(); |
51 | } else { |
52 | switch (m_mesh) { |
53 | case QAbstract3DSeries::MeshBar: |
54 | case QAbstract3DSeries::MeshCube: |
55 | meshFileName = QStringLiteral(":/defaultMeshes/bar" ); |
56 | break; |
57 | case QAbstract3DSeries::MeshPyramid: |
58 | meshFileName = QStringLiteral(":/defaultMeshes/pyramid" ); |
59 | break; |
60 | case QAbstract3DSeries::MeshCone: |
61 | meshFileName = QStringLiteral(":/defaultMeshes/cone" ); |
62 | break; |
63 | case QAbstract3DSeries::MeshCylinder: |
64 | meshFileName = QStringLiteral(":/defaultMeshes/cylinder" ); |
65 | break; |
66 | case QAbstract3DSeries::MeshBevelBar: |
67 | case QAbstract3DSeries::MeshBevelCube: |
68 | meshFileName = QStringLiteral(":/defaultMeshes/bevelbar" ); |
69 | break; |
70 | case QAbstract3DSeries::MeshSphere: |
71 | meshFileName = QStringLiteral(":/defaultMeshes/sphere" ); |
72 | break; |
73 | case QAbstract3DSeries::MeshMinimal: |
74 | meshFileName = QStringLiteral(":/defaultMeshes/minimal" ); |
75 | break; |
76 | case QAbstract3DSeries::MeshArrow: |
77 | meshFileName = QStringLiteral(":/defaultMeshes/arrow" ); |
78 | break; |
79 | case QAbstract3DSeries::MeshPoint: |
80 | if (Utils::isOpenGLES()) |
81 | qWarning(msg: "QAbstract3DSeries::MeshPoint is not fully supported on OpenGL ES2" ); |
82 | break; |
83 | default: |
84 | // Default to cube |
85 | meshFileName = QStringLiteral(":/defaultMeshes/bar" ); |
86 | break; |
87 | } |
88 | |
89 | if (m_series->isMeshSmooth() && m_mesh != QAbstract3DSeries::MeshPoint) |
90 | meshFileName += smoothString; |
91 | |
92 | // Give renderer an opportunity to customize the mesh |
93 | m_renderer->fixMeshFileName(fileName&: meshFileName, mesh: m_mesh); |
94 | } |
95 | |
96 | ObjectHelper::resetObjectHelper(cacheId: m_renderer, obj&: m_object, meshFile: meshFileName); |
97 | } |
98 | |
99 | if (newSeries || changeTracker.meshRotationChanged) { |
100 | m_meshRotation = m_series->meshRotation().normalized(); |
101 | if (m_series->type() == QAbstract3DSeries::SeriesTypeBar |
102 | && (m_meshRotation.x() || m_meshRotation.z())) { |
103 | m_meshRotation = identityQuaternion; |
104 | } |
105 | changeTracker.meshRotationChanged = false; |
106 | } |
107 | |
108 | if (newSeries || changeTracker.colorStyleChanged) { |
109 | m_colorStyle = m_series->colorStyle(); |
110 | changeTracker.colorStyleChanged = false; |
111 | } |
112 | |
113 | if (newSeries || changeTracker.baseColorChanged) { |
114 | m_baseColor = Utils::vectorFromColor(color: m_series->baseColor()); |
115 | if (m_series->type() == QAbstract3DSeries::SeriesTypeSurface) |
116 | m_renderer->generateBaseColorTexture(color: m_series->baseColor(), texture: &m_baseUniformTexture); |
117 | changeTracker.baseColorChanged = false; |
118 | } |
119 | |
120 | if (newSeries || changeTracker.baseGradientChanged) { |
121 | QLinearGradient gradient = m_series->baseGradient(); |
122 | m_gradientImage = Utils::getGradientImage(gradient); |
123 | m_renderer->fixGradientAndGenerateTexture(gradient: &gradient, gradientTexture: &m_baseGradientTexture); |
124 | changeTracker.baseGradientChanged = false; |
125 | } |
126 | |
127 | if (newSeries || changeTracker.singleHighlightColorChanged) { |
128 | m_singleHighlightColor = Utils::vectorFromColor(color: m_series->singleHighlightColor()); |
129 | changeTracker.singleHighlightColorChanged = false; |
130 | } |
131 | |
132 | if (newSeries || changeTracker.singleHighlightGradientChanged) { |
133 | QLinearGradient gradient = m_series->singleHighlightGradient(); |
134 | m_renderer->fixGradientAndGenerateTexture(gradient: &gradient, gradientTexture: &m_singleHighlightGradientTexture); |
135 | changeTracker.singleHighlightGradientChanged = false; |
136 | } |
137 | |
138 | if (newSeries || changeTracker.multiHighlightColorChanged) { |
139 | m_multiHighlightColor = Utils::vectorFromColor(color: m_series->multiHighlightColor()); |
140 | changeTracker.multiHighlightColorChanged = false; |
141 | } |
142 | |
143 | if (newSeries || changeTracker.multiHighlightGradientChanged) { |
144 | QLinearGradient gradient = m_series->multiHighlightGradient(); |
145 | m_renderer->fixGradientAndGenerateTexture(gradient: &gradient, gradientTexture: &m_multiHighlightGradientTexture); |
146 | changeTracker.multiHighlightGradientChanged = false; |
147 | } |
148 | |
149 | if (newSeries || changeTracker.nameChanged) { |
150 | m_name = m_series->name(); |
151 | changeTracker.nameChanged = false; |
152 | } |
153 | |
154 | if (newSeries || changeTracker.itemLabelChanged |
155 | || changeTracker.itemLabelVisibilityChanged) { |
156 | changeTracker.itemLabelChanged = false; |
157 | changeTracker.itemLabelVisibilityChanged = false; |
158 | // series->itemLabel() call resolves the item label and emits the changed signal |
159 | // if it is dirty, so we need to call it even if m_itemLabel is eventually set |
160 | // to an empty string. |
161 | m_itemLabel = m_series->itemLabel(); |
162 | if (!m_series->isItemLabelVisible()) |
163 | m_itemLabel = QString(); |
164 | } |
165 | |
166 | if (newSeries || changeTracker.visibilityChanged) { |
167 | m_visible = m_series->isVisible(); |
168 | changeTracker.visibilityChanged = false; |
169 | } |
170 | } |
171 | |
172 | void SeriesRenderCache::cleanup(TextureHelper *texHelper) |
173 | { |
174 | ObjectHelper::releaseObjectHelper(cacheId: m_renderer, obj&: m_object); |
175 | if (QOpenGLContext::currentContext()) { |
176 | texHelper->deleteTexture(texture: &m_baseUniformTexture); |
177 | texHelper->deleteTexture(texture: &m_baseGradientTexture); |
178 | texHelper->deleteTexture(texture: &m_singleHighlightGradientTexture); |
179 | texHelper->deleteTexture(texture: &m_multiHighlightGradientTexture); |
180 | } |
181 | } |
182 | |
183 | QT_END_NAMESPACE |
184 | |