1
1
#include " waveform/renderers/allshader/waveformrendererpreroll.h"
2
2
3
3
#include < QDomNode>
4
- #include < QOpenGLTexture>
5
4
#include < QPainterPath>
6
5
#include < array>
7
6
7
+ #include " rendergraph/geometry.h"
8
+ #include " rendergraph/material/patternmaterial.h"
9
+ #include " rendergraph/vertexupdaters/texturedvertexupdater.h"
8
10
#include " skin/legacy/skincontext.h"
9
- #include " waveform/renderers/allshader/matrixforwidgetgeometry.h"
10
11
#include " waveform/renderers/waveformwidgetrenderer.h"
11
12
#include " widget/wskincolor.h"
12
13
@@ -20,7 +21,7 @@ QImage drawPrerollImage(float markerLength,
20
21
const float imageW = static_cast <float >(imagePixelW) / devicePixelRatio;
21
22
const float imageH = static_cast <float >(imagePixelH) / devicePixelRatio;
22
23
23
- QImage image (imagePixelW, imagePixelH, QImage::Format_ARGB32_Premultiplied );
24
+ QImage image (imagePixelW, imagePixelH, QImage::Format_RGBA8888_Premultiplied );
24
25
image.setDevicePixelRatio (devicePixelRatio);
25
26
26
27
const float penWidth = 1 .5f ;
@@ -47,7 +48,7 @@ QImage drawPrerollImage(float markerLength,
47
48
path.lineTo (p0);
48
49
path.closeSubpath ();
49
50
QColor fillColor = color;
50
- fillColor.setAlphaF (0 .5f );
51
+ fillColor.setAlphaF (0 .25f );
51
52
painter.fillPath (path, QBrush (fillColor));
52
53
53
54
painter.drawPath (path);
@@ -57,31 +58,52 @@ QImage drawPrerollImage(float markerLength,
57
58
}
58
59
} // anonymous namespace
59
60
61
+ using namespace rendergraph ;
62
+
60
63
namespace allshader {
61
64
62
65
WaveformRendererPreroll::WaveformRendererPreroll (
63
66
WaveformWidgetRenderer* waveformWidget,
64
67
::WaveformRendererAbstract::PositionSource type)
65
- : WaveformRenderer (waveformWidget),
68
+ : ::WaveformRendererAbstract (waveformWidget),
66
69
m_isSlipRenderer (type == ::WaveformRendererAbstract::Slip) {
70
+ setGeometry (std::make_unique<Geometry>(PatternMaterial::attributes (), 0 ));
71
+ setMaterial (std::make_unique<PatternMaterial>());
72
+ setUsePreprocess (true );
73
+ geometry ().setDrawingMode (Geometry::DrawingMode::Triangles);
67
74
}
68
75
69
76
WaveformRendererPreroll::~WaveformRendererPreroll () = default ;
70
77
71
78
void WaveformRendererPreroll::setup (
72
- const QDomNode& node, const SkinContext& context ) {
73
- m_color = QColor (context .selectString (node, " SignalColor" ));
79
+ const QDomNode& node, const SkinContext& skinContext ) {
80
+ m_color = QColor (skinContext .selectString (node, " SignalColor" ));
74
81
m_color = WSkinColor::getCorrectColor (m_color);
75
82
}
76
83
77
- void WaveformRendererPreroll::initializeGL () {
78
- m_shader.init ();
84
+ void WaveformRendererPreroll::draw (QPainter* painter, QPaintEvent* event) {
85
+ Q_UNUSED (painter);
86
+ Q_UNUSED (event);
87
+ DEBUG_ASSERT (false );
88
+ }
89
+
90
+ void WaveformRendererPreroll::preprocess () {
91
+ if (!preprocessInner ()) {
92
+ if (geometry ().vertexCount () != 0 ) {
93
+ geometry ().allocate (0 );
94
+ markDirtyGeometry ();
95
+ }
96
+ } else {
97
+ markDirtyMaterial ();
98
+ markDirtyGeometry ();
99
+ }
79
100
}
80
101
81
- void WaveformRendererPreroll::paintGL () {
82
- const TrackPointer track = m_waveformRenderer->getTrackInfo ();
83
- if (!track || (m_isSlipRenderer && !m_waveformRenderer->isSlipActive ())) {
84
- return ;
102
+ bool WaveformRendererPreroll::preprocessInner () {
103
+ const TrackPointer trackInfo = m_waveformRenderer->getTrackInfo ();
104
+
105
+ if (!trackInfo || (m_isSlipRenderer && !m_waveformRenderer->isSlipActive ())) {
106
+ return false ;
85
107
}
86
108
87
109
auto positionType = m_isSlipRenderer ? ::WaveformRendererAbstract::Slip
@@ -95,11 +117,15 @@ void WaveformRendererPreroll::paintGL() {
95
117
// to indicate the respective zones.
96
118
const bool preRollVisible = firstDisplayedPosition < 0 ;
97
119
const bool postRollVisible = lastDisplayedPosition > 1 ;
120
+ const int numVerticesPerRectangle = 6 ;
98
121
99
- if (!( preRollVisible || postRollVisible) ) {
100
- return ;
122
+ if (!preRollVisible && ! postRollVisible) {
123
+ return false ;
101
124
}
102
125
126
+ const int reserved = (preRollVisible ? numVerticesPerRectangle : 0 ) +
127
+ (postRollVisible ? numVerticesPerRectangle : 0 );
128
+
103
129
const double playMarkerPosition = m_waveformRenderer->getPlayMarkerPosition ();
104
130
const double vSamplesPerPixel = m_waveformRenderer->getVisualSamplePerPixel ();
105
131
const double numberOfVSamples = m_waveformRenderer->getLength () * vSamplesPerPixel;
@@ -125,36 +151,20 @@ void WaveformRendererPreroll::paintGL() {
125
151
// has changed size last time.
126
152
m_markerLength = markerLength;
127
153
m_markerBreadth = markerBreadth;
128
- m_texture.setData (drawPrerollImage (m_markerLength,
129
- m_markerBreadth,
130
- m_waveformRenderer->getDevicePixelRatio (),
131
- m_color));
154
+ dynamic_cast <PatternMaterial&>(material ())
155
+ .setTexture (std::make_unique<Texture>(m_waveformRenderer->getContext (),
156
+ drawPrerollImage (m_markerLength,
157
+ m_markerBreadth,
158
+ m_waveformRenderer->getDevicePixelRatio (),
159
+ m_color)));
132
160
}
133
161
134
- if (!m_texture.isStorageAllocated ()) {
135
- return ;
136
- }
137
-
138
- const int matrixLocation = m_shader.matrixLocation ();
139
- const int textureLocation = m_shader.textureLocation ();
140
- const int positionLocation = m_shader.positionLocation ();
141
- const int texcoordLocation = m_shader.texcoordLocation ();
142
-
143
- // Set up the shader
144
- m_shader.bind ();
145
-
146
- m_shader.enableAttributeArray (positionLocation);
147
- m_shader.enableAttributeArray (texcoordLocation);
148
-
149
- const QMatrix4x4 matrix = matrixForWidgetGeometry (m_waveformRenderer, false );
150
-
151
- m_shader.setUniformValue (matrixLocation, matrix);
152
- m_shader.setUniformValue (textureLocation, 0 );
153
-
154
- m_texture.bind ();
162
+ geometry ().allocate (reserved);
155
163
156
164
const float end = m_waveformRenderer->getLength ();
157
165
166
+ TexturedVertexUpdater vertexUpdater{geometry ().vertexDataAs <Geometry::TexturedPoint2D>()};
167
+
158
168
if (preRollVisible) {
159
169
// VSample position of the right-most triangle's tip
160
170
const double triangleTipVSamplePosition =
@@ -168,11 +178,14 @@ void WaveformRendererPreroll::paintGL() {
168
178
x -= std::ceil ((x - limit) / markerLength) * markerLength;
169
179
}
170
180
171
- drawPattern (x,
172
- halfBreadth - halfMarkerBreadth,
173
- 0 .f ,
174
- m_isSlipRenderer ? halfBreadth : halfBreadth + halfMarkerBreadth,
175
- x / markerLength);
181
+ const float repetitions = x / markerLength;
182
+
183
+ vertexUpdater.addRectangle ({x, halfBreadth - halfMarkerBreadth},
184
+ {0 ,
185
+ m_isSlipRenderer ? halfBreadth
186
+ : halfBreadth + halfMarkerBreadth},
187
+ {0 .f , 0 .f },
188
+ {repetitions, m_isSlipRenderer ? 0 .5f : 1 .f });
176
189
}
177
190
178
191
if (postRollVisible) {
@@ -189,44 +202,19 @@ void WaveformRendererPreroll::paintGL() {
189
202
x += std::ceil ((limit - x) / markerLength) * markerLength;
190
203
}
191
204
192
- drawPattern (x,
193
- halfBreadth - halfMarkerBreadth,
194
- end,
195
- m_isSlipRenderer ? halfBreadth : halfBreadth + halfMarkerBreadth,
196
- (end - x) / markerLength);
197
- }
205
+ const float repetitions = (end - x) / markerLength;
198
206
199
- m_texture.release ();
207
+ vertexUpdater.addRectangle ({x, halfBreadth - halfMarkerBreadth},
208
+ {end,
209
+ m_isSlipRenderer ? halfBreadth
210
+ : halfBreadth + halfMarkerBreadth},
211
+ {0 .f , 0 .f },
212
+ {repetitions, m_isSlipRenderer ? 0 .5f : 1 .f });
213
+ }
200
214
201
- m_shader.disableAttributeArray (positionLocation);
202
- m_shader.disableAttributeArray (texcoordLocation);
203
- m_shader.release ();
204
- }
215
+ DEBUG_ASSERT (reserved == vertexUpdater.index ());
205
216
206
- void WaveformRendererPreroll::drawPattern (
207
- float x1, float y1, float x2, float y2, float repetitions) {
208
- // Draw a large rectangle with a repeating pattern of the texture
209
- const int repetitionsLocation = m_shader.repetitionsLocation ();
210
- const int positionLocation = m_shader.positionLocation ();
211
- const int texcoordLocation = m_shader.texcoordLocation ();
212
-
213
- const std::array<float , 8 > positionArray = {x1, y1 , x2, y1 , x1, y2, x2, y2};
214
- const std::array<float , 8 > texcoordArray = {0 .f ,
215
- 0 .f ,
216
- 1 .f ,
217
- 0 .f ,
218
- 0 .f ,
219
- m_isSlipRenderer ? 0 .5f : 1 .f ,
220
- 1 .f ,
221
- m_isSlipRenderer ? 0 .5f : 1 .f };
222
- m_shader.setUniformValue (repetitionsLocation, QVector2D (repetitions, 1.0 ));
223
-
224
- m_shader.setAttributeArray (
225
- positionLocation, GL_FLOAT, positionArray.data (), 2 );
226
- m_shader.setAttributeArray (
227
- texcoordLocation, GL_FLOAT, texcoordArray.data (), 2 );
228
-
229
- glDrawArrays (GL_TRIANGLE_STRIP, 0 , 4 );
217
+ return true ;
230
218
}
231
219
232
220
} // namespace allshader
0 commit comments