gl2paintengineex/qglengineshadermanager.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7 -
8 -
9 -
10 -
11class QGLEngineSharedShadersResource : public QOpenGLSharedResource -
12{ -
13public: -
14 QGLEngineSharedShadersResource(QOpenGLContext *ctx) -
15 : QOpenGLSharedResource(ctx->shareGroup()) -
16 , m_shaders(new QGLEngineSharedShaders(QGLContext::fromOpenGLContext(ctx))) -
17 { -
18 }
never executed: }
0
19 -
20 ~QGLEngineSharedShadersResource() -
21 { -
22 delete m_shaders; -
23 }
never executed: }
0
24 -
25 void invalidateResource() -
26 { -
27 delete m_shaders; -
28 m_shaders = 0; -
29 }
never executed: }
0
30 -
31 void freeResource(QOpenGLContext *) -
32 { -
33 } -
34 -
35 QGLEngineSharedShaders *shaders() const { return m_shaders; }
never executed: return m_shaders;
0
36 -
37private: -
38 QGLEngineSharedShaders *m_shaders; -
39}; -
40 -
41class QGLShaderStorage -
42{ -
43public: -
44 QGLEngineSharedShaders *shadersForThread(const QGLContext *context) { -
45 QOpenGLMultiGroupSharedResource *&shaders = m_storage.localData(); -
46 if (!shaders)
never evaluated: !shaders
0
47 shaders = new QOpenGLMultiGroupSharedResource;
never executed: shaders = new QOpenGLMultiGroupSharedResource;
0
48 QGLEngineSharedShadersResource *resource = -
49 shaders->value<QGLEngineSharedShadersResource>(context->contextHandle()); -
50 return resource ? resource->shaders() : 0;
never executed: return resource ? resource->shaders() : 0;
0
51 } -
52 -
53private: -
54 QThreadStorage<QOpenGLMultiGroupSharedResource *> m_storage; -
55}; -
56 -
57static QGLShaderStorage *qt_shader_storage() { static QGlobalStatic<QGLShaderStorage > thisGlobalStatic = { { (0) }, false }; if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { QGLShaderStorage *x = new QGLShaderStorage; if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) delete x; else static QGlobalStaticDeleter<QGLShaderStorage > cleanup(thisGlobalStatic); } return thisGlobalStatic.pointer.load(); };
never evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x)
never evaluated: !thisGlobalStatic.pointer.load()
never evaluated: !thisGlobalStatic.destroyed
never executed: delete x;
never executed: return thisGlobalStatic.pointer.load();
0
58 -
59QGLEngineSharedShaders *QGLEngineSharedShaders::shadersForContext(const QGLContext *context) -
60{ -
61 return qt_shader_storage()->shadersForThread(context);
never executed: return qt_shader_storage()->shadersForThread(context);
0
62} -
63 -
64const char* QGLEngineSharedShaders::qShaderSnippets[] = { -
65 0,0,0,0,0,0,0,0,0,0, -
66 0,0,0,0,0,0,0,0,0,0, -
67 0,0,0,0,0,0,0,0,0,0, -
68 0,0,0,0,0 -
69}; -
70 -
71QGLEngineSharedShaders::QGLEngineSharedShaders(const QGLContext* context) -
72 : blitShaderProg(0) -
73 , simpleShaderProg(0) -
74{ -
75 -
76 -
77 -
78 -
79 -
80 -
81 -
82 static bool snippetsPopulated = false; -
83 if (!snippetsPopulated) {
never evaluated: !snippetsPopulated
0
84 -
85 const char** code = qShaderSnippets; -
86 -
87 code[MainVertexShader] = qglslMainVertexShader; -
88 code[MainWithTexCoordsVertexShader] = qglslMainWithTexCoordsVertexShader; -
89 code[MainWithTexCoordsAndOpacityVertexShader] = qglslMainWithTexCoordsAndOpacityVertexShader; -
90 -
91 code[UntransformedPositionVertexShader] = qglslUntransformedPositionVertexShader; -
92 code[PositionOnlyVertexShader] = qglslPositionOnlyVertexShader; -
93 code[ComplexGeometryPositionOnlyVertexShader] = qglslComplexGeometryPositionOnlyVertexShader; -
94 code[PositionWithPatternBrushVertexShader] = qglslPositionWithPatternBrushVertexShader; -
95 code[PositionWithLinearGradientBrushVertexShader] = qglslPositionWithLinearGradientBrushVertexShader; -
96 code[PositionWithConicalGradientBrushVertexShader] = qglslPositionWithConicalGradientBrushVertexShader; -
97 code[PositionWithRadialGradientBrushVertexShader] = qglslPositionWithRadialGradientBrushVertexShader; -
98 code[PositionWithTextureBrushVertexShader] = qglslPositionWithTextureBrushVertexShader; -
99 code[AffinePositionWithPatternBrushVertexShader] = qglslAffinePositionWithPatternBrushVertexShader; -
100 code[AffinePositionWithLinearGradientBrushVertexShader] = qglslAffinePositionWithLinearGradientBrushVertexShader; -
101 code[AffinePositionWithConicalGradientBrushVertexShader] = qglslAffinePositionWithConicalGradientBrushVertexShader; -
102 code[AffinePositionWithRadialGradientBrushVertexShader] = qglslAffinePositionWithRadialGradientBrushVertexShader; -
103 code[AffinePositionWithTextureBrushVertexShader] = qglslAffinePositionWithTextureBrushVertexShader; -
104 -
105 code[MainFragmentShader_CMO] = qglslMainFragmentShader_CMO; -
106 code[MainFragmentShader_CM] = qglslMainFragmentShader_CM; -
107 code[MainFragmentShader_MO] = qglslMainFragmentShader_MO; -
108 code[MainFragmentShader_M] = qglslMainFragmentShader_M; -
109 code[MainFragmentShader_CO] = qglslMainFragmentShader_CO; -
110 code[MainFragmentShader_C] = qglslMainFragmentShader_C; -
111 code[MainFragmentShader_O] = qglslMainFragmentShader_O; -
112 code[MainFragmentShader] = qglslMainFragmentShader; -
113 code[MainFragmentShader_ImageArrays] = qglslMainFragmentShader_ImageArrays; -
114 -
115 code[ImageSrcFragmentShader] = qglslImageSrcFragmentShader; -
116 code[ImageSrcWithPatternFragmentShader] = qglslImageSrcWithPatternFragmentShader; -
117 code[NonPremultipliedImageSrcFragmentShader] = qglslNonPremultipliedImageSrcFragmentShader; -
118 code[CustomImageSrcFragmentShader] = qglslCustomSrcFragmentShader; -
119 code[SolidBrushSrcFragmentShader] = qglslSolidBrushSrcFragmentShader; -
120 code[TextureBrushSrcFragmentShader] = qglslTextureBrushSrcFragmentShader; -
121 code[TextureBrushSrcWithPatternFragmentShader] = qglslTextureBrushSrcWithPatternFragmentShader; -
122 code[PatternBrushSrcFragmentShader] = qglslPatternBrushSrcFragmentShader; -
123 code[LinearGradientBrushSrcFragmentShader] = qglslLinearGradientBrushSrcFragmentShader; -
124 code[RadialGradientBrushSrcFragmentShader] = qglslRadialGradientBrushSrcFragmentShader; -
125 code[ConicalGradientBrushSrcFragmentShader] = qglslConicalGradientBrushSrcFragmentShader; -
126 code[ShockingPinkSrcFragmentShader] = qglslShockingPinkSrcFragmentShader; -
127 -
128 code[NoMaskFragmentShader] = ""; -
129 code[MaskFragmentShader] = qglslMaskFragmentShader; -
130 code[RgbMaskFragmentShaderPass1] = qglslRgbMaskFragmentShaderPass1; -
131 code[RgbMaskFragmentShaderPass2] = qglslRgbMaskFragmentShaderPass2; -
132 code[RgbMaskWithGammaFragmentShader] = ""; -
133 -
134 code[NoCompositionModeFragmentShader] = ""; -
135 code[MultiplyCompositionModeFragmentShader] = ""; -
136 code[ScreenCompositionModeFragmentShader] = ""; -
137 code[OverlayCompositionModeFragmentShader] = ""; -
138 code[DarkenCompositionModeFragmentShader] = ""; -
139 code[LightenCompositionModeFragmentShader] = ""; -
140 code[ColorDodgeCompositionModeFragmentShader] = ""; -
141 code[ColorBurnCompositionModeFragmentShader] = ""; -
142 code[HardLightCompositionModeFragmentShader] = ""; -
143 code[SoftLightCompositionModeFragmentShader] = ""; -
144 code[DifferenceCompositionModeFragmentShader] = ""; -
145 code[ExclusionCompositionModeFragmentShader] = ""; -
146 snippetsPopulated = true; -
147 }
never executed: }
0
148 -
149 QGLShader* fragShader; -
150 QGLShader* vertexShader; -
151 QByteArray vertexSource; -
152 QByteArray fragSource; -
153 -
154 -
155 vertexSource.append(qShaderSnippets[MainVertexShader]); -
156 vertexSource.append(qShaderSnippets[PositionOnlyVertexShader]); -
157 -
158 fragSource.append(qShaderSnippets[MainFragmentShader]); -
159 fragSource.append(qShaderSnippets[ShockingPinkSrcFragmentShader]); -
160 -
161 simpleShaderProg = new QGLShaderProgram(context, 0); -
162 -
163 CachedShader simpleShaderCache(fragSource, vertexSource); -
164 -
165 bool inCache = simpleShaderCache.load(simpleShaderProg, context); -
166 -
167 if (!inCache) {
never evaluated: !inCache
0
168 vertexShader = new QGLShader(QGLShader::Vertex, context, 0); -
169 shaders.append(vertexShader); -
170 if (!vertexShader->compileSourceCode(vertexSource))
never evaluated: !vertexShader->compileSourceCode(vertexSource)
0
171 QMessageLogger("gl2paintengineex/qglengineshadermanager.cpp", 227, __PRETTY_FUNCTION__).warning("Vertex shader for simpleShaderProg (MainVertexShader & PositionOnlyVertexShader) failed to compile");
never executed: QMessageLogger("gl2paintengineex/qglengineshadermanager.cpp", 227, __PRETTY_FUNCTION__).warning("Vertex shader for simpleShaderProg (MainVertexShader & PositionOnlyVertexShader) failed to compile");
0
172 -
173 fragShader = new QGLShader(QGLShader::Fragment, context, 0); -
174 shaders.append(fragShader); -
175 if (!fragShader->compileSourceCode(fragSource))
never evaluated: !fragShader->compileSourceCode(fragSource)
0
176 QMessageLogger("gl2paintengineex/qglengineshadermanager.cpp", 232, __PRETTY_FUNCTION__).warning("Fragment shader for simpleShaderProg (MainFragmentShader & ShockingPinkSrcFragmentShader) failed to compile");
never executed: QMessageLogger("gl2paintengineex/qglengineshadermanager.cpp", 232, __PRETTY_FUNCTION__).warning("Fragment shader for simpleShaderProg (MainFragmentShader & ShockingPinkSrcFragmentShader) failed to compile");
0
177 -
178 simpleShaderProg->addShader(vertexShader); -
179 simpleShaderProg->addShader(fragShader); -
180 -
181 simpleShaderProg->bindAttributeLocation("vertexCoordsArray", QT_VERTEX_COORDS_ATTR); -
182 simpleShaderProg->bindAttributeLocation("pmvMatrix1", QT_PMV_MATRIX_1_ATTR); -
183 simpleShaderProg->bindAttributeLocation("pmvMatrix2", QT_PMV_MATRIX_2_ATTR); -
184 simpleShaderProg->bindAttributeLocation("pmvMatrix3", QT_PMV_MATRIX_3_ATTR); -
185 }
never executed: }
0
186 -
187 simpleShaderProg->link(); -
188 -
189 if (simpleShaderProg->isLinked()) {
never evaluated: simpleShaderProg->isLinked()
0
190 if (!inCache)
never evaluated: !inCache
0
191 simpleShaderCache.store(simpleShaderProg, context);
never executed: simpleShaderCache.store(simpleShaderProg, context);
0
192 } else {
never executed: }
0
193 QMessageLogger("gl2paintengineex/qglengineshadermanager.cpp", 249, __PRETTY_FUNCTION__).critical("Errors linking simple shader: %s", QString(simpleShaderProg->log()).toLocal8Bit().constData()); -
194 }
never executed: }
0
195 -
196 -
197 vertexSource.clear(); -
198 vertexSource.append(qShaderSnippets[MainWithTexCoordsVertexShader]); -
199 vertexSource.append(qShaderSnippets[UntransformedPositionVertexShader]); -
200 -
201 fragSource.clear(); -
202 fragSource.append(qShaderSnippets[MainFragmentShader]); -
203 fragSource.append(qShaderSnippets[ImageSrcFragmentShader]); -
204 -
205 blitShaderProg = new QGLShaderProgram(context, 0); -
206 -
207 CachedShader blitShaderCache(fragSource, vertexSource); -
208 -
209 inCache = blitShaderCache.load(blitShaderProg, context); -
210 -
211 if (!inCache) {
never evaluated: !inCache
0
212 vertexShader = new QGLShader(QGLShader::Vertex, context, 0); -
213 shaders.append(vertexShader); -
214 if (!vertexShader->compileSourceCode(vertexSource))
never evaluated: !vertexShader->compileSourceCode(vertexSource)
0
215 QMessageLogger("gl2paintengineex/qglengineshadermanager.cpp", 271, __PRETTY_FUNCTION__).warning("Vertex shader for blitShaderProg (MainWithTexCoordsVertexShader & UntransformedPositionVertexShader) failed to compile");
never executed: QMessageLogger("gl2paintengineex/qglengineshadermanager.cpp", 271, __PRETTY_FUNCTION__).warning("Vertex shader for blitShaderProg (MainWithTexCoordsVertexShader & UntransformedPositionVertexShader) failed to compile");
0
216 -
217 fragShader = new QGLShader(QGLShader::Fragment, context, 0); -
218 shaders.append(fragShader); -
219 if (!fragShader->compileSourceCode(fragSource))
never evaluated: !fragShader->compileSourceCode(fragSource)
0
220 QMessageLogger("gl2paintengineex/qglengineshadermanager.cpp", 276, __PRETTY_FUNCTION__).warning("Fragment shader for blitShaderProg (MainFragmentShader & ImageSrcFragmentShader) failed to compile");
never executed: QMessageLogger("gl2paintengineex/qglengineshadermanager.cpp", 276, __PRETTY_FUNCTION__).warning("Fragment shader for blitShaderProg (MainFragmentShader & ImageSrcFragmentShader) failed to compile");
0
221 -
222 blitShaderProg->addShader(vertexShader); -
223 blitShaderProg->addShader(fragShader); -
224 -
225 blitShaderProg->bindAttributeLocation("textureCoordArray", QT_TEXTURE_COORDS_ATTR); -
226 blitShaderProg->bindAttributeLocation("vertexCoordsArray", QT_VERTEX_COORDS_ATTR); -
227 }
never executed: }
0
228 -
229 blitShaderProg->link(); -
230 if (blitShaderProg->isLinked()) {
never evaluated: blitShaderProg->isLinked()
0
231 if (!inCache)
never evaluated: !inCache
0
232 blitShaderCache.store(blitShaderProg, context);
never executed: blitShaderCache.store(blitShaderProg, context);
0
233 } else {
never executed: }
0
234 QMessageLogger("gl2paintengineex/qglengineshadermanager.cpp", 290, __PRETTY_FUNCTION__).critical("Errors linking blit shader: %s", QString(blitShaderProg->log()).toLocal8Bit().constData()); -
235 }
never executed: }
0
236 -
237 -
238 -
239 -
240} -
241 -
242QGLEngineSharedShaders::~QGLEngineSharedShaders() -
243{ -
244 -
245 -
246 -
247 qDeleteAll(shaders); -
248 shaders.clear(); -
249 -
250 qDeleteAll(cachedPrograms); -
251 cachedPrograms.clear(); -
252 -
253 if (blitShaderProg) {
never evaluated: blitShaderProg
0
254 delete blitShaderProg; -
255 blitShaderProg = 0; -
256 }
never executed: }
0
257 -
258 if (simpleShaderProg) {
never evaluated: simpleShaderProg
0
259 delete simpleShaderProg; -
260 simpleShaderProg = 0; -
261 }
never executed: }
0
262}
never executed: }
0
263QGLEngineShaderProg *QGLEngineSharedShaders::findProgramInCache(const QGLEngineShaderProg &prog) -
264{ -
265 for (int i = 0; i < cachedPrograms.size(); ++i) {
never evaluated: i < cachedPrograms.size()
0
266 QGLEngineShaderProg *cachedProg = cachedPrograms[i]; -
267 if (*cachedProg == prog) {
never evaluated: *cachedProg == prog
0
268 -
269 cachedPrograms.move(i, 0); -
270 cachedProg->program->bind(); -
271 return cachedProg;
never executed: return cachedProg;
0
272 } -
273 }
never executed: }
0
274 -
275 QScopedPointer<QGLEngineShaderProg> newProg; -
276 -
277 do { -
278 QByteArray fragSource; -
279 -
280 -
281 if (prog.srcPixelFragShader == CustomImageSrcFragmentShader)
never evaluated: prog.srcPixelFragShader == CustomImageSrcFragmentShader
0
282 fragSource.append(prog.customStageSource);
never executed: fragSource.append(prog.customStageSource);
0
283 fragSource.append(qShaderSnippets[prog.mainFragShader]); -
284 fragSource.append(qShaderSnippets[prog.srcPixelFragShader]); -
285 if (prog.compositionFragShader)
never evaluated: prog.compositionFragShader
0
286 fragSource.append(qShaderSnippets[prog.compositionFragShader]);
never executed: fragSource.append(qShaderSnippets[prog.compositionFragShader]);
0
287 if (prog.maskFragShader)
never evaluated: prog.maskFragShader
0
288 fragSource.append(qShaderSnippets[prog.maskFragShader]);
never executed: fragSource.append(qShaderSnippets[prog.maskFragShader]);
0
289 -
290 QByteArray vertexSource; -
291 vertexSource.append(qShaderSnippets[prog.mainVertexShader]); -
292 vertexSource.append(qShaderSnippets[prog.positionVertexShader]); -
293 -
294 QScopedPointer<QGLShaderProgram> shaderProgram(new QGLShaderProgram); -
295 -
296 CachedShader shaderCache(fragSource, vertexSource); -
297 bool inCache = shaderCache.load(shaderProgram.data(), QGLContext::currentContext()); -
298 -
299 if (!inCache) {
never evaluated: !inCache
0
300 -
301 QScopedPointer<QGLShader> fragShader(new QGLShader(QGLShader::Fragment)); -
302 QByteArray description; -
303 if (!fragShader->compileSourceCode(fragSource)) {
never evaluated: !fragShader->compileSourceCode(fragSource)
0
304 QMessageLogger("gl2paintengineex/qglengineshadermanager.cpp", 387, __PRETTY_FUNCTION__).warning() << "Warning:" << description << "failed to compile!"; -
305 break;
never executed: break;
0
306 } -
307 -
308 QScopedPointer<QGLShader> vertexShader(new QGLShader(QGLShader::Vertex)); -
309 if (!vertexShader->compileSourceCode(vertexSource)) {
never evaluated: !vertexShader->compileSourceCode(vertexSource)
0
310 QMessageLogger("gl2paintengineex/qglengineshadermanager.cpp", 402, __PRETTY_FUNCTION__).warning() << "Warning:" << description << "failed to compile!"; -
311 break;
never executed: break;
0
312 } -
313 -
314 shaders.append(vertexShader.data()); -
315 shaders.append(fragShader.data()); -
316 shaderProgram->addShader(vertexShader.take()); -
317 shaderProgram->addShader(fragShader.take()); -
318 -
319 -
320 shaderProgram->bindAttributeLocation("vertexCoordsArray", QT_VERTEX_COORDS_ATTR); -
321 if (prog.useTextureCoords)
never evaluated: prog.useTextureCoords
0
322 shaderProgram->bindAttributeLocation("textureCoordArray", QT_TEXTURE_COORDS_ATTR);
never executed: shaderProgram->bindAttributeLocation("textureCoordArray", QT_TEXTURE_COORDS_ATTR);
0
323 if (prog.useOpacityAttribute)
never evaluated: prog.useOpacityAttribute
0
324 shaderProgram->bindAttributeLocation("opacityArray", QT_OPACITY_ATTR);
never executed: shaderProgram->bindAttributeLocation("opacityArray", QT_OPACITY_ATTR);
0
325 if (prog.usePmvMatrixAttribute) {
never evaluated: prog.usePmvMatrixAttribute
0
326 shaderProgram->bindAttributeLocation("pmvMatrix1", QT_PMV_MATRIX_1_ATTR); -
327 shaderProgram->bindAttributeLocation("pmvMatrix2", QT_PMV_MATRIX_2_ATTR); -
328 shaderProgram->bindAttributeLocation("pmvMatrix3", QT_PMV_MATRIX_3_ATTR); -
329 }
never executed: }
0
330 }
never executed: }
0
331 -
332 newProg.reset(new QGLEngineShaderProg(prog)); -
333 newProg->program = shaderProgram.take(); -
334 -
335 newProg->program->link(); -
336 if (newProg->program->isLinked()) {
never evaluated: newProg->program->isLinked()
0
337 if (!inCache)
never evaluated: !inCache
0
338 shaderCache.store(newProg->program, QGLContext::currentContext());
never executed: shaderCache.store(newProg->program, QGLContext::currentContext());
0
339 } else {
never executed: }
0
340 QLatin1String none("none"); -
341 QLatin1String br("\n"); -
342 QString error; -
343 error = QLatin1String("Shader program failed to link,"); -
344 error += QLatin1String(" Error Log:\n") -
345 + QLatin1String(" ") + newProg->program->log(); -
346 QMessageLogger("gl2paintengineex/qglengineshadermanager.cpp", 446, __PRETTY_FUNCTION__).warning() << error; -
347 break;
never executed: break;
0
348 } -
349 -
350 newProg->program->bind(); -
351 -
352 if (newProg->maskFragShader != QGLEngineSharedShaders::NoMaskFragmentShader) {
never evaluated: newProg->maskFragShader != QGLEngineSharedShaders::NoMaskFragmentShader
0
353 GLuint location = newProg->program->uniformLocation("maskTexture"); -
354 newProg->program->setUniformValue(location, GLuint(1)); -
355 }
never executed: }
0
356 -
357 if (cachedPrograms.count() > 30) {
never evaluated: cachedPrograms.count() > 30
0
358 -
359 -
360 -
361 for (int i = 0; i < 5; ++i) {
never evaluated: i < 5
0
362 delete cachedPrograms.last(); -
363 cachedPrograms.removeLast(); -
364 }
never executed: }
0
365 }
never executed: }
0
366 -
367 cachedPrograms.insert(0, newProg.data()); -
368 } while (false);
never evaluated: false
never executed: }
0
369 -
370 return newProg.take();
never executed: return newProg.take();
0
371} -
372 -
373void QGLEngineSharedShaders::cleanupCustomStage(QGLCustomShaderStage* stage) -
374{ -
375 -
376 for (int i = 0; i < cachedPrograms.size(); ++i) {
never evaluated: i < cachedPrograms.size()
0
377 QGLEngineShaderProg *cachedProg = cachedPrograms[i]; -
378 if (cachedProg->customStageSource == stage->source()) {
never evaluated: cachedProg->customStageSource == stage->source()
0
379 delete cachedProg; -
380 cachedPrograms.removeAt(i); -
381 i--; -
382 }
never executed: }
0
383 }
never executed: }
0
384}
never executed: }
0
385 -
386 -
387QGLEngineShaderManager::QGLEngineShaderManager(QGLContext* context) -
388 : ctx(context), -
389 shaderProgNeedsChanging(true), -
390 complexGeometry(false), -
391 srcPixelType(Qt::NoBrush), -
392 opacityMode(NoOpacity), -
393 maskType(NoMask), -
394 compositionMode(QPainter::CompositionMode_SourceOver), -
395 customSrcStage(0), -
396 currentShaderProg(0) -
397{ -
398 sharedShaders = QGLEngineSharedShaders::shadersForContext(context); -
399}
never executed: }
0
400 -
401QGLEngineShaderManager::~QGLEngineShaderManager() -
402{ -
403 -
404 removeCustomStage(); -
405}
never executed: }
0
406 -
407GLuint QGLEngineShaderManager::getUniformLocation(Uniform id) -
408{ -
409 if (!currentShaderProg)
never evaluated: !currentShaderProg
0
410 return 0;
never executed: return 0;
0
411 -
412 QVector<uint> &uniformLocations = currentShaderProg->uniformLocations; -
413 if (uniformLocations.isEmpty())
never evaluated: uniformLocations.isEmpty()
0
414 uniformLocations.fill(GLuint(-1), NumUniforms);
never executed: uniformLocations.fill(GLuint(-1), NumUniforms);
0
415 -
416 static const char *uniformNames[] = { -
417 "imageTexture", -
418 "patternColor", -
419 "globalOpacity", -
420 "depth", -
421 "maskTexture", -
422 "fragmentColor", -
423 "linearData", -
424 "angle", -
425 "halfViewportSize", -
426 "fmp", -
427 "fmp2_m_radius2", -
428 "inverse_2_fmp2_m_radius2", -
429 "sqrfr", -
430 "bradius", -
431 "invertedTextureSize", -
432 "brushTransform", -
433 "brushTexture", -
434 "matrix" -
435 }; -
436 -
437 if (uniformLocations.at(id) == GLuint(-1))
never evaluated: uniformLocations.at(id) == GLuint(-1)
0
438 uniformLocations[id] = currentShaderProg->program->uniformLocation(uniformNames[id]);
never executed: uniformLocations[id] = currentShaderProg->program->uniformLocation(uniformNames[id]);
0
439 -
440 return uniformLocations.at(id);
never executed: return uniformLocations.at(id);
0
441} -
442 -
443 -
444void QGLEngineShaderManager::optimiseForBrushTransform(QTransform::TransformationType transformType) -
445{ -
446 (void)transformType;; -
447}
never executed: }
0
448 -
449void QGLEngineShaderManager::setDirty() -
450{ -
451 shaderProgNeedsChanging = true; -
452}
never executed: }
0
453 -
454void QGLEngineShaderManager::setSrcPixelType(Qt::BrushStyle style) -
455{ -
456 qt_noop(); -
457 if (srcPixelType == PixelSrcType(style))
never evaluated: srcPixelType == PixelSrcType(style)
0
458 return;
never executed: return;
0
459 -
460 srcPixelType = style; -
461 shaderProgNeedsChanging = true; -
462}
never executed: }
0
463 -
464void QGLEngineShaderManager::setSrcPixelType(PixelSrcType type) -
465{ -
466 if (srcPixelType == type)
never evaluated: srcPixelType == type
0
467 return;
never executed: return;
0
468 -
469 srcPixelType = type; -
470 shaderProgNeedsChanging = true; -
471}
never executed: }
0
472 -
473void QGLEngineShaderManager::setOpacityMode(OpacityMode mode) -
474{ -
475 if (opacityMode == mode)
never evaluated: opacityMode == mode
0
476 return;
never executed: return;
0
477 -
478 opacityMode = mode; -
479 shaderProgNeedsChanging = true; -
480}
never executed: }
0
481 -
482void QGLEngineShaderManager::setMaskType(MaskType type) -
483{ -
484 if (maskType == type)
never evaluated: maskType == type
0
485 return;
never executed: return;
0
486 -
487 maskType = type; -
488 shaderProgNeedsChanging = true; -
489}
never executed: }
0
490 -
491void QGLEngineShaderManager::setCompositionMode(QPainter::CompositionMode mode) -
492{ -
493 if (compositionMode == mode)
never evaluated: compositionMode == mode
0
494 return;
never executed: return;
0
495 -
496 compositionMode = mode; -
497 shaderProgNeedsChanging = true; -
498}
never executed: }
0
499 -
500void QGLEngineShaderManager::setCustomStage(QGLCustomShaderStage* stage) -
501{ -
502 if (customSrcStage)
never evaluated: customSrcStage
0
503 removeCustomStage();
never executed: removeCustomStage();
0
504 customSrcStage = stage; -
505 shaderProgNeedsChanging = true; -
506}
never executed: }
0
507 -
508void QGLEngineShaderManager::removeCustomStage() -
509{ -
510 if (customSrcStage)
never evaluated: customSrcStage
0
511 customSrcStage->setInactive();
never executed: customSrcStage->setInactive();
0
512 customSrcStage = 0; -
513 shaderProgNeedsChanging = true; -
514}
never executed: }
0
515 -
516QGLShaderProgram* QGLEngineShaderManager::currentProgram() -
517{ -
518 if (currentShaderProg)
never evaluated: currentShaderProg
0
519 return currentShaderProg->program;
never executed: return currentShaderProg->program;
0
520 else -
521 return sharedShaders->simpleProgram();
never executed: return sharedShaders->simpleProgram();
0
522} -
523 -
524void QGLEngineShaderManager::useSimpleProgram() -
525{ -
526 sharedShaders->simpleProgram()->bind(); -
527 QGLContextPrivate* ctx_d = ctx->d_func(); -
528 ctx_d->setVertexAttribArrayEnabled(QT_VERTEX_COORDS_ATTR, true); -
529 ctx_d->setVertexAttribArrayEnabled(QT_TEXTURE_COORDS_ATTR, false); -
530 ctx_d->setVertexAttribArrayEnabled(QT_OPACITY_ATTR, false); -
531 shaderProgNeedsChanging = true; -
532}
never executed: }
0
533 -
534void QGLEngineShaderManager::useBlitProgram() -
535{ -
536 sharedShaders->blitProgram()->bind(); -
537 QGLContextPrivate* ctx_d = ctx->d_func(); -
538 ctx_d->setVertexAttribArrayEnabled(QT_VERTEX_COORDS_ATTR, true); -
539 ctx_d->setVertexAttribArrayEnabled(QT_TEXTURE_COORDS_ATTR, true); -
540 ctx_d->setVertexAttribArrayEnabled(QT_OPACITY_ATTR, false); -
541 shaderProgNeedsChanging = true; -
542}
never executed: }
0
543 -
544QGLShaderProgram* QGLEngineShaderManager::simpleProgram() -
545{ -
546 return sharedShaders->simpleProgram();
never executed: return sharedShaders->simpleProgram();
0
547} -
548 -
549QGLShaderProgram* QGLEngineShaderManager::blitProgram() -
550{ -
551 return sharedShaders->blitProgram();
never executed: return sharedShaders->blitProgram();
0
552} -
553 -
554 -
555 -
556 -
557 -
558bool QGLEngineShaderManager::useCorrectShaderProg() -
559{ -
560 if (!shaderProgNeedsChanging)
never evaluated: !shaderProgNeedsChanging
0
561 return false;
never executed: return false;
0
562 -
563 bool useCustomSrc = customSrcStage != 0; -
564 if (useCustomSrc && srcPixelType != QGLEngineShaderManager::ImageSrc && srcPixelType != Qt::TexturePattern) {
never evaluated: useCustomSrc
never evaluated: srcPixelType != QGLEngineShaderManager::ImageSrc
never evaluated: srcPixelType != Qt::TexturePattern
0
565 useCustomSrc = false; -
566 QMessageLogger("gl2paintengineex/qglengineshadermanager.cpp", 666, __PRETTY_FUNCTION__).warning("QGLEngineShaderManager - Ignoring custom shader stage for non image src"); -
567 }
never executed: }
0
568 -
569 QGLEngineShaderProg requiredProgram; -
570 -
571 bool texCoords = false; -
572 -
573 -
574 -
575 requiredProgram.positionVertexShader = QGLEngineSharedShaders::InvalidSnippetName; -
576 requiredProgram.srcPixelFragShader = QGLEngineSharedShaders::InvalidSnippetName; -
577 bool isAffine = brushTransform.isAffine(); -
578 if ( (srcPixelType >= Qt::Dense1Pattern) && (srcPixelType <= Qt::DiagCrossPattern) ) {
never evaluated: (srcPixelType >= Qt::Dense1Pattern)
never evaluated: (srcPixelType <= Qt::DiagCrossPattern)
0
579 if (isAffine)
never evaluated: isAffine
0
580 requiredProgram.positionVertexShader = QGLEngineSharedShaders::AffinePositionWithPatternBrushVertexShader;
never executed: requiredProgram.positionVertexShader = QGLEngineSharedShaders::AffinePositionWithPatternBrushVertexShader;
0
581 else -
582 requiredProgram.positionVertexShader = QGLEngineSharedShaders::PositionWithPatternBrushVertexShader;
never executed: requiredProgram.positionVertexShader = QGLEngineSharedShaders::PositionWithPatternBrushVertexShader;
0
583 -
584 requiredProgram.srcPixelFragShader = QGLEngineSharedShaders::PatternBrushSrcFragmentShader; -
585 }
never executed: }
0
586 else switch (srcPixelType) { -
587 default: -
588 case Qt::NoBrush: -
589 QMessageLogger("gl2paintengineex/qglengineshadermanager.cpp", 689, __PRETTY_FUNCTION__).fatal("QGLEngineShaderManager::useCorrectShaderProg() - Qt::NoBrush style is set"); -
590 break;
never executed: break;
0
591 case QGLEngineShaderManager::ImageSrc: -
592 requiredProgram.srcPixelFragShader = QGLEngineSharedShaders::ImageSrcFragmentShader; -
593 requiredProgram.positionVertexShader = QGLEngineSharedShaders::PositionOnlyVertexShader; -
594 texCoords = true; -
595 break;
never executed: break;
0
596 case QGLEngineShaderManager::NonPremultipliedImageSrc: -
597 requiredProgram.srcPixelFragShader = QGLEngineSharedShaders::NonPremultipliedImageSrcFragmentShader; -
598 requiredProgram.positionVertexShader = QGLEngineSharedShaders::PositionOnlyVertexShader; -
599 texCoords = true; -
600 break;
never executed: break;
0
601 case QGLEngineShaderManager::PatternSrc: -
602 requiredProgram.srcPixelFragShader = QGLEngineSharedShaders::ImageSrcWithPatternFragmentShader; -
603 requiredProgram.positionVertexShader = QGLEngineSharedShaders::PositionOnlyVertexShader; -
604 texCoords = true; -
605 break;
never executed: break;
0
606 case QGLEngineShaderManager::TextureSrcWithPattern: -
607 requiredProgram.srcPixelFragShader = QGLEngineSharedShaders::TextureBrushSrcWithPatternFragmentShader; -
608 requiredProgram.positionVertexShader = isAffine ? QGLEngineSharedShaders::AffinePositionWithTextureBrushVertexShader
never evaluated: isAffine
0
609 : QGLEngineSharedShaders::PositionWithTextureBrushVertexShader; -
610 break;
never executed: break;
0
611 case Qt::SolidPattern: -
612 requiredProgram.srcPixelFragShader = QGLEngineSharedShaders::SolidBrushSrcFragmentShader; -
613 requiredProgram.positionVertexShader = QGLEngineSharedShaders::PositionOnlyVertexShader; -
614 break;
never executed: break;
0
615 case Qt::LinearGradientPattern: -
616 requiredProgram.srcPixelFragShader = QGLEngineSharedShaders::LinearGradientBrushSrcFragmentShader; -
617 requiredProgram.positionVertexShader = isAffine ? QGLEngineSharedShaders::AffinePositionWithLinearGradientBrushVertexShader
never evaluated: isAffine
0
618 : QGLEngineSharedShaders::PositionWithLinearGradientBrushVertexShader; -
619 break;
never executed: break;
0
620 case Qt::ConicalGradientPattern: -
621 requiredProgram.srcPixelFragShader = QGLEngineSharedShaders::ConicalGradientBrushSrcFragmentShader; -
622 requiredProgram.positionVertexShader = isAffine ? QGLEngineSharedShaders::AffinePositionWithConicalGradientBrushVertexShader
never evaluated: isAffine
0
623 : QGLEngineSharedShaders::PositionWithConicalGradientBrushVertexShader; -
624 break;
never executed: break;
0
625 case Qt::RadialGradientPattern: -
626 requiredProgram.srcPixelFragShader = QGLEngineSharedShaders::RadialGradientBrushSrcFragmentShader; -
627 requiredProgram.positionVertexShader = isAffine ? QGLEngineSharedShaders::AffinePositionWithRadialGradientBrushVertexShader
never evaluated: isAffine
0
628 : QGLEngineSharedShaders::PositionWithRadialGradientBrushVertexShader; -
629 break;
never executed: break;
0
630 case Qt::TexturePattern: -
631 requiredProgram.srcPixelFragShader = QGLEngineSharedShaders::TextureBrushSrcFragmentShader; -
632 requiredProgram.positionVertexShader = isAffine ? QGLEngineSharedShaders::AffinePositionWithTextureBrushVertexShader
never evaluated: isAffine
0
633 : QGLEngineSharedShaders::PositionWithTextureBrushVertexShader; -
634 break;
never executed: break;
0
635 };
never executed: }
0
636 -
637 if (useCustomSrc) {
never evaluated: useCustomSrc
0
638 requiredProgram.srcPixelFragShader = QGLEngineSharedShaders::CustomImageSrcFragmentShader; -
639 requiredProgram.customStageSource = customSrcStage->source(); -
640 }
never executed: }
0
641 -
642 const bool hasCompose = compositionMode > QPainter::CompositionMode_Plus; -
643 const bool hasMask = maskType != QGLEngineShaderManager::NoMask; -
644 -
645 -
646 if (opacityMode == AttributeOpacity) {
never evaluated: opacityMode == AttributeOpacity
0
647 qt_noop(); -
648 requiredProgram.mainFragShader = QGLEngineSharedShaders::MainFragmentShader_ImageArrays; -
649 } else {
never executed: }
0
650 bool useGlobalOpacity = (opacityMode == UniformOpacity); -
651 if (hasCompose && hasMask && useGlobalOpacity)
never evaluated: hasCompose
never evaluated: hasMask
never evaluated: useGlobalOpacity
0
652 requiredProgram.mainFragShader = QGLEngineSharedShaders::MainFragmentShader_CMO;
never executed: requiredProgram.mainFragShader = QGLEngineSharedShaders::MainFragmentShader_CMO;
0
653 if (hasCompose && hasMask && !useGlobalOpacity)
never evaluated: hasCompose
never evaluated: hasMask
never evaluated: !useGlobalOpacity
0
654 requiredProgram.mainFragShader = QGLEngineSharedShaders::MainFragmentShader_CM;
never executed: requiredProgram.mainFragShader = QGLEngineSharedShaders::MainFragmentShader_CM;
0
655 if (!hasCompose && hasMask && useGlobalOpacity)
never evaluated: !hasCompose
never evaluated: hasMask
never evaluated: useGlobalOpacity
0
656 requiredProgram.mainFragShader = QGLEngineSharedShaders::MainFragmentShader_MO;
never executed: requiredProgram.mainFragShader = QGLEngineSharedShaders::MainFragmentShader_MO;
0
657 if (!hasCompose && hasMask && !useGlobalOpacity)
never evaluated: !hasCompose
never evaluated: hasMask
never evaluated: !useGlobalOpacity
0
658 requiredProgram.mainFragShader = QGLEngineSharedShaders::MainFragmentShader_M;
never executed: requiredProgram.mainFragShader = QGLEngineSharedShaders::MainFragmentShader_M;
0
659 if (hasCompose && !hasMask && useGlobalOpacity)
never evaluated: hasCompose
never evaluated: !hasMask
never evaluated: useGlobalOpacity
0
660 requiredProgram.mainFragShader = QGLEngineSharedShaders::MainFragmentShader_CO;
never executed: requiredProgram.mainFragShader = QGLEngineSharedShaders::MainFragmentShader_CO;
0
661 if (hasCompose && !hasMask && !useGlobalOpacity)
never evaluated: hasCompose
never evaluated: !hasMask
never evaluated: !useGlobalOpacity
0
662 requiredProgram.mainFragShader = QGLEngineSharedShaders::MainFragmentShader_C;
never executed: requiredProgram.mainFragShader = QGLEngineSharedShaders::MainFragmentShader_C;
0
663 if (!hasCompose && !hasMask && useGlobalOpacity)
never evaluated: !hasCompose
never evaluated: !hasMask
never evaluated: useGlobalOpacity
0
664 requiredProgram.mainFragShader = QGLEngineSharedShaders::MainFragmentShader_O;
never executed: requiredProgram.mainFragShader = QGLEngineSharedShaders::MainFragmentShader_O;
0
665 if (!hasCompose && !hasMask && !useGlobalOpacity)
never evaluated: !hasCompose
never evaluated: !hasMask
never evaluated: !useGlobalOpacity
0
666 requiredProgram.mainFragShader = QGLEngineSharedShaders::MainFragmentShader;
never executed: requiredProgram.mainFragShader = QGLEngineSharedShaders::MainFragmentShader;
0
667 }
never executed: }
0
668 -
669 if (hasMask) {
never evaluated: hasMask
0
670 if (maskType == PixelMask) {
never evaluated: maskType == PixelMask
0
671 requiredProgram.maskFragShader = QGLEngineSharedShaders::MaskFragmentShader; -
672 texCoords = true; -
673 } else if (maskType == SubPixelMaskPass1) {
never executed: }
never evaluated: maskType == SubPixelMaskPass1
0
674 requiredProgram.maskFragShader = QGLEngineSharedShaders::RgbMaskFragmentShaderPass1; -
675 texCoords = true; -
676 } else if (maskType == SubPixelMaskPass2) {
never executed: }
never evaluated: maskType == SubPixelMaskPass2
0
677 requiredProgram.maskFragShader = QGLEngineSharedShaders::RgbMaskFragmentShaderPass2; -
678 texCoords = true; -
679 } else if (maskType == SubPixelWithGammaMask) {
never executed: }
never evaluated: maskType == SubPixelWithGammaMask
0
680 requiredProgram.maskFragShader = QGLEngineSharedShaders::RgbMaskWithGammaFragmentShader; -
681 texCoords = true; -
682 } else {
never executed: }
0
683 QMessageLogger("gl2paintengineex/qglengineshadermanager.cpp", 783, __PRETTY_FUNCTION__).critical("QGLEngineShaderManager::useCorrectShaderProg() - Unknown mask type"); -
684 }
never executed: }
0
685 } else { -
686 requiredProgram.maskFragShader = QGLEngineSharedShaders::NoMaskFragmentShader; -
687 }
never executed: }
0
688 -
689 if (hasCompose) {
never evaluated: hasCompose
0
690 switch (compositionMode) { -
691 case QPainter::CompositionMode_Multiply: -
692 requiredProgram.compositionFragShader = QGLEngineSharedShaders::MultiplyCompositionModeFragmentShader; -
693 break;
never executed: break;
0
694 case QPainter::CompositionMode_Screen: -
695 requiredProgram.compositionFragShader = QGLEngineSharedShaders::ScreenCompositionModeFragmentShader; -
696 break;
never executed: break;
0
697 case QPainter::CompositionMode_Overlay: -
698 requiredProgram.compositionFragShader = QGLEngineSharedShaders::OverlayCompositionModeFragmentShader; -
699 break;
never executed: break;
0
700 case QPainter::CompositionMode_Darken: -
701 requiredProgram.compositionFragShader = QGLEngineSharedShaders::DarkenCompositionModeFragmentShader; -
702 break;
never executed: break;
0
703 case QPainter::CompositionMode_Lighten: -
704 requiredProgram.compositionFragShader = QGLEngineSharedShaders::LightenCompositionModeFragmentShader; -
705 break;
never executed: break;
0
706 case QPainter::CompositionMode_ColorDodge: -
707 requiredProgram.compositionFragShader = QGLEngineSharedShaders::ColorDodgeCompositionModeFragmentShader; -
708 break;
never executed: break;
0
709 case QPainter::CompositionMode_ColorBurn: -
710 requiredProgram.compositionFragShader = QGLEngineSharedShaders::ColorBurnCompositionModeFragmentShader; -
711 break;
never executed: break;
0
712 case QPainter::CompositionMode_HardLight: -
713 requiredProgram.compositionFragShader = QGLEngineSharedShaders::HardLightCompositionModeFragmentShader; -
714 break;
never executed: break;
0
715 case QPainter::CompositionMode_SoftLight: -
716 requiredProgram.compositionFragShader = QGLEngineSharedShaders::SoftLightCompositionModeFragmentShader; -
717 break;
never executed: break;
0
718 case QPainter::CompositionMode_Difference: -
719 requiredProgram.compositionFragShader = QGLEngineSharedShaders::DifferenceCompositionModeFragmentShader; -
720 break;
never executed: break;
0
721 case QPainter::CompositionMode_Exclusion: -
722 requiredProgram.compositionFragShader = QGLEngineSharedShaders::ExclusionCompositionModeFragmentShader; -
723 break;
never executed: break;
0
724 default: -
725 QMessageLogger("gl2paintengineex/qglengineshadermanager.cpp", 825, __PRETTY_FUNCTION__).warning("QGLEngineShaderManager::useCorrectShaderProg() - Unsupported composition mode"); -
726 }
never executed: }
0
727 } else {
never executed: }
0
728 requiredProgram.compositionFragShader = QGLEngineSharedShaders::NoCompositionModeFragmentShader; -
729 }
never executed: }
0
730 -
731 -
732 if (opacityMode == AttributeOpacity) {
never evaluated: opacityMode == AttributeOpacity
0
733 qt_noop(); -
734 requiredProgram.mainVertexShader = QGLEngineSharedShaders::MainWithTexCoordsAndOpacityVertexShader; -
735 } else if (texCoords) {
never executed: }
never evaluated: texCoords
0
736 requiredProgram.mainVertexShader = QGLEngineSharedShaders::MainWithTexCoordsVertexShader; -
737 } else {
never executed: }
0
738 requiredProgram.mainVertexShader = QGLEngineSharedShaders::MainVertexShader; -
739 }
never executed: }
0
740 requiredProgram.useTextureCoords = texCoords; -
741 requiredProgram.useOpacityAttribute = (opacityMode == AttributeOpacity); -
742 if (complexGeometry && srcPixelType == Qt::SolidPattern) {
never evaluated: complexGeometry
never evaluated: srcPixelType == Qt::SolidPattern
0
743 requiredProgram.positionVertexShader = QGLEngineSharedShaders::ComplexGeometryPositionOnlyVertexShader; -
744 requiredProgram.usePmvMatrixAttribute = false; -
745 } else {
never executed: }
0
746 requiredProgram.usePmvMatrixAttribute = true; -
747 -
748 -
749 -
750 complexGeometry = false; -
751 }
never executed: }
0
752 -
753 -
754 currentShaderProg = sharedShaders->findProgramInCache(requiredProgram); -
755 -
756 if (currentShaderProg && useCustomSrc) {
never evaluated: currentShaderProg
never evaluated: useCustomSrc
0
757 customSrcStage->setUniforms(currentShaderProg->program); -
758 }
never executed: }
0
759 -
760 -
761 -
762 QGLContextPrivate* ctx_d = ctx->d_func(); -
763 ctx_d->setVertexAttribArrayEnabled(QT_VERTEX_COORDS_ATTR, true); -
764 ctx_d->setVertexAttribArrayEnabled(QT_TEXTURE_COORDS_ATTR, currentShaderProg && currentShaderProg->useTextureCoords); -
765 ctx_d->setVertexAttribArrayEnabled(QT_OPACITY_ATTR, currentShaderProg && currentShaderProg->useOpacityAttribute); -
766 -
767 shaderProgNeedsChanging = false; -
768 return true;
never executed: return true;
0
769} -
770 -
771 -
772 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial