1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtOpenGL module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
43 When the active program changes, we need to update it's uniforms.
44 We could track state for each program and only update stale uniforms
45 - Could lead to lots of overhead if there's a lot of programs
46 We could update all the uniforms when the program changes
47 - Could end up updating lots of uniforms which don't need updating
49 Updating uniforms should be cheap, so the overhead of updating up-to-date
50 uniforms should be minimal. It's also less complex.
52 Things which _may_ cause a different program to be used:
53 - Change in brush/pen style
54 - Change in painter opacity
55 - Change in composition mode
57 Whenever we set a mode on the shader manager - it needs to tell us if it had
58 to switch to a different program.
60 The shader manager should only switch when we tell it to. E.g. if we set a new
61 brush style and then switch to transparent painter, we only want it to compile
62 and use the correct program when we really need it.
65 // #define QT_OPENGL_CACHE_AS_VBOS
67 #include "qglgradientcache_p.h"
68 #include "qpaintengineex_opengl2_p.h"
70 #include <string.h> //for memcpy
73 #include <private/qgl_p.h>
74 #include <private/qmath_p.h>
75 #include <private/qpaintengineex_p.h>
76 #include <QPaintEngine>
77 #include <private/qpainter_p.h>
78 #include <private/qfontengine_p.h>
79 #include <private/qpixmapdata_gl_p.h>
80 #include <private/qdatabuffer_p.h>
81 #include <private/qstatictext_p.h>
82 #include <private/qtriangulator_p.h>
84 #include "qglengineshadermanager_p.h"
85 #include "qgl2pexvertexarray_p.h"
86 #include "qtriangulatingstroker_p.h"
87 #include "qtextureglyphcache_gl_p.h"
94 extern Q_GUI_EXPORT bool qt_cleartype_enabled;
98 extern bool qt_applefontsmoothing_enabled;
101 #if !defined(QT_MAX_CACHED_GLYPH_SIZE)
102 # define QT_MAX_CACHED_GLYPH_SIZE 64
105 Q_GUI_EXPORT QImage qt_imageForBrush(int brushStyle, bool invert);
107 ////////////////////////////////// Private Methods //////////////////////////////////////////
109 QGL2PaintEngineExPrivate::~QGL2PaintEngineExPrivate()
111 delete shaderManager;
113 while (pathCaches.size()) {
114 QVectorPath::CacheEntry *e = *(pathCaches.constBegin());
115 e->cleanup(e->engine, e->data);
120 if (elementIndicesVBOId != 0) {
121 glDeleteBuffers(1, &elementIndicesVBOId);
122 elementIndicesVBOId = 0;
126 void QGL2PaintEngineExPrivate::updateTextureFilter(GLenum target, GLenum wrapMode, bool smoothPixmapTransform, GLuint id)
128 // glActiveTexture(GL_TEXTURE0 + QT_BRUSH_TEXTURE_UNIT); //### Is it always this texture unit?
129 if (id != GLuint(-1) && id == lastTextureUsed)
132 lastTextureUsed = id;
134 if (smoothPixmapTransform) {
135 glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
136 glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
138 glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
139 glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
141 glTexParameterf(target, GL_TEXTURE_WRAP_S, wrapMode);
142 glTexParameterf(target, GL_TEXTURE_WRAP_T, wrapMode);
146 inline QColor qt_premultiplyColor(QColor c, GLfloat opacity)
148 qreal alpha = c.alphaF() * opacity;
150 c.setRedF(c.redF() * alpha);
151 c.setGreenF(c.greenF() * alpha);
152 c.setBlueF(c.blueF() * alpha);
157 void QGL2PaintEngineExPrivate::setBrush(const QBrush& brush)
159 if (qbrush_fast_equals(currentBrush, brush))
162 const Qt::BrushStyle newStyle = qbrush_style(brush);
163 Q_ASSERT(newStyle != Qt::NoBrush);
165 currentBrush = brush;
166 if (!currentBrushPixmap.isNull())
167 currentBrushPixmap = QPixmap();
168 brushUniformsDirty = true; // All brushes have at least one uniform
170 if (newStyle > Qt::SolidPattern)
171 brushTextureDirty = true;
173 if (currentBrush.style() == Qt::TexturePattern
174 && qHasPixmapTexture(brush) && brush.texture().isQBitmap())
176 shaderManager->setSrcPixelType(QGLEngineShaderManager::TextureSrcWithPattern);
178 shaderManager->setSrcPixelType(newStyle);
180 shaderManager->optimiseForBrushTransform(currentBrush.transform().type());
184 void QGL2PaintEngineExPrivate::useSimpleShader()
186 shaderManager->useSimpleProgram();
192 void QGL2PaintEngineExPrivate::updateBrushTexture()
194 Q_Q(QGL2PaintEngineEx);
195 // qDebug("QGL2PaintEngineExPrivate::updateBrushTexture()");
196 Qt::BrushStyle style = currentBrush.style();
198 if ( (style >= Qt::Dense1Pattern) && (style <= Qt::DiagCrossPattern) ) {
199 // Get the image data for the pattern
200 QImage texImage = qt_imageForBrush(style, false);
202 glActiveTexture(GL_TEXTURE0 + QT_BRUSH_TEXTURE_UNIT);
203 ctx->d_func()->bindTexture(texImage, GL_TEXTURE_2D, GL_RGBA, QGLContext::InternalBindOption);
204 updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, q->state()->renderHints & QPainter::SmoothPixmapTransform);
206 else if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern) {
207 // Gradiant brush: All the gradiants use the same texture
209 const QGradient* g = currentBrush.gradient();
211 // We apply global opacity in the fragment shaders, so we always pass 1.0
212 // for opacity to the cache.
213 GLuint texId = QGL2GradientCache::cacheForContext(ctx)->getBuffer(*g, 1.0);
215 glActiveTexture(GL_TEXTURE0 + QT_BRUSH_TEXTURE_UNIT);
216 glBindTexture(GL_TEXTURE_2D, texId);
218 if (g->spread() == QGradient::RepeatSpread || g->type() == QGradient::ConicalGradient)
219 updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, q->state()->renderHints & QPainter::SmoothPixmapTransform);
220 else if (g->spread() == QGradient::ReflectSpread)
221 updateTextureFilter(GL_TEXTURE_2D, GL_MIRRORED_REPEAT_IBM, q->state()->renderHints & QPainter::SmoothPixmapTransform);
223 updateTextureFilter(GL_TEXTURE_2D, GL_CLAMP_TO_EDGE, q->state()->renderHints & QPainter::SmoothPixmapTransform);
225 else if (style == Qt::TexturePattern) {
226 currentBrushPixmap = currentBrush.texture();
228 int max_texture_size = ctx->d_func()->maxTextureSize();
229 if (currentBrushPixmap.width() > max_texture_size || currentBrushPixmap.height() > max_texture_size)
230 currentBrushPixmap = currentBrushPixmap.scaled(max_texture_size, max_texture_size, Qt::KeepAspectRatio);
232 glActiveTexture(GL_TEXTURE0 + QT_BRUSH_TEXTURE_UNIT);
233 QGLTexture *tex = ctx->d_func()->bindTexture(currentBrushPixmap, GL_TEXTURE_2D, GL_RGBA,
234 QGLContext::InternalBindOption |
235 QGLContext::CanFlipNativePixmapBindOption);
236 updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, q->state()->renderHints & QPainter::SmoothPixmapTransform);
237 textureInvertedY = tex->options & QGLContext::InvertedYBindOption ? -1 : 1;
239 brushTextureDirty = false;
243 void QGL2PaintEngineExPrivate::updateBrushUniforms()
245 // qDebug("QGL2PaintEngineExPrivate::updateBrushUniforms()");
246 Qt::BrushStyle style = currentBrush.style();
248 if (style == Qt::NoBrush)
251 QTransform brushQTransform = currentBrush.transform();
253 if (style == Qt::SolidPattern) {
254 QColor col = qt_premultiplyColor(currentBrush.color(), (GLfloat)q->state()->opacity);
255 shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::FragmentColor), col);
258 // All other brushes have a transform and thus need the translation point:
259 QPointF translationPoint;
261 if (style <= Qt::DiagCrossPattern) {
262 QColor col = qt_premultiplyColor(currentBrush.color(), (GLfloat)q->state()->opacity);
264 shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::PatternColor), col);
266 QVector2D halfViewportSize(width*0.5, height*0.5);
267 shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::HalfViewportSize), halfViewportSize);
269 else if (style == Qt::LinearGradientPattern) {
270 const QLinearGradient *g = static_cast<const QLinearGradient *>(currentBrush.gradient());
272 QPointF realStart = g->start();
273 QPointF realFinal = g->finalStop();
274 translationPoint = realStart;
276 QPointF l = realFinal - realStart;
278 QVector3D linearData(
281 1.0f / (l.x() * l.x() + l.y() * l.y())
284 shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::LinearData), linearData);
286 QVector2D halfViewportSize(width*0.5, height*0.5);
287 shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::HalfViewportSize), halfViewportSize);
289 else if (style == Qt::ConicalGradientPattern) {
290 const QConicalGradient *g = static_cast<const QConicalGradient *>(currentBrush.gradient());
291 translationPoint = g->center();
293 GLfloat angle = -(g->angle() * 2 * Q_PI) / 360.0;
295 shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::Angle), angle);
297 QVector2D halfViewportSize(width*0.5, height*0.5);
298 shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::HalfViewportSize), halfViewportSize);
300 else if (style == Qt::RadialGradientPattern) {
301 const QRadialGradient *g = static_cast<const QRadialGradient *>(currentBrush.gradient());
302 QPointF realCenter = g->center();
303 QPointF realFocal = g->focalPoint();
304 qreal realRadius = g->centerRadius() - g->focalRadius();
305 translationPoint = realFocal;
307 QPointF fmp = realCenter - realFocal;
308 shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::Fmp), fmp);
310 GLfloat fmp2_m_radius2 = -fmp.x() * fmp.x() - fmp.y() * fmp.y() + realRadius*realRadius;
311 shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::Fmp2MRadius2), fmp2_m_radius2);
312 shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::Inverse2Fmp2MRadius2),
313 GLfloat(1.0 / (2.0*fmp2_m_radius2)));
314 shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::SqrFr),
315 GLfloat(g->focalRadius() * g->focalRadius()));
316 shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::BRadius),
317 GLfloat(2 * (g->centerRadius() - g->focalRadius()) * g->focalRadius()),
319 g->centerRadius() - g->focalRadius());
321 QVector2D halfViewportSize(width*0.5, height*0.5);
322 shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::HalfViewportSize), halfViewportSize);
324 else if (style == Qt::TexturePattern) {
325 const QPixmap& texPixmap = currentBrush.texture();
327 if (qHasPixmapTexture(currentBrush) && currentBrush.texture().isQBitmap()) {
328 QColor col = qt_premultiplyColor(currentBrush.color(), (GLfloat)q->state()->opacity);
329 shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::PatternColor), col);
332 QSizeF invertedTextureSize(1.0 / texPixmap.width(), 1.0 / texPixmap.height());
333 shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::InvertedTextureSize), invertedTextureSize);
335 QVector2D halfViewportSize(width*0.5, height*0.5);
336 shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::HalfViewportSize), halfViewportSize);
339 qWarning("QGL2PaintEngineEx: Unimplemented fill style");
341 const QPointF &brushOrigin = q->state()->brushOrigin;
342 QTransform matrix = q->state()->matrix;
343 matrix.translate(brushOrigin.x(), brushOrigin.y());
345 QTransform translate(1, 0, 0, 1, -translationPoint.x(), -translationPoint.y());
348 if (device->isFlipped()) {
352 QTransform gl_to_qt(1, 0, 0, m22, 0, dy);
353 QTransform inv_matrix;
354 if (style == Qt::TexturePattern && textureInvertedY == -1)
355 inv_matrix = gl_to_qt * (QTransform(1, 0, 0, -1, 0, currentBrush.texture().height()) * brushQTransform * matrix).inverted() * translate;
357 inv_matrix = gl_to_qt * (brushQTransform * matrix).inverted() * translate;
359 shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::BrushTransform), inv_matrix);
360 shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::BrushTexture), QT_BRUSH_TEXTURE_UNIT);
362 brushUniformsDirty = false;
366 // This assumes the shader manager has already setup the correct shader program
367 void QGL2PaintEngineExPrivate::updateMatrix()
369 // qDebug("QGL2PaintEngineExPrivate::updateMatrix()");
371 const QTransform& transform = q->state()->matrix;
373 // The projection matrix converts from Qt's coordinate system to GL's coordinate system
374 // * GL's viewport is 2x2, Qt's is width x height
375 // * GL has +y -> -y going from bottom -> top, Qt is the other way round
376 // * GL has [0,0] in the center, Qt has it in the top-left
378 // This results in the Projection matrix below, which is multiplied by the painter's
379 // transformation matrix, as shown below:
381 // Projection Matrix Painter Transform
382 // ------------------------------------------------ ------------------------
383 // | 2.0 / width | 0.0 | -1.0 | | m11 | m21 | dx |
384 // | 0.0 | -2.0 / height | 1.0 | * | m12 | m22 | dy |
385 // | 0.0 | 0.0 | 1.0 | | m13 | m23 | m33 |
386 // ------------------------------------------------ ------------------------
388 // NOTE: The resultant matrix is also transposed, as GL expects column-major matracies
390 const GLfloat wfactor = 2.0f / width;
391 GLfloat hfactor = -2.0f / height;
393 GLfloat dx = transform.dx();
394 GLfloat dy = transform.dy();
396 if (device->isFlipped()) {
401 // Non-integer translates can have strange effects for some rendering operations such as
402 // anti-aliased text rendering. In such cases, we snap the translate to the pixel grid.
403 if (snapToPixelGrid && transform.type() == QTransform::TxTranslate) {
404 // 0.50 needs to rounded down to 0.0 for consistency with raster engine:
405 dx = ceilf(dx - 0.5f);
406 dy = ceilf(dy - 0.5f);
408 pmvMatrix[0][0] = (wfactor * transform.m11()) - transform.m13();
409 pmvMatrix[1][0] = (wfactor * transform.m21()) - transform.m23();
410 pmvMatrix[2][0] = (wfactor * dx) - transform.m33();
411 pmvMatrix[0][1] = (hfactor * transform.m12()) + transform.m13();
412 pmvMatrix[1][1] = (hfactor * transform.m22()) + transform.m23();
413 pmvMatrix[2][1] = (hfactor * dy) + transform.m33();
414 pmvMatrix[0][2] = transform.m13();
415 pmvMatrix[1][2] = transform.m23();
416 pmvMatrix[2][2] = transform.m33();
418 // 1/10000 == 0.0001, so we have good enough res to cover curves
419 // that span the entire widget...
420 inverseScale = qMax(1 / qMax( qMax(qAbs(transform.m11()), qAbs(transform.m22())),
421 qMax(qAbs(transform.m12()), qAbs(transform.m21())) ),
425 matrixUniformDirty = true;
427 // Set the PMV matrix attribute. As we use an attributes rather than uniforms, we only
428 // need to do this once for every matrix change and persists across all shader programs.
429 glVertexAttrib3fv(QT_PMV_MATRIX_1_ATTR, pmvMatrix[0]);
430 glVertexAttrib3fv(QT_PMV_MATRIX_2_ATTR, pmvMatrix[1]);
431 glVertexAttrib3fv(QT_PMV_MATRIX_3_ATTR, pmvMatrix[2]);
433 dasher.setInvScale(inverseScale);
434 stroker.setInvScale(inverseScale);
438 void QGL2PaintEngineExPrivate::updateCompositionMode()
440 // NOTE: The entire paint engine works on pre-multiplied data - which is why some of these
441 // composition modes look odd.
442 // qDebug() << "QGL2PaintEngineExPrivate::updateCompositionMode() - Setting GL composition mode for " << q->state()->composition_mode;
443 switch(q->state()->composition_mode) {
444 case QPainter::CompositionMode_SourceOver:
445 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
447 case QPainter::CompositionMode_DestinationOver:
448 glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE);
450 case QPainter::CompositionMode_Clear:
451 glBlendFunc(GL_ZERO, GL_ZERO);
453 case QPainter::CompositionMode_Source:
454 glBlendFunc(GL_ONE, GL_ZERO);
456 case QPainter::CompositionMode_Destination:
457 glBlendFunc(GL_ZERO, GL_ONE);
459 case QPainter::CompositionMode_SourceIn:
460 glBlendFunc(GL_DST_ALPHA, GL_ZERO);
462 case QPainter::CompositionMode_DestinationIn:
463 glBlendFunc(GL_ZERO, GL_SRC_ALPHA);
465 case QPainter::CompositionMode_SourceOut:
466 glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ZERO);
468 case QPainter::CompositionMode_DestinationOut:
469 glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);
471 case QPainter::CompositionMode_SourceAtop:
472 glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
474 case QPainter::CompositionMode_DestinationAtop:
475 glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA);
477 case QPainter::CompositionMode_Xor:
478 glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
480 case QPainter::CompositionMode_Plus:
481 glBlendFunc(GL_ONE, GL_ONE);
484 qWarning("Unsupported composition mode");
488 compositionModeDirty = false;
491 static inline void setCoords(GLfloat *coords, const QGLRect &rect)
493 coords[0] = rect.left;
494 coords[1] = rect.top;
495 coords[2] = rect.right;
496 coords[3] = rect.top;
497 coords[4] = rect.right;
498 coords[5] = rect.bottom;
499 coords[6] = rect.left;
500 coords[7] = rect.bottom;
503 void QGL2PaintEngineExPrivate::drawTexture(const QGLRect& dest, const QGLRect& src, const QSize &textureSize, bool opaque, bool pattern)
505 // Setup for texture drawing
506 currentBrush = noBrush;
507 shaderManager->setSrcPixelType(pattern ? QGLEngineShaderManager::PatternSrc : QGLEngineShaderManager::ImageSrc);
509 if (snapToPixelGrid) {
510 snapToPixelGrid = false;
514 if (prepareForDraw(opaque))
515 shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::ImageTexture), QT_IMAGE_TEXTURE_UNIT);
518 QColor col = qt_premultiplyColor(q->state()->pen.color(), (GLfloat)q->state()->opacity);
519 shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::PatternColor), col);
522 GLfloat dx = 1.0 / textureSize.width();
523 GLfloat dy = 1.0 / textureSize.height();
525 QGLRect srcTextureRect(src.left*dx, src.top*dy, src.right*dx, src.bottom*dy);
527 setCoords(staticVertexCoordinateArray, dest);
528 setCoords(staticTextureCoordinateArray, srcTextureRect);
530 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
533 void QGL2PaintEngineEx::beginNativePainting()
535 Q_D(QGL2PaintEngineEx);
537 d->transferMode(BrushDrawingMode);
539 d->nativePaintingActive = true;
541 QGLContext *ctx = d->ctx;
544 // Disable all the vertex attribute arrays:
545 for (int i = 0; i < QT_GL_VERTEX_ARRAY_TRACKED_COUNT; ++i)
546 glDisableVertexAttribArray(i);
548 #ifndef QT_OPENGL_ES_2
549 const QGLFormat &fmt = d->device->format();
550 if (fmt.majorVersion() < 3 || (fmt.majorVersion() == 3 && fmt.minorVersion() < 1)
551 || fmt.profile() == QGLFormat::CompatibilityProfile)
553 // be nice to people who mix OpenGL 1.x code with QPainter commands
554 // by setting modelview and projection matrices to mirror the GL 1
556 const QTransform& mtx = state()->matrix;
558 float mv_matrix[4][4] =
560 { float(mtx.m11()), float(mtx.m12()), 0, float(mtx.m13()) },
561 { float(mtx.m21()), float(mtx.m22()), 0, float(mtx.m23()) },
563 { float(mtx.dx()), float(mtx.dy()), 0, float(mtx.m33()) }
566 const QSize sz = d->device->size();
568 glMatrixMode(GL_PROJECTION);
570 glOrtho(0, sz.width(), sz.height(), 0, -999999, 999999);
572 glMatrixMode(GL_MODELVIEW);
573 glLoadMatrixf(&mv_matrix[0][0]);
579 d->lastTextureUsed = GLuint(-1);
580 d->dirtyStencilRegion = QRect(0, 0, d->width, d->height);
583 d->shaderManager->setDirty();
588 void QGL2PaintEngineExPrivate::resetGLState()
591 glActiveTexture(GL_TEXTURE0);
592 glDisable(GL_STENCIL_TEST);
593 glDisable(GL_DEPTH_TEST);
594 glDisable(GL_SCISSOR_TEST);
596 glDepthFunc(GL_LESS);
599 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
600 glStencilFunc(GL_ALWAYS, 0, 0xff);
601 ctx->d_func()->setVertexAttribArrayEnabled(QT_TEXTURE_COORDS_ATTR, false);
602 ctx->d_func()->setVertexAttribArrayEnabled(QT_VERTEX_COORDS_ATTR, false);
603 ctx->d_func()->setVertexAttribArrayEnabled(QT_OPACITY_ATTR, false);
604 #ifndef QT_OPENGL_ES_2
605 // gl_Color, corresponding to vertex attribute 3, may have been changed
606 float color[] = { 1.0f, 1.0f, 1.0f, 1.0f };
607 glVertexAttrib4fv(3, color);
611 void QGL2PaintEngineEx::endNativePainting()
613 Q_D(QGL2PaintEngineEx);
615 d->nativePaintingActive = false;
618 void QGL2PaintEngineEx::invalidateState()
620 Q_D(QGL2PaintEngineEx);
624 bool QGL2PaintEngineEx::isNativePaintingActive() const {
625 Q_D(const QGL2PaintEngineEx);
626 return d->nativePaintingActive;
629 void QGL2PaintEngineExPrivate::transferMode(EngineMode newMode)
634 if (mode == TextDrawingMode || mode == ImageDrawingMode || mode == ImageArrayDrawingMode) {
635 lastTextureUsed = GLuint(-1);
638 if (newMode == TextDrawingMode) {
639 shaderManager->setHasComplexGeometry(true);
641 shaderManager->setHasComplexGeometry(false);
644 if (newMode == ImageDrawingMode) {
645 setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, staticVertexCoordinateArray);
646 setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, staticTextureCoordinateArray);
649 if (newMode == ImageArrayDrawingMode) {
650 setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, (GLfloat*)vertexCoordinateArray.data());
651 setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, (GLfloat*)textureCoordinateArray.data());
652 setVertexAttributePointer(QT_OPACITY_ATTR, (GLfloat*)opacityArray.data());
655 // This needs to change when we implement high-quality anti-aliasing...
656 if (newMode != TextDrawingMode)
657 shaderManager->setMaskType(QGLEngineShaderManager::NoMask);
662 struct QGL2PEVectorPathCache
664 #ifdef QT_OPENGL_CACHE_AS_VBOS
673 GLenum primitiveType;
677 void QGL2PaintEngineExPrivate::cleanupVectorPath(QPaintEngineEx *engine, void *data)
679 QGL2PEVectorPathCache *c = (QGL2PEVectorPathCache *) data;
680 #ifdef QT_OPENGL_CACHE_AS_VBOS
681 Q_ASSERT(engine->type() == QPaintEngine::OpenGL2);
682 static_cast<QGL2PaintEngineEx *>(engine)->d_func()->unusedVBOSToClean << c->vbo;
684 d->unusedIBOSToClean << c->ibo;
693 // Assumes everything is configured for the brush you want to use
694 void QGL2PaintEngineExPrivate::fill(const QVectorPath& path)
696 transferMode(BrushDrawingMode);
698 if (snapToPixelGrid) {
699 snapToPixelGrid = false;
703 // Might need to call updateMatrix to re-calculate inverseScale
707 const QPointF* const points = reinterpret_cast<const QPointF*>(path.points());
709 // Check to see if there's any hints
710 if (path.shape() == QVectorPath::RectangleHint) {
711 QGLRect rect(points[0].x(), points[0].y(), points[2].x(), points[2].y());
712 prepareForDraw(currentBrush.isOpaque());
714 } else if (path.isConvex()) {
716 if (path.isCacheable()) {
717 QVectorPath::CacheEntry *data = path.lookupCacheData(q);
718 QGL2PEVectorPathCache *cache;
720 bool updateCache = false;
723 cache = (QGL2PEVectorPathCache *) data->data;
724 // Check if scale factor is exceeded for curved paths and generate curves if so...
725 if (path.isCurved()) {
726 qreal scaleFactor = cache->iscale / inverseScale;
727 if (scaleFactor < 0.5 || scaleFactor > 2.0) {
728 #ifdef QT_OPENGL_CACHE_AS_VBOS
729 glDeleteBuffers(1, &cache->vbo);
731 Q_ASSERT(cache->ibo == 0);
733 qFree(cache->vertices);
734 Q_ASSERT(cache->indices == 0);
740 cache = new QGL2PEVectorPathCache;
741 data = const_cast<QVectorPath &>(path).addCacheData(q, cache, cleanupVectorPath);
745 // Flatten the path at the current scale factor and fill it into the cache struct.
747 vertexCoordinateArray.clear();
748 vertexCoordinateArray.addPath(path, inverseScale, false);
749 int vertexCount = vertexCoordinateArray.vertexCount();
750 int floatSizeInBytes = vertexCount * 2 * sizeof(float);
751 cache->vertexCount = vertexCount;
752 cache->indexCount = 0;
753 cache->primitiveType = GL_TRIANGLE_FAN;
754 cache->iscale = inverseScale;
755 #ifdef QT_OPENGL_CACHE_AS_VBOS
756 glGenBuffers(1, &cache->vbo);
757 glBindBuffer(GL_ARRAY_BUFFER, cache->vbo);
758 glBufferData(GL_ARRAY_BUFFER, floatSizeInBytes, vertexCoordinateArray.data(), GL_STATIC_DRAW);
761 cache->vertices = (float *) qMalloc(floatSizeInBytes);
762 memcpy(cache->vertices, vertexCoordinateArray.data(), floatSizeInBytes);
767 prepareForDraw(currentBrush.isOpaque());
768 #ifdef QT_OPENGL_CACHE_AS_VBOS
769 glBindBuffer(GL_ARRAY_BUFFER, cache->vbo);
770 setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, 0);
772 setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, cache->vertices);
774 glDrawArrays(cache->primitiveType, 0, cache->vertexCount);
777 // printf(" - Marking path as cachable...\n");
778 // Tag it for later so that if the same path is drawn twice, it is assumed to be static and thus cachable
779 path.makeCacheable();
780 vertexCoordinateArray.clear();
781 vertexCoordinateArray.addPath(path, inverseScale, false);
782 prepareForDraw(currentBrush.isOpaque());
783 drawVertexArrays(vertexCoordinateArray, GL_TRIANGLE_FAN);
787 bool useCache = path.isCacheable();
789 QRectF bbox = path.controlPointRect();
790 // If the path doesn't fit within these limits, it is possible that the triangulation will fail.
791 useCache &= (bbox.left() > -0x8000 * inverseScale)
792 && (bbox.right() < 0x8000 * inverseScale)
793 && (bbox.top() > -0x8000 * inverseScale)
794 && (bbox.bottom() < 0x8000 * inverseScale);
798 QVectorPath::CacheEntry *data = path.lookupCacheData(q);
799 QGL2PEVectorPathCache *cache;
801 bool updateCache = false;
804 cache = (QGL2PEVectorPathCache *) data->data;
805 // Check if scale factor is exceeded for curved paths and generate curves if so...
806 if (path.isCurved()) {
807 qreal scaleFactor = cache->iscale / inverseScale;
808 if (scaleFactor < 0.5 || scaleFactor > 2.0) {
809 #ifdef QT_OPENGL_CACHE_AS_VBOS
810 glDeleteBuffers(1, &cache->vbo);
811 glDeleteBuffers(1, &cache->ibo);
813 qFree(cache->vertices);
814 qFree(cache->indices);
820 cache = new QGL2PEVectorPathCache;
821 data = const_cast<QVectorPath &>(path).addCacheData(q, cache, cleanupVectorPath);
825 // Flatten the path at the current scale factor and fill it into the cache struct.
827 QTriangleSet polys = qTriangulate(path, QTransform().scale(1 / inverseScale, 1 / inverseScale));
828 cache->vertexCount = polys.vertices.size() / 2;
829 cache->indexCount = polys.indices.size();
830 cache->primitiveType = GL_TRIANGLES;
831 cache->iscale = inverseScale;
832 #ifdef QT_OPENGL_CACHE_AS_VBOS
833 glGenBuffers(1, &cache->vbo);
834 glGenBuffers(1, &cache->ibo);
835 glBindBuffer(GL_ARRAY_BUFFER, cache->vbo);
836 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cache->ibo);
838 if (QGLExtensions::glExtensions() & QGLExtensions::ElementIndexUint)
839 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(quint32) * polys.indices.size(), polys.indices.data(), GL_STATIC_DRAW);
841 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(quint16) * polys.indices.size(), polys.indices.data(), GL_STATIC_DRAW);
843 QVarLengthArray<float> vertices(polys.vertices.size());
844 for (int i = 0; i < polys.vertices.size(); ++i)
845 vertices[i] = float(inverseScale * polys.vertices.at(i));
846 glBufferData(GL_ARRAY_BUFFER, sizeof(float) * vertices.size(), vertices.data(), GL_STATIC_DRAW);
848 cache->vertices = (float *) qMalloc(sizeof(float) * polys.vertices.size());
849 if (QGLExtensions::glExtensions() & QGLExtensions::ElementIndexUint) {
850 cache->indices = (quint32 *) qMalloc(sizeof(quint32) * polys.indices.size());
851 memcpy(cache->indices, polys.indices.data(), sizeof(quint32) * polys.indices.size());
853 cache->indices = (quint16 *) qMalloc(sizeof(quint16) * polys.indices.size());
854 memcpy(cache->indices, polys.indices.data(), sizeof(quint16) * polys.indices.size());
856 for (int i = 0; i < polys.vertices.size(); ++i)
857 cache->vertices[i] = float(inverseScale * polys.vertices.at(i));
861 prepareForDraw(currentBrush.isOpaque());
862 #ifdef QT_OPENGL_CACHE_AS_VBOS
863 glBindBuffer(GL_ARRAY_BUFFER, cache->vbo);
864 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cache->ibo);
865 setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, 0);
866 if (QGLExtensions::glExtensions() & QGLExtensions::ElementIndexUint)
867 glDrawElements(cache->primitiveType, cache->indexCount, GL_UNSIGNED_INT, 0);
869 glDrawElements(cache->primitiveType, cache->indexCount, GL_UNSIGNED_SHORT, 0);
870 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
871 glBindBuffer(GL_ARRAY_BUFFER, 0);
873 setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, cache->vertices);
874 if (QGLExtensions::glExtensions() & QGLExtensions::ElementIndexUint)
875 glDrawElements(cache->primitiveType, cache->indexCount, GL_UNSIGNED_INT, (qint32 *)cache->indices);
877 glDrawElements(cache->primitiveType, cache->indexCount, GL_UNSIGNED_SHORT, (qint16 *)cache->indices);
881 // printf(" - Marking path as cachable...\n");
882 // Tag it for later so that if the same path is drawn twice, it is assumed to be static and thus cachable
883 path.makeCacheable();
885 if (!device->format().stencil()) {
886 // If there is no stencil buffer, triangulate the path instead.
888 QRectF bbox = path.controlPointRect();
889 // If the path doesn't fit within these limits, it is possible that the triangulation will fail.
890 bool withinLimits = (bbox.left() > -0x8000 * inverseScale)
891 && (bbox.right() < 0x8000 * inverseScale)
892 && (bbox.top() > -0x8000 * inverseScale)
893 && (bbox.bottom() < 0x8000 * inverseScale);
895 QTriangleSet polys = qTriangulate(path, QTransform().scale(1 / inverseScale, 1 / inverseScale));
897 QVarLengthArray<float> vertices(polys.vertices.size());
898 for (int i = 0; i < polys.vertices.size(); ++i)
899 vertices[i] = float(inverseScale * polys.vertices.at(i));
901 prepareForDraw(currentBrush.isOpaque());
902 setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, vertices.constData());
903 if (QGLExtensions::glExtensions() & QGLExtensions::ElementIndexUint)
904 glDrawElements(GL_TRIANGLES, polys.indices.size(), GL_UNSIGNED_INT, polys.indices.data());
906 glDrawElements(GL_TRIANGLES, polys.indices.size(), GL_UNSIGNED_SHORT, polys.indices.data());
908 // We can't handle big, concave painter paths with OpenGL without stencil buffer.
909 qWarning("Painter path exceeds +/-32767 pixels.");
914 // The path is too complicated & needs the stencil technique
915 vertexCoordinateArray.clear();
916 vertexCoordinateArray.addPath(path, inverseScale, false);
918 fillStencilWithVertexArray(vertexCoordinateArray, path.hasWindingFill());
921 glStencilOp(GL_KEEP, GL_REPLACE, GL_REPLACE);
923 if (q->state()->clipTestEnabled) {
924 // Pass when high bit is set, replace stencil value with current clip
925 glStencilFunc(GL_NOTEQUAL, q->state()->currentClip, GL_STENCIL_HIGH_BIT);
926 } else if (path.hasWindingFill()) {
927 // Pass when any bit is set, replace stencil value with 0
928 glStencilFunc(GL_NOTEQUAL, 0, 0xff);
930 // Pass when high bit is set, replace stencil value with 0
931 glStencilFunc(GL_NOTEQUAL, 0, GL_STENCIL_HIGH_BIT);
933 prepareForDraw(currentBrush.isOpaque());
935 // Stencil the brush onto the dest buffer
936 composite(vertexCoordinateArray.boundingRect());
938 updateClipScissorTest();
944 void QGL2PaintEngineExPrivate::fillStencilWithVertexArray(const float *data,
948 const QGLRect &bounds,
949 StencilFillMode mode)
951 Q_ASSERT(count || stops);
953 // qDebug("QGL2PaintEngineExPrivate::fillStencilWithVertexArray()");
954 glStencilMask(0xff); // Enable stencil writes
956 if (dirtyStencilRegion.intersects(currentScissorBounds)) {
957 QVector<QRect> clearRegion = dirtyStencilRegion.intersected(currentScissorBounds).rects();
958 glClearStencil(0); // Clear to zero
959 for (int i = 0; i < clearRegion.size(); ++i) {
960 #ifndef QT_GL_NO_SCISSOR_TEST
961 setScissor(clearRegion.at(i));
963 glClear(GL_STENCIL_BUFFER_BIT);
966 dirtyStencilRegion -= currentScissorBounds;
968 #ifndef QT_GL_NO_SCISSOR_TEST
969 updateClipScissorTest();
973 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // Disable color writes
975 glEnable(GL_STENCIL_TEST); // For some reason, this has to happen _after_ the simple shader is use()'d
977 if (mode == WindingFillMode) {
978 Q_ASSERT(stops && !count);
979 if (q->state()->clipTestEnabled) {
980 // Flatten clip values higher than current clip, and set high bit to match current clip
981 glStencilFunc(GL_LEQUAL, GL_STENCIL_HIGH_BIT | q->state()->currentClip, ~GL_STENCIL_HIGH_BIT);
982 glStencilOp(GL_KEEP, GL_REPLACE, GL_REPLACE);
985 glStencilFunc(GL_EQUAL, GL_STENCIL_HIGH_BIT, GL_STENCIL_HIGH_BIT);
986 } else if (!stencilClean) {
987 // Clear stencil buffer within bounding rect
988 glStencilFunc(GL_ALWAYS, 0, 0xff);
989 glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO);
993 // Inc. for front-facing triangle
994 glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_INCR_WRAP, GL_INCR_WRAP);
995 // Dec. for back-facing "holes"
996 glStencilOpSeparate(GL_BACK, GL_KEEP, GL_DECR_WRAP, GL_DECR_WRAP);
997 glStencilMask(~GL_STENCIL_HIGH_BIT);
998 drawVertexArrays(data, stops, stopCount, GL_TRIANGLE_FAN);
1000 if (q->state()->clipTestEnabled) {
1001 // Clear high bit of stencil outside of path
1002 glStencilFunc(GL_EQUAL, q->state()->currentClip, ~GL_STENCIL_HIGH_BIT);
1003 glStencilOp(GL_KEEP, GL_REPLACE, GL_REPLACE);
1004 glStencilMask(GL_STENCIL_HIGH_BIT);
1007 } else if (mode == OddEvenFillMode) {
1008 glStencilMask(GL_STENCIL_HIGH_BIT);
1009 glStencilOp(GL_KEEP, GL_KEEP, GL_INVERT); // Simply invert the stencil bit
1010 drawVertexArrays(data, stops, stopCount, GL_TRIANGLE_FAN);
1012 } else { // TriStripStrokeFillMode
1013 Q_ASSERT(count && !stops); // tristrips generated directly, so no vertexArray or stops
1014 glStencilMask(GL_STENCIL_HIGH_BIT);
1016 glStencilOp(GL_KEEP, GL_KEEP, GL_INVERT); // Simply invert the stencil bit
1017 setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, data);
1018 glDrawArrays(GL_TRIANGLE_STRIP, 0, count);
1021 glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
1022 if (q->state()->clipTestEnabled) {
1023 glStencilFunc(GL_LEQUAL, q->state()->currentClip | GL_STENCIL_HIGH_BIT,
1024 ~GL_STENCIL_HIGH_BIT);
1026 glStencilFunc(GL_ALWAYS, GL_STENCIL_HIGH_BIT, 0xff);
1028 setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, data);
1029 glDrawArrays(GL_TRIANGLE_STRIP, 0, count);
1033 // Enable color writes & disable stencil writes
1034 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
1038 If the maximum value in the stencil buffer is GL_STENCIL_HIGH_BIT - 1,
1039 restore the stencil buffer to a pristine state. The current clip region
1040 is set to 1, and the rest to 0.
1042 void QGL2PaintEngineExPrivate::resetClipIfNeeded()
1044 if (maxClip != (GL_STENCIL_HIGH_BIT - 1))
1047 Q_Q(QGL2PaintEngineEx);
1050 glEnable(GL_STENCIL_TEST);
1051 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
1053 QRectF bounds = q->state()->matrix.inverted().mapRect(QRectF(0, 0, width, height));
1054 QGLRect rect(bounds.left(), bounds.top(), bounds.right(), bounds.bottom());
1056 // Set high bit on clip region
1057 glStencilFunc(GL_LEQUAL, q->state()->currentClip, 0xff);
1058 glStencilOp(GL_KEEP, GL_INVERT, GL_INVERT);
1059 glStencilMask(GL_STENCIL_HIGH_BIT);
1062 // Reset clipping to 1 and everything else to zero
1063 glStencilFunc(GL_NOTEQUAL, 0x01, GL_STENCIL_HIGH_BIT);
1064 glStencilOp(GL_ZERO, GL_REPLACE, GL_REPLACE);
1065 glStencilMask(0xff);
1068 q->state()->currentClip = 1;
1069 q->state()->canRestoreClip = false;
1074 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
1077 bool QGL2PaintEngineExPrivate::prepareForDraw(bool srcPixelsAreOpaque)
1079 if (brushTextureDirty && mode != ImageDrawingMode && mode != ImageArrayDrawingMode)
1080 updateBrushTexture();
1082 if (compositionModeDirty)
1083 updateCompositionMode();
1088 const bool stateHasOpacity = q->state()->opacity < 0.99f;
1089 if (q->state()->composition_mode == QPainter::CompositionMode_Source
1090 || (q->state()->composition_mode == QPainter::CompositionMode_SourceOver
1091 && srcPixelsAreOpaque && !stateHasOpacity))
1093 glDisable(GL_BLEND);
1098 QGLEngineShaderManager::OpacityMode opacityMode;
1099 if (mode == ImageArrayDrawingMode) {
1100 opacityMode = QGLEngineShaderManager::AttributeOpacity;
1102 opacityMode = stateHasOpacity ? QGLEngineShaderManager::UniformOpacity
1103 : QGLEngineShaderManager::NoOpacity;
1104 if (stateHasOpacity && (mode != ImageDrawingMode)) {
1106 bool brushIsPattern = (currentBrush.style() >= Qt::Dense1Pattern) &&
1107 (currentBrush.style() <= Qt::DiagCrossPattern);
1109 if ((currentBrush.style() == Qt::SolidPattern) || brushIsPattern)
1110 opacityMode = QGLEngineShaderManager::NoOpacity; // Global opacity handled by srcPixel shader
1113 shaderManager->setOpacityMode(opacityMode);
1115 bool changed = shaderManager->useCorrectShaderProg();
1116 // If the shader program needs changing, we change it and mark all uniforms as dirty
1118 // The shader program has changed so mark all uniforms as dirty:
1119 brushUniformsDirty = true;
1120 opacityUniformDirty = true;
1121 matrixUniformDirty = true;
1124 if (brushUniformsDirty && mode != ImageDrawingMode && mode != ImageArrayDrawingMode)
1125 updateBrushUniforms();
1127 if (opacityMode == QGLEngineShaderManager::UniformOpacity && opacityUniformDirty) {
1128 shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::GlobalOpacity), (GLfloat)q->state()->opacity);
1129 opacityUniformDirty = false;
1132 if (matrixUniformDirty && shaderManager->hasComplexGeometry()) {
1133 shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::Matrix),
1135 matrixUniformDirty = false;
1141 void QGL2PaintEngineExPrivate::composite(const QGLRect& boundingRect)
1143 setCoords(staticVertexCoordinateArray, boundingRect);
1144 setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, staticVertexCoordinateArray);
1145 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
1148 // Draws the vertex array as a set of <vertexArrayStops.size()> triangle fans.
1149 void QGL2PaintEngineExPrivate::drawVertexArrays(const float *data, int *stops, int stopCount,
1152 // Now setup the pointer to the vertex array:
1153 setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, (GLfloat*)data);
1155 int previousStop = 0;
1156 for (int i=0; i<stopCount; ++i) {
1157 int stop = stops[i];
1159 qDebug("Drawing triangle fan for vertecies %d -> %d:", previousStop, stop-1);
1160 for (int i=previousStop; i<stop; ++i)
1161 qDebug(" %02d: [%.2f, %.2f]", i, vertexArray.data()[i].x, vertexArray.data()[i].y);
1163 glDrawArrays(primitive, previousStop, stop - previousStop);
1164 previousStop = stop;
1168 /////////////////////////////////// Public Methods //////////////////////////////////////////
1170 QGL2PaintEngineEx::QGL2PaintEngineEx()
1171 : QPaintEngineEx(*(new QGL2PaintEngineExPrivate(this)))
1175 QGL2PaintEngineEx::~QGL2PaintEngineEx()
1179 void QGL2PaintEngineEx::fill(const QVectorPath &path, const QBrush &brush)
1181 Q_D(QGL2PaintEngineEx);
1183 if (qbrush_style(brush) == Qt::NoBrush)
1190 Q_GUI_EXPORT bool qt_scaleForTransform(const QTransform &transform, qreal *scale); // qtransform.cpp
1193 void QGL2PaintEngineEx::stroke(const QVectorPath &path, const QPen &pen)
1195 Q_D(QGL2PaintEngineEx);
1197 const QBrush &penBrush = qpen_brush(pen);
1198 if (qpen_style(pen) == Qt::NoPen || qbrush_style(penBrush) == Qt::NoBrush)
1201 QOpenGL2PaintEngineState *s = state();
1202 if (pen.isCosmetic() && !qt_scaleForTransform(s->transform(), 0)) {
1203 // QTriangulatingStroker class is not meant to support cosmetically sheared strokes.
1204 QPaintEngineEx::stroke(path, pen);
1209 d->setBrush(penBrush);
1210 d->stroke(path, pen);
1213 void QGL2PaintEngineExPrivate::stroke(const QVectorPath &path, const QPen &pen)
1215 const QOpenGL2PaintEngineState *s = q->state();
1216 if (snapToPixelGrid) {
1217 snapToPixelGrid = false;
1221 const Qt::PenStyle penStyle = qpen_style(pen);
1222 const QBrush &penBrush = qpen_brush(pen);
1223 const bool opaque = penBrush.isOpaque() && s->opacity > 0.99;
1225 transferMode(BrushDrawingMode);
1227 // updateMatrix() is responsible for setting the inverse scale on
1228 // the strokers, so we need to call it here and not wait for
1229 // prepareForDraw() down below.
1232 QRectF clip = q->state()->matrix.inverted().mapRect(q->state()->clipEnabled
1233 ? q->state()->rectangleClip
1234 : QRectF(0, 0, width, height));
1236 if (penStyle == Qt::SolidLine) {
1237 stroker.process(path, pen, clip);
1239 } else { // Some sort of dash
1240 dasher.process(path, pen, clip);
1242 QVectorPath dashStroke(dasher.points(),
1243 dasher.elementCount(),
1244 dasher.elementTypes());
1245 stroker.process(dashStroke, pen, clip);
1248 if (!stroker.vertexCount())
1252 prepareForDraw(opaque);
1253 setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, stroker.vertices());
1254 glDrawArrays(GL_TRIANGLE_STRIP, 0, stroker.vertexCount() / 2);
1256 // QBrush b(Qt::green);
1258 // d->prepareForDraw(true);
1259 // glDrawArrays(GL_LINE_STRIP, 0, d->stroker.vertexCount() / 2);
1262 qreal width = qpen_widthf(pen) / 2;
1265 qreal extra = pen.joinStyle() == Qt::MiterJoin
1266 ? qMax(pen.miterLimit() * width, width)
1269 if (pen.isCosmetic())
1270 extra = extra * inverseScale;
1272 QRectF bounds = path.controlPointRect().adjusted(-extra, -extra, extra, extra);
1274 fillStencilWithVertexArray(stroker.vertices(), stroker.vertexCount() / 2,
1275 0, 0, bounds, QGL2PaintEngineExPrivate::TriStripStrokeFillMode);
1277 glStencilOp(GL_KEEP, GL_REPLACE, GL_REPLACE);
1279 // Pass when any bit is set, replace stencil value with 0
1280 glStencilFunc(GL_NOTEQUAL, 0, GL_STENCIL_HIGH_BIT);
1281 prepareForDraw(false);
1283 // Stencil the brush onto the dest buffer
1288 updateClipScissorTest();
1292 void QGL2PaintEngineEx::penChanged() { }
1293 void QGL2PaintEngineEx::brushChanged() { }
1294 void QGL2PaintEngineEx::brushOriginChanged() { }
1296 void QGL2PaintEngineEx::opacityChanged()
1298 // qDebug("QGL2PaintEngineEx::opacityChanged()");
1299 Q_D(QGL2PaintEngineEx);
1300 state()->opacityChanged = true;
1302 Q_ASSERT(d->shaderManager);
1303 d->brushUniformsDirty = true;
1304 d->opacityUniformDirty = true;
1307 void QGL2PaintEngineEx::compositionModeChanged()
1309 // qDebug("QGL2PaintEngineEx::compositionModeChanged()");
1310 Q_D(QGL2PaintEngineEx);
1311 state()->compositionModeChanged = true;
1312 d->compositionModeDirty = true;
1315 void QGL2PaintEngineEx::renderHintsChanged()
1317 state()->renderHintsChanged = true;
1319 #if !defined(QT_OPENGL_ES_2)
1320 if ((state()->renderHints & QPainter::Antialiasing)
1321 || (state()->renderHints & QPainter::HighQualityAntialiasing))
1322 glEnable(GL_MULTISAMPLE);
1324 glDisable(GL_MULTISAMPLE);
1327 Q_D(QGL2PaintEngineEx);
1328 d->lastTextureUsed = GLuint(-1);
1329 d->brushTextureDirty = true;
1330 // qDebug("QGL2PaintEngineEx::renderHintsChanged() not implemented!");
1333 void QGL2PaintEngineEx::transformChanged()
1335 Q_D(QGL2PaintEngineEx);
1336 d->matrixDirty = true;
1337 state()->matrixChanged = true;
1341 static const QRectF scaleRect(const QRectF &r, qreal sx, qreal sy)
1343 return QRectF(r.x() * sx, r.y() * sy, r.width() * sx, r.height() * sy);
1346 void QGL2PaintEngineEx::drawPixmap(const QRectF& dest, const QPixmap & pixmap, const QRectF & src)
1348 Q_D(QGL2PaintEngineEx);
1349 QGLContext *ctx = d->ctx;
1351 int max_texture_size = ctx->d_func()->maxTextureSize();
1352 if (pixmap.width() > max_texture_size || pixmap.height() > max_texture_size) {
1353 QPixmap scaled = pixmap.scaled(max_texture_size, max_texture_size, Qt::KeepAspectRatio);
1355 const qreal sx = scaled.width() / qreal(pixmap.width());
1356 const qreal sy = scaled.height() / qreal(pixmap.height());
1358 drawPixmap(dest, scaled, scaleRect(src, sx, sy));
1363 d->transferMode(ImageDrawingMode);
1365 QGLContext::BindOptions bindOptions = QGLContext::InternalBindOption|QGLContext::CanFlipNativePixmapBindOption;
1366 #ifdef QGL_USE_TEXTURE_POOL
1367 bindOptions |= QGLContext::TemporarilyCachedBindOption;
1370 glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT);
1371 QGLTexture *texture =
1372 ctx->d_func()->bindTexture(pixmap, GL_TEXTURE_2D, GL_RGBA, bindOptions);
1374 GLfloat top = texture->options & QGLContext::InvertedYBindOption ? (pixmap.height() - src.top()) : src.top();
1375 GLfloat bottom = texture->options & QGLContext::InvertedYBindOption ? (pixmap.height() - src.bottom()) : src.bottom();
1376 QGLRect srcRect(src.left(), top, src.right(), bottom);
1378 bool isBitmap = pixmap.isQBitmap();
1379 bool isOpaque = !isBitmap && !pixmap.hasAlpha();
1381 d->updateTextureFilter(GL_TEXTURE_2D, GL_CLAMP_TO_EDGE,
1382 state()->renderHints & QPainter::SmoothPixmapTransform, texture->id);
1383 d->drawTexture(dest, srcRect, pixmap.size(), isOpaque, isBitmap);
1385 if (texture->options&QGLContext::TemporarilyCachedBindOption) {
1386 // pixmap was temporarily cached as a QImage texture by pooling system
1387 // and should be destroyed immediately
1388 QGLTextureCache::instance()->remove(ctx, texture->id);
1392 void QGL2PaintEngineEx::drawImage(const QRectF& dest, const QImage& image, const QRectF& src,
1393 Qt::ImageConversionFlags)
1395 Q_D(QGL2PaintEngineEx);
1396 QGLContext *ctx = d->ctx;
1398 int max_texture_size = ctx->d_func()->maxTextureSize();
1399 if (image.width() > max_texture_size || image.height() > max_texture_size) {
1400 QImage scaled = image.scaled(max_texture_size, max_texture_size, Qt::KeepAspectRatio);
1402 const qreal sx = scaled.width() / qreal(image.width());
1403 const qreal sy = scaled.height() / qreal(image.height());
1405 drawImage(dest, scaled, scaleRect(src, sx, sy));
1410 d->transferMode(ImageDrawingMode);
1412 glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT);
1414 QGLContext::BindOptions bindOptions = QGLContext::InternalBindOption;
1415 #ifdef QGL_USE_TEXTURE_POOL
1416 bindOptions |= QGLContext::TemporarilyCachedBindOption;
1419 QGLTexture *texture = ctx->d_func()->bindTexture(image, GL_TEXTURE_2D, GL_RGBA, bindOptions);
1420 GLuint id = texture->id;
1422 d->updateTextureFilter(GL_TEXTURE_2D, GL_CLAMP_TO_EDGE,
1423 state()->renderHints & QPainter::SmoothPixmapTransform, id);
1424 d->drawTexture(dest, src, image.size(), !image.hasAlphaChannel());
1426 if (texture->options&QGLContext::TemporarilyCachedBindOption) {
1427 // image was temporarily cached by texture pooling system
1428 // and should be destroyed immediately
1429 QGLTextureCache::instance()->remove(ctx, texture->id);
1433 void QGL2PaintEngineEx::drawStaticTextItem(QStaticTextItem *textItem)
1435 Q_D(QGL2PaintEngineEx);
1439 QPainterState *s = state();
1440 float det = s->matrix.determinant();
1442 // don't try to cache huge fonts or vastly transformed fonts
1443 QFontEngine *fontEngine = textItem->fontEngine();
1444 const qreal pixelSize = fontEngine->fontDef.pixelSize;
1445 if (pixelSize * pixelSize * qAbs(det) < QT_MAX_CACHED_GLYPH_SIZE * QT_MAX_CACHED_GLYPH_SIZE ||
1446 det < 0.25f || det > 4.f) {
1447 QFontEngineGlyphCache::Type glyphType = fontEngine->glyphFormat >= 0
1448 ? QFontEngineGlyphCache::Type(textItem->fontEngine()->glyphFormat)
1449 : d->glyphCacheType;
1450 if (glyphType == QFontEngineGlyphCache::Raster_RGBMask) {
1451 if (d->device->alphaRequested() || s->matrix.type() > QTransform::TxTranslate
1452 || (s->composition_mode != QPainter::CompositionMode_Source
1453 && s->composition_mode != QPainter::CompositionMode_SourceOver))
1455 glyphType = QFontEngineGlyphCache::Raster_A8;
1459 d->drawCachedGlyphs(glyphType, textItem);
1461 QPaintEngineEx::drawStaticTextItem(textItem);
1465 bool QGL2PaintEngineEx::drawTexture(const QRectF &dest, GLuint textureId, const QSize &size, const QRectF &src)
1467 Q_D(QGL2PaintEngineEx);
1468 if (!d->shaderManager)
1472 d->transferMode(ImageDrawingMode);
1474 #ifndef QT_OPENGL_ES_2
1475 QGLContext *ctx = d->ctx;
1477 glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT);
1478 glBindTexture(GL_TEXTURE_2D, textureId);
1480 QGLRect srcRect(src.left(), src.bottom(), src.right(), src.top());
1482 d->updateTextureFilter(GL_TEXTURE_2D, GL_CLAMP_TO_EDGE,
1483 state()->renderHints & QPainter::SmoothPixmapTransform, textureId);
1484 d->drawTexture(dest, srcRect, size, false);
1488 void QGL2PaintEngineEx::drawTextItem(const QPointF &p, const QTextItem &textItem)
1490 Q_D(QGL2PaintEngineEx);
1493 QOpenGL2PaintEngineState *s = state();
1495 const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem);
1497 QTransform::TransformationType txtype = s->matrix.type();
1499 float det = s->matrix.determinant();
1500 bool drawCached = txtype < QTransform::TxProject;
1502 // don't try to cache huge fonts or vastly transformed fonts
1503 const qreal pixelSize = ti.fontEngine->fontDef.pixelSize;
1504 if (pixelSize * pixelSize * qAbs(det) >= QT_MAX_CACHED_GLYPH_SIZE * QT_MAX_CACHED_GLYPH_SIZE ||
1505 det < 0.25f || det > 4.f)
1508 QFontEngineGlyphCache::Type glyphType = ti.fontEngine->glyphFormat >= 0
1509 ? QFontEngineGlyphCache::Type(ti.fontEngine->glyphFormat)
1510 : d->glyphCacheType;
1513 if (glyphType == QFontEngineGlyphCache::Raster_RGBMask) {
1514 if (d->device->alphaRequested() || txtype > QTransform::TxTranslate
1515 || (state()->composition_mode != QPainter::CompositionMode_Source
1516 && state()->composition_mode != QPainter::CompositionMode_SourceOver))
1518 glyphType = QFontEngineGlyphCache::Raster_A8;
1523 QVarLengthArray<QFixedPoint> positions;
1524 QVarLengthArray<glyph_t> glyphs;
1525 QTransform matrix = QTransform::fromTranslate(p.x(), p.y());
1526 ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions);
1529 QStaticTextItem staticTextItem;
1530 staticTextItem.chars = const_cast<QChar *>(ti.chars);
1531 staticTextItem.setFontEngine(ti.fontEngine);
1532 staticTextItem.glyphs = glyphs.data();
1533 staticTextItem.numChars = ti.num_chars;
1534 staticTextItem.numGlyphs = glyphs.size();
1535 staticTextItem.glyphPositions = positions.data();
1537 d->drawCachedGlyphs(glyphType, &staticTextItem);
1542 QPaintEngineEx::drawTextItem(p, ti);
1547 class QOpenGLStaticTextUserData: public QStaticTextUserData
1550 QOpenGLStaticTextUserData()
1551 : QStaticTextUserData(OpenGLUserData), cacheSize(0, 0), cacheSerialNumber(0)
1555 ~QOpenGLStaticTextUserData()
1560 QGL2PEXVertexArray vertexCoordinateArray;
1561 QGL2PEXVertexArray textureCoordinateArray;
1562 QFontEngineGlyphCache::Type glyphType;
1563 int cacheSerialNumber;
1568 #if defined(Q_WS_WIN)
1569 static bool fontSmoothingApproximately(qreal target)
1571 extern Q_GUI_EXPORT qreal qt_fontsmoothing_gamma; // qapplication_win.cpp
1572 return (qAbs(qt_fontsmoothing_gamma - target) < 0.2);
1576 // #define QT_OPENGL_DRAWCACHEDGLYPHS_INDEX_ARRAY_VBO
1578 void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyphType,
1579 QStaticTextItem *staticTextItem)
1581 Q_Q(QGL2PaintEngineEx);
1583 QOpenGL2PaintEngineState *s = q->state();
1585 void *cacheKey = const_cast<QGLContext *>(QGLContextPrivate::contextGroup(ctx)->context());
1586 bool recreateVertexArrays = false;
1588 QGLTextureGlyphCache *cache =
1589 (QGLTextureGlyphCache *) staticTextItem->fontEngine()->glyphCache(cacheKey, glyphType, QTransform());
1590 if (!cache || cache->cacheType() != glyphType || cache->context() == 0) {
1591 cache = new QGLTextureGlyphCache(ctx, glyphType, QTransform());
1592 staticTextItem->fontEngine()->setGlyphCache(cacheKey, cache);
1593 cache->insert(ctx, cache);
1594 recreateVertexArrays = true;
1597 if (staticTextItem->userDataNeedsUpdate) {
1598 recreateVertexArrays = true;
1599 } else if (staticTextItem->userData() == 0) {
1600 recreateVertexArrays = true;
1601 } else if (staticTextItem->userData()->type != QStaticTextUserData::OpenGLUserData) {
1602 recreateVertexArrays = true;
1604 QOpenGLStaticTextUserData *userData = static_cast<QOpenGLStaticTextUserData *>(staticTextItem->userData());
1605 if (userData->glyphType != glyphType) {
1606 recreateVertexArrays = true;
1607 } else if (userData->cacheSerialNumber != cache->serialNumber()) {
1608 recreateVertexArrays = true;
1612 // We only need to update the cache with new glyphs if we are actually going to recreate the vertex arrays.
1613 // If the cache size has changed, we do need to regenerate the vertices, but we don't need to repopulate the
1614 // cache so this text is performed before we test if the cache size has changed.
1615 if (recreateVertexArrays) {
1616 cache->setPaintEnginePrivate(this);
1617 if (!cache->populate(staticTextItem->fontEngine(), staticTextItem->numGlyphs,
1618 staticTextItem->glyphs, staticTextItem->glyphPositions)) {
1619 // No space for glyphs in cache. We need to reset it and try again.
1621 cache->populate(staticTextItem->fontEngine(), staticTextItem->numGlyphs,
1622 staticTextItem->glyphs, staticTextItem->glyphPositions);
1624 cache->fillInPendingGlyphs();
1627 if (cache->width() == 0 || cache->height() == 0)
1630 transferMode(TextDrawingMode);
1632 int margin = cache->glyphMargin();
1634 GLfloat dx = 1.0 / cache->width();
1635 GLfloat dy = 1.0 / cache->height();
1637 // Use global arrays by default
1638 QGL2PEXVertexArray *vertexCoordinates = &vertexCoordinateArray;
1639 QGL2PEXVertexArray *textureCoordinates = &textureCoordinateArray;
1641 if (staticTextItem->useBackendOptimizations) {
1642 QOpenGLStaticTextUserData *userData = 0;
1644 if (staticTextItem->userData() == 0
1645 || staticTextItem->userData()->type != QStaticTextUserData::OpenGLUserData) {
1647 userData = new QOpenGLStaticTextUserData();
1648 staticTextItem->setUserData(userData);
1651 userData = static_cast<QOpenGLStaticTextUserData*>(staticTextItem->userData());
1654 userData->glyphType = glyphType;
1655 userData->cacheSerialNumber = cache->serialNumber();
1657 // Use cache if backend optimizations is turned on
1658 vertexCoordinates = &userData->vertexCoordinateArray;
1659 textureCoordinates = &userData->textureCoordinateArray;
1661 QSize size(cache->width(), cache->height());
1662 if (userData->cacheSize != size) {
1663 recreateVertexArrays = true;
1664 userData->cacheSize = size;
1668 if (recreateVertexArrays) {
1669 vertexCoordinates->clear();
1670 textureCoordinates->clear();
1672 bool supportsSubPixelPositions = staticTextItem->fontEngine()->supportsSubPixelPositions();
1673 for (int i=0; i<staticTextItem->numGlyphs; ++i) {
1674 QFixed subPixelPosition;
1675 if (supportsSubPixelPositions)
1676 subPixelPosition = cache->subPixelPositionForX(staticTextItem->glyphPositions[i].x);
1678 QTextureGlyphCache::GlyphAndSubPixelPosition glyph(staticTextItem->glyphs[i], subPixelPosition);
1680 const QTextureGlyphCache::Coord &c = cache->coords[glyph];
1684 int x = qFloor(staticTextItem->glyphPositions[i].x) + c.baseLineX - margin;
1685 int y = qFloor(staticTextItem->glyphPositions[i].y) - c.baseLineY - margin;
1687 vertexCoordinates->addQuad(QRectF(x, y, c.w, c.h));
1688 textureCoordinates->addQuad(QRectF(c.x*dx, c.y*dy, c.w * dx, c.h * dy));
1691 staticTextItem->userDataNeedsUpdate = false;
1694 int numGlyphs = vertexCoordinates->vertexCount() / 4;
1696 if (elementIndices.size() < numGlyphs*6) {
1697 Q_ASSERT(elementIndices.size() % 6 == 0);
1698 int j = elementIndices.size() / 6 * 4;
1699 while (j < numGlyphs*4) {
1700 elementIndices.append(j + 0);
1701 elementIndices.append(j + 0);
1702 elementIndices.append(j + 1);
1703 elementIndices.append(j + 2);
1704 elementIndices.append(j + 3);
1705 elementIndices.append(j + 3);
1710 #if defined(QT_OPENGL_DRAWCACHEDGLYPHS_INDEX_ARRAY_VBO)
1711 if (elementIndicesVBOId == 0)
1712 glGenBuffers(1, &elementIndicesVBOId);
1714 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementIndicesVBOId);
1715 glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementIndices.size() * sizeof(GLushort),
1716 elementIndices.constData(), GL_STATIC_DRAW);
1719 #if defined(QT_OPENGL_DRAWCACHEDGLYPHS_INDEX_ARRAY_VBO)
1720 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementIndicesVBOId);
1724 setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, (GLfloat*)vertexCoordinates->data());
1725 setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, (GLfloat*)textureCoordinates->data());
1727 if (!snapToPixelGrid) {
1728 snapToPixelGrid = true;
1732 QBrush pensBrush = q->state()->pen.brush();
1733 setBrush(pensBrush);
1735 if (glyphType == QFontEngineGlyphCache::Raster_RGBMask) {
1737 // Subpixel antialiasing without gamma correction
1739 QPainter::CompositionMode compMode = q->state()->composition_mode;
1740 Q_ASSERT(compMode == QPainter::CompositionMode_Source
1741 || compMode == QPainter::CompositionMode_SourceOver);
1743 shaderManager->setMaskType(QGLEngineShaderManager::SubPixelMaskPass1);
1745 if (pensBrush.style() == Qt::SolidPattern) {
1746 // Solid patterns can get away with only one pass.
1747 QColor c = pensBrush.color();
1748 qreal oldOpacity = q->state()->opacity;
1749 if (compMode == QPainter::CompositionMode_Source) {
1750 c = qt_premultiplyColor(c, q->state()->opacity);
1751 q->state()->opacity = 1;
1752 opacityUniformDirty = true;
1755 compositionModeDirty = false; // I can handle this myself, thank you very much
1756 prepareForDraw(false); // Text always causes src pixels to be transparent
1758 // prepareForDraw() have set the opacity on the current shader, so the opacity state can now be reset.
1759 if (compMode == QPainter::CompositionMode_Source) {
1760 q->state()->opacity = oldOpacity;
1761 opacityUniformDirty = true;
1765 glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_SRC_COLOR);
1766 glBlendColor(c.redF(), c.greenF(), c.blueF(), c.alphaF());
1768 // Other brush styles need two passes.
1770 qreal oldOpacity = q->state()->opacity;
1771 if (compMode == QPainter::CompositionMode_Source) {
1772 q->state()->opacity = 1;
1773 opacityUniformDirty = true;
1774 pensBrush = Qt::white;
1775 setBrush(pensBrush);
1778 compositionModeDirty = false; // I can handle this myself, thank you very much
1779 prepareForDraw(false); // Text always causes src pixels to be transparent
1781 glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR);
1783 glActiveTexture(GL_TEXTURE0 + QT_MASK_TEXTURE_UNIT);
1784 glBindTexture(GL_TEXTURE_2D, cache->texture());
1785 updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, false);
1787 #if defined(QT_OPENGL_DRAWCACHEDGLYPHS_INDEX_ARRAY_VBO)
1788 glDrawElements(GL_TRIANGLE_STRIP, 6 * numGlyphs, GL_UNSIGNED_SHORT, 0);
1790 glDrawElements(GL_TRIANGLE_STRIP, 6 * numGlyphs, GL_UNSIGNED_SHORT, elementIndices.data());
1793 shaderManager->setMaskType(QGLEngineShaderManager::SubPixelMaskPass2);
1795 if (compMode == QPainter::CompositionMode_Source) {
1796 q->state()->opacity = oldOpacity;
1797 opacityUniformDirty = true;
1798 pensBrush = q->state()->pen.brush();
1799 setBrush(pensBrush);
1802 compositionModeDirty = false;
1803 prepareForDraw(false); // Text always causes src pixels to be transparent
1805 glBlendFunc(GL_ONE, GL_ONE);
1807 compositionModeDirty = true;
1809 // Greyscale/mono glyphs
1811 shaderManager->setMaskType(QGLEngineShaderManager::PixelMask);
1812 prepareForDraw(false); // Text always causes src pixels to be transparent
1815 QGLTextureGlyphCache::FilterMode filterMode = (s->matrix.type() > QTransform::TxTranslate)?QGLTextureGlyphCache::Linear:QGLTextureGlyphCache::Nearest;
1816 if (lastMaskTextureUsed != cache->texture() || cache->filterMode() != filterMode) {
1818 glActiveTexture(GL_TEXTURE0 + QT_MASK_TEXTURE_UNIT);
1819 if (lastMaskTextureUsed != cache->texture()) {
1820 glBindTexture(GL_TEXTURE_2D, cache->texture());
1821 lastMaskTextureUsed = cache->texture();
1824 if (cache->filterMode() != filterMode) {
1825 if (filterMode == QGLTextureGlyphCache::Linear) {
1826 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1827 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1829 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1830 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1832 cache->setFilterMode(filterMode);
1836 bool srgbFrameBufferEnabled = false;
1837 if (ctx->d_ptr->extension_flags & QGLExtensions::SRGBFrameBuffer) {
1838 #if defined(Q_WS_MAC)
1839 if (glyphType == QFontEngineGlyphCache::Raster_RGBMask)
1840 #elif defined(Q_WS_WIN)
1841 if (glyphType != QFontEngineGlyphCache::Raster_RGBMask || fontSmoothingApproximately(2.1))
1846 glEnable(FRAMEBUFFER_SRGB_EXT);
1847 srgbFrameBufferEnabled = true;
1851 #if defined(QT_OPENGL_DRAWCACHEDGLYPHS_INDEX_ARRAY_VBO)
1852 glDrawElements(GL_TRIANGLE_STRIP, 6 * numGlyphs, GL_UNSIGNED_SHORT, 0);
1853 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
1855 glDrawElements(GL_TRIANGLE_STRIP, 6 * numGlyphs, GL_UNSIGNED_SHORT, elementIndices.data());
1858 if (srgbFrameBufferEnabled)
1859 glDisable(FRAMEBUFFER_SRGB_EXT);
1863 void QGL2PaintEngineEx::drawPixmapFragments(const QPainter::PixmapFragment *fragments, int fragmentCount, const QPixmap &pixmap,
1864 QPainter::PixmapFragmentHints hints)
1866 Q_D(QGL2PaintEngineEx);
1867 // Use fallback for extended composition modes.
1868 if (state()->composition_mode > QPainter::CompositionMode_Plus) {
1869 QPaintEngineEx::drawPixmapFragments(fragments, fragmentCount, pixmap, hints);
1874 int max_texture_size = d->ctx->d_func()->maxTextureSize();
1875 if (pixmap.width() > max_texture_size || pixmap.height() > max_texture_size) {
1876 QPixmap scaled = pixmap.scaled(max_texture_size, max_texture_size, Qt::KeepAspectRatio);
1877 d->drawPixmapFragments(fragments, fragmentCount, scaled, hints);
1879 d->drawPixmapFragments(fragments, fragmentCount, pixmap, hints);
1884 void QGL2PaintEngineExPrivate::drawPixmapFragments(const QPainter::PixmapFragment *fragments,
1885 int fragmentCount, const QPixmap &pixmap,
1886 QPainter::PixmapFragmentHints hints)
1888 GLfloat dx = 1.0f / pixmap.size().width();
1889 GLfloat dy = 1.0f / pixmap.size().height();
1891 vertexCoordinateArray.clear();
1892 textureCoordinateArray.clear();
1893 opacityArray.reset();
1895 if (snapToPixelGrid) {
1896 snapToPixelGrid = false;
1900 bool allOpaque = true;
1902 for (int i = 0; i < fragmentCount; ++i) {
1905 if (fragments[i].rotation != 0) {
1906 s = qFastSin(fragments[i].rotation * Q_PI / 180);
1907 c = qFastCos(fragments[i].rotation * Q_PI / 180);
1910 qreal right = 0.5 * fragments[i].scaleX * fragments[i].width;
1911 qreal bottom = 0.5 * fragments[i].scaleY * fragments[i].height;
1912 QGLPoint bottomRight(right * c - bottom * s, right * s + bottom * c);
1913 QGLPoint bottomLeft(-right * c - bottom * s, -right * s + bottom * c);
1915 vertexCoordinateArray.addVertex(bottomRight.x + fragments[i].x, bottomRight.y + fragments[i].y);
1916 vertexCoordinateArray.addVertex(-bottomLeft.x + fragments[i].x, -bottomLeft.y + fragments[i].y);
1917 vertexCoordinateArray.addVertex(-bottomRight.x + fragments[i].x, -bottomRight.y + fragments[i].y);
1918 vertexCoordinateArray.addVertex(-bottomRight.x + fragments[i].x, -bottomRight.y + fragments[i].y);
1919 vertexCoordinateArray.addVertex(bottomLeft.x + fragments[i].x, bottomLeft.y + fragments[i].y);
1920 vertexCoordinateArray.addVertex(bottomRight.x + fragments[i].x, bottomRight.y + fragments[i].y);
1922 QGLRect src(fragments[i].sourceLeft * dx, fragments[i].sourceTop * dy,
1923 (fragments[i].sourceLeft + fragments[i].width) * dx,
1924 (fragments[i].sourceTop + fragments[i].height) * dy);
1926 textureCoordinateArray.addVertex(src.right, src.bottom);
1927 textureCoordinateArray.addVertex(src.right, src.top);
1928 textureCoordinateArray.addVertex(src.left, src.top);
1929 textureCoordinateArray.addVertex(src.left, src.top);
1930 textureCoordinateArray.addVertex(src.left, src.bottom);
1931 textureCoordinateArray.addVertex(src.right, src.bottom);
1933 qreal opacity = fragments[i].opacity * q->state()->opacity;
1934 opacityArray << opacity << opacity << opacity << opacity << opacity << opacity;
1935 allOpaque &= (opacity >= 0.99f);
1938 glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT);
1939 QGLTexture *texture = ctx->d_func()->bindTexture(pixmap, GL_TEXTURE_2D, GL_RGBA,
1940 QGLContext::InternalBindOption
1941 | QGLContext::CanFlipNativePixmapBindOption);
1943 if (texture->options & QGLContext::InvertedYBindOption) {
1944 // Flip texture y-coordinate.
1945 QGLPoint *data = textureCoordinateArray.data();
1946 for (int i = 0; i < 6 * fragmentCount; ++i)
1947 data[i].y = 1 - data[i].y;
1950 transferMode(ImageArrayDrawingMode);
1952 bool isBitmap = pixmap.isQBitmap();
1953 bool isOpaque = !isBitmap && (!pixmap.hasAlpha() || (hints & QPainter::OpaqueHint)) && allOpaque;
1955 updateTextureFilter(GL_TEXTURE_2D, GL_CLAMP_TO_EDGE,
1956 q->state()->renderHints & QPainter::SmoothPixmapTransform, texture->id);
1958 // Setup for texture drawing
1959 currentBrush = noBrush;
1960 shaderManager->setSrcPixelType(isBitmap ? QGLEngineShaderManager::PatternSrc
1961 : QGLEngineShaderManager::ImageSrc);
1962 if (prepareForDraw(isOpaque))
1963 shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::ImageTexture), QT_IMAGE_TEXTURE_UNIT);
1966 QColor col = qt_premultiplyColor(q->state()->pen.color(), (GLfloat)q->state()->opacity);
1967 shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::PatternColor), col);
1970 glDrawArrays(GL_TRIANGLES, 0, 6 * fragmentCount);
1973 bool QGL2PaintEngineEx::begin(QPaintDevice *pdev)
1975 Q_D(QGL2PaintEngineEx);
1977 // qDebug("QGL2PaintEngineEx::begin()");
1978 if (pdev->devType() == QInternal::OpenGL)
1979 d->device = static_cast<QGLPaintDevice*>(pdev);
1981 d->device = QGLPaintDevice::getDevice(pdev);
1986 d->ctx = d->device->context();
1987 d->ctx->d_ptr->active_engine = this;
1989 const QSize sz = d->device->size();
1990 d->width = sz.width();
1991 d->height = sz.height();
1992 d->mode = BrushDrawingMode;
1993 d->brushTextureDirty = true;
1994 d->brushUniformsDirty = true;
1995 d->matrixUniformDirty = true;
1996 d->matrixDirty = true;
1997 d->compositionModeDirty = true;
1998 d->opacityUniformDirty = true;
1999 d->needsSync = true;
2000 d->useSystemClip = !systemClip().isEmpty();
2001 d->currentBrush = QBrush();
2003 d->dirtyStencilRegion = QRect(0, 0, d->width, d->height);
2004 d->stencilClean = true;
2006 // Calling begin paint should make the correct context current. So, any
2007 // code which calls into GL or otherwise needs a current context *must*
2008 // go after beginPaint:
2009 d->device->beginPaint();
2011 #if !defined(QT_OPENGL_ES_2)
2012 bool success = qt_resolve_version_2_0_functions(d->ctx)
2013 && qt_resolve_buffer_extensions(d->ctx);
2018 d->shaderManager = new QGLEngineShaderManager(d->ctx);
2020 glDisable(GL_STENCIL_TEST);
2021 glDisable(GL_DEPTH_TEST);
2022 glDisable(GL_SCISSOR_TEST);
2024 #if !defined(QT_OPENGL_ES_2)
2025 glDisable(GL_MULTISAMPLE);
2028 d->glyphCacheType = QFontEngineGlyphCache::Raster_A8;
2030 #if !defined(QT_OPENGL_ES_2)
2031 #if defined(Q_WS_WIN)
2032 if (qt_cleartype_enabled
2033 && (fontSmoothingApproximately(1.0) || fontSmoothingApproximately(2.1)))
2035 #if defined(Q_WS_MAC)
2036 if (qt_applefontsmoothing_enabled)
2038 d->glyphCacheType = QFontEngineGlyphCache::Raster_RGBMask;
2041 #if defined(QT_OPENGL_ES_2)
2042 // OpenGL ES can't switch MSAA off, so if the gl paint device is
2043 // multisampled, it's always multisampled.
2044 d->multisamplingAlwaysEnabled = d->device->format().sampleBuffers();
2046 d->multisamplingAlwaysEnabled = false;
2052 bool QGL2PaintEngineEx::end()
2054 Q_D(QGL2PaintEngineEx);
2055 QGLContext *ctx = d->ctx;
2058 d->transferMode(BrushDrawingMode);
2059 d->device->endPaint();
2061 #if defined(Q_WS_X11)
2062 // On some (probably all) drivers, deleting an X pixmap which has been bound to a texture
2063 // before calling glFinish/swapBuffers renders garbage. Presumably this is because X deletes
2064 // the pixmap behind the driver's back before it's had a chance to use it. To fix this, we
2065 // reference all QPixmaps which have been bound to stop them being deleted and only deref
2066 // them here, after swapBuffers, where they can be safely deleted.
2067 ctx->d_func()->boundPixmaps.clear();
2069 d->ctx->d_ptr->active_engine = 0;
2073 delete d->shaderManager;
2074 d->shaderManager = 0;
2075 d->currentBrush = QBrush();
2077 #ifdef QT_OPENGL_CACHE_AS_VBOS
2078 if (!d->unusedVBOSToClean.isEmpty()) {
2079 glDeleteBuffers(d->unusedVBOSToClean.size(), d->unusedVBOSToClean.constData());
2080 d->unusedVBOSToClean.clear();
2082 if (!d->unusedIBOSToClean.isEmpty()) {
2083 glDeleteBuffers(d->unusedIBOSToClean.size(), d->unusedIBOSToClean.constData());
2084 d->unusedIBOSToClean.clear();
2091 void QGL2PaintEngineEx::ensureActive()
2093 Q_D(QGL2PaintEngineEx);
2094 QGLContext *ctx = d->ctx;
2096 if (isActive() && ctx->d_ptr->active_engine != this) {
2097 ctx->d_ptr->active_engine = this;
2098 d->needsSync = true;
2101 d->device->ensureActiveTarget();
2104 d->transferMode(BrushDrawingMode);
2105 glViewport(0, 0, d->width, d->height);
2106 d->needsSync = false;
2107 d->lastMaskTextureUsed = 0;
2108 d->shaderManager->setDirty();
2109 d->ctx->d_func()->syncGlState();
2110 for (int i = 0; i < 3; ++i)
2111 d->vertexAttribPointers[i] = (GLfloat*)-1; // Assume the pointers are clobbered
2116 void QGL2PaintEngineExPrivate::updateClipScissorTest()
2118 Q_Q(QGL2PaintEngineEx);
2119 if (q->state()->clipTestEnabled) {
2120 glEnable(GL_STENCIL_TEST);
2121 glStencilFunc(GL_LEQUAL, q->state()->currentClip, ~GL_STENCIL_HIGH_BIT);
2123 glDisable(GL_STENCIL_TEST);
2124 glStencilFunc(GL_ALWAYS, 0, 0xff);
2127 #ifdef QT_GL_NO_SCISSOR_TEST
2128 currentScissorBounds = QRect(0, 0, width, height);
2130 QRect bounds = q->state()->rectangleClip;
2131 if (!q->state()->clipEnabled) {
2133 bounds = systemClip.boundingRect();
2135 bounds = QRect(0, 0, width, height);
2138 bounds = bounds.intersected(systemClip.boundingRect());
2140 bounds = bounds.intersected(QRect(0, 0, width, height));
2143 currentScissorBounds = bounds;
2145 if (bounds == QRect(0, 0, width, height)) {
2146 glDisable(GL_SCISSOR_TEST);
2148 glEnable(GL_SCISSOR_TEST);
2154 void QGL2PaintEngineExPrivate::setScissor(const QRect &rect)
2156 const int left = rect.left();
2157 const int width = rect.width();
2158 int bottom = height - (rect.top() + rect.height());
2159 if (device->isFlipped()) {
2160 bottom = rect.top();
2162 const int height = rect.height();
2164 glScissor(left, bottom, width, height);
2167 void QGL2PaintEngineEx::clipEnabledChanged()
2169 Q_D(QGL2PaintEngineEx);
2171 state()->clipChanged = true;
2173 if (painter()->hasClipping())
2174 d->regenerateClip();
2176 d->systemStateChanged();
2179 void QGL2PaintEngineExPrivate::clearClip(uint value)
2181 dirtyStencilRegion -= currentScissorBounds;
2183 glStencilMask(0xff);
2184 glClearStencil(value);
2185 glClear(GL_STENCIL_BUFFER_BIT);
2188 q->state()->needsClipBufferClear = false;
2191 void QGL2PaintEngineExPrivate::writeClip(const QVectorPath &path, uint value)
2193 transferMode(BrushDrawingMode);
2195 if (snapToPixelGrid) {
2196 snapToPixelGrid = false;
2203 stencilClean = false;
2205 const bool singlePass = !path.hasWindingFill()
2206 && (((q->state()->currentClip == maxClip - 1) && q->state()->clipTestEnabled)
2207 || q->state()->needsClipBufferClear);
2208 const uint referenceClipValue = q->state()->needsClipBufferClear ? 1 : q->state()->currentClip;
2210 if (q->state()->needsClipBufferClear)
2213 if (path.isEmpty()) {
2214 glEnable(GL_STENCIL_TEST);
2215 glStencilFunc(GL_LEQUAL, value, ~GL_STENCIL_HIGH_BIT);
2219 if (q->state()->clipTestEnabled)
2220 glStencilFunc(GL_LEQUAL, q->state()->currentClip, ~GL_STENCIL_HIGH_BIT);
2222 glStencilFunc(GL_ALWAYS, 0, 0xff);
2224 vertexCoordinateArray.clear();
2225 vertexCoordinateArray.addPath(path, inverseScale, false);
2228 fillStencilWithVertexArray(vertexCoordinateArray, path.hasWindingFill());
2230 glColorMask(false, false, false, false);
2231 glEnable(GL_STENCIL_TEST);
2235 // Under these conditions we can set the new stencil value in a single
2236 // pass, by using the current value and the "new value" as the toggles
2238 glStencilFunc(GL_LEQUAL, referenceClipValue, ~GL_STENCIL_HIGH_BIT);
2239 glStencilOp(GL_KEEP, GL_INVERT, GL_INVERT);
2240 glStencilMask(value ^ referenceClipValue);
2242 drawVertexArrays(vertexCoordinateArray, GL_TRIANGLE_FAN);
2244 glStencilOp(GL_KEEP, GL_REPLACE, GL_REPLACE);
2245 glStencilMask(0xff);
2247 if (!q->state()->clipTestEnabled && path.hasWindingFill()) {
2248 // Pass when any clip bit is set, set high bit
2249 glStencilFunc(GL_NOTEQUAL, GL_STENCIL_HIGH_BIT, ~GL_STENCIL_HIGH_BIT);
2250 composite(vertexCoordinateArray.boundingRect());
2253 // Pass when high bit is set, replace stencil value with new clip value
2254 glStencilFunc(GL_NOTEQUAL, value, GL_STENCIL_HIGH_BIT);
2256 composite(vertexCoordinateArray.boundingRect());
2259 glStencilFunc(GL_LEQUAL, value, ~GL_STENCIL_HIGH_BIT);
2262 glColorMask(true, true, true, true);
2265 void QGL2PaintEngineEx::clip(const QVectorPath &path, Qt::ClipOperation op)
2267 // qDebug("QGL2PaintEngineEx::clip()");
2268 Q_D(QGL2PaintEngineEx);
2270 state()->clipChanged = true;
2274 if (op == Qt::ReplaceClip) {
2275 op = Qt::IntersectClip;
2276 if (d->hasClipOperations()) {
2277 d->systemStateChanged();
2278 state()->canRestoreClip = false;
2282 #ifndef QT_GL_NO_SCISSOR_TEST
2283 if (!path.isEmpty() && op == Qt::IntersectClip && (path.shape() == QVectorPath::RectangleHint)) {
2284 const QPointF* const points = reinterpret_cast<const QPointF*>(path.points());
2285 QRectF rect(points[0], points[2]);
2287 if (state()->matrix.type() <= QTransform::TxScale
2288 || (state()->matrix.type() == QTransform::TxRotate
2289 && qFuzzyIsNull(state()->matrix.m11())
2290 && qFuzzyIsNull(state()->matrix.m22())))
2292 state()->rectangleClip = state()->rectangleClip.intersected(state()->matrix.mapRect(rect).toRect());
2293 d->updateClipScissorTest();
2299 const QRect pathRect = state()->matrix.mapRect(path.controlPointRect()).toAlignedRect();
2303 if (d->useSystemClip) {
2304 state()->clipTestEnabled = true;
2305 state()->currentClip = 1;
2307 state()->clipTestEnabled = false;
2309 state()->rectangleClip = QRect(0, 0, d->width, d->height);
2310 state()->canRestoreClip = false;
2311 d->updateClipScissorTest();
2313 case Qt::IntersectClip:
2314 state()->rectangleClip = state()->rectangleClip.intersected(pathRect);
2315 d->updateClipScissorTest();
2316 d->resetClipIfNeeded();
2318 d->writeClip(path, d->maxClip);
2319 state()->currentClip = d->maxClip;
2320 state()->clipTestEnabled = true;
2322 case Qt::UniteClip: {
2323 d->resetClipIfNeeded();
2325 if (state()->rectangleClip.isValid()) {
2327 path.addRect(state()->rectangleClip);
2329 // flush the existing clip rectangle to the depth buffer
2330 d->writeClip(qtVectorPathForPath(state()->matrix.inverted().map(path)), d->maxClip);
2333 state()->clipTestEnabled = false;
2334 #ifndef QT_GL_NO_SCISSOR_TEST
2335 QRect oldRectangleClip = state()->rectangleClip;
2337 state()->rectangleClip = state()->rectangleClip.united(pathRect);
2338 d->updateClipScissorTest();
2340 QRegion extendRegion = QRegion(state()->rectangleClip) - oldRectangleClip;
2342 if (!extendRegion.isEmpty()) {
2343 QPainterPath extendPath;
2344 extendPath.addRegion(extendRegion);
2346 // first clear the depth buffer in the extended region
2347 d->writeClip(qtVectorPathForPath(state()->matrix.inverted().map(extendPath)), 0);
2350 // now write the clip path
2351 d->writeClip(path, d->maxClip);
2352 state()->canRestoreClip = false;
2353 state()->currentClip = d->maxClip;
2354 state()->clipTestEnabled = true;
2362 void QGL2PaintEngineExPrivate::regenerateClip()
2364 systemStateChanged();
2365 replayClipOperations();
2368 void QGL2PaintEngineExPrivate::systemStateChanged()
2370 Q_Q(QGL2PaintEngineEx);
2372 q->state()->clipChanged = true;
2374 if (systemClip.isEmpty()) {
2375 useSystemClip = false;
2377 if (q->paintDevice()->devType() == QInternal::Widget && currentClipDevice) {
2378 QWidgetPrivate *widgetPrivate = qt_widget_private(static_cast<QWidget *>(currentClipDevice)->window());
2379 useSystemClip = widgetPrivate->extra && widgetPrivate->extra->inRenderWithPainter;
2381 useSystemClip = true;
2385 q->state()->clipTestEnabled = false;
2386 q->state()->needsClipBufferClear = true;
2388 q->state()->currentClip = 1;
2391 q->state()->rectangleClip = useSystemClip ? systemClip.boundingRect() : QRect(0, 0, width, height);
2392 updateClipScissorTest();
2394 if (systemClip.rectCount() == 1) {
2395 if (systemClip.boundingRect() == QRect(0, 0, width, height))
2396 useSystemClip = false;
2397 #ifndef QT_GL_NO_SCISSOR_TEST
2398 // scissoring takes care of the system clip
2403 if (useSystemClip) {
2407 path.addRegion(systemClip);
2409 q->state()->currentClip = 0;
2410 writeClip(qtVectorPathForPath(q->state()->matrix.inverted().map(path)), 1);
2411 q->state()->currentClip = 1;
2412 q->state()->clipTestEnabled = true;
2416 void QGL2PaintEngineEx::setState(QPainterState *new_state)
2418 // qDebug("QGL2PaintEngineEx::setState()");
2420 Q_D(QGL2PaintEngineEx);
2422 QOpenGL2PaintEngineState *s = static_cast<QOpenGL2PaintEngineState *>(new_state);
2423 QOpenGL2PaintEngineState *old_state = state();
2425 QPaintEngineEx::setState(s);
2428 // Newly created state object. The call to setState()
2429 // will either be followed by a call to begin(), or we are
2430 // setting the state as part of a save().
2435 // Setting the state as part of a restore().
2437 if (old_state == s || old_state->renderHintsChanged)
2438 renderHintsChanged();
2440 if (old_state == s || old_state->matrixChanged)
2441 d->matrixDirty = true;
2443 if (old_state == s || old_state->compositionModeChanged)
2444 d->compositionModeDirty = true;
2446 if (old_state == s || old_state->opacityChanged)
2447 d->opacityUniformDirty = true;
2449 if (old_state == s || old_state->clipChanged) {
2450 if (old_state && old_state != s && old_state->canRestoreClip) {
2451 d->updateClipScissorTest();
2452 glDepthFunc(GL_LEQUAL);
2454 d->regenerateClip();
2459 QPainterState *QGL2PaintEngineEx::createState(QPainterState *orig) const
2462 const_cast<QGL2PaintEngineEx *>(this)->ensureActive();
2464 QOpenGL2PaintEngineState *s;
2466 s = new QOpenGL2PaintEngineState();
2468 s = new QOpenGL2PaintEngineState(*static_cast<QOpenGL2PaintEngineState *>(orig));
2470 s->matrixChanged = false;
2471 s->compositionModeChanged = false;
2472 s->opacityChanged = false;
2473 s->renderHintsChanged = false;
2474 s->clipChanged = false;
2479 QOpenGL2PaintEngineState::QOpenGL2PaintEngineState(QOpenGL2PaintEngineState &other)
2480 : QPainterState(other)
2483 needsClipBufferClear = other.needsClipBufferClear;
2484 clipTestEnabled = other.clipTestEnabled;
2485 currentClip = other.currentClip;
2486 canRestoreClip = other.canRestoreClip;
2487 rectangleClip = other.rectangleClip;
2490 QOpenGL2PaintEngineState::QOpenGL2PaintEngineState()
2493 needsClipBufferClear = true;
2494 clipTestEnabled = false;
2495 canRestoreClip = true;
2498 QOpenGL2PaintEngineState::~QOpenGL2PaintEngineState()