/**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Qt Software Information (qt-info@nokia.com) ** ** This file is part of the QtOpenGL module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage ** This file contains pre-release code and may not be distributed. ** You may use this file in accordance with the terms and conditions ** contained in the either Technology Preview License Agreement or the ** Beta Release License Agreement. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Nokia gives you certain ** additional rights. These rights are described in the Nokia Qt LGPL ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this ** package. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3.0 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU General Public License version 3.0 requirements will be ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please ** contact the sales department at qt-sales@nokia.com. ** $QT_END_LICENSE$ ** ****************************************************************************/ /* When the active program changes, we need to update it's uniforms. We could track state for each program and only update stale uniforms - Could lead to lots of overhead if there's a lot of programs We could update all the uniforms when the program changes - Could end up updating lots of uniforms which don't need updating Updating uniforms should be cheap, so the overhead of updating up-to-date uniforms should be minimal. It's also less complex. Things which _may_ cause a different program to be used: - Change in brush/pen style - Change in painter opacity - Change in composition mode Whenever we set a mode on the shader manager - it needs to tell us if it had to switch to a different program. The shader manager should only switch when we tell it to. E.g. if we set a new brush style and then switch to transparent painter, we only want it to compile and use the correct program when we really need it. */ #include "qpaintengineex_opengl2_p.h" #include //for memcpy #include #include #include #include #include #include #include #include #include "qglgradientcache_p.h" #include "qglengineshadermanager_p.h" #include "qgl2pexvertexarray_p.h" #include QT_BEGIN_NAMESPACE static const GLuint QT_BRUSH_TEXTURE_UNIT = 0; static const GLuint QT_IMAGE_TEXTURE_UNIT = 0; //Can be the same as brush texture unit static const GLuint QT_MASK_TEXTURE_UNIT = 1; static const GLuint QT_BACKGROUND_TEXTURE_UNIT = 2; class QGLTextureGlyphCache : public QTextureGlyphCache { public: QGLTextureGlyphCache(QGLContext *context, QFontEngineGlyphCache::Type type, const QTransform &matrix); ~QGLTextureGlyphCache(); virtual void createTextureData(int width, int height); virtual void resizeTextureData(int width, int height); virtual void fillTexture(const Coord &c, glyph_t glyph); inline GLuint texture() const { return m_texture; } inline int width() const { return m_width; } inline int height() const { return m_height; } inline void setPaintEnginePrivate(QGL2PaintEngineExPrivate *p) { pex = p; } private: QGLContext *ctx; QGL2PaintEngineExPrivate *pex; GLuint m_texture; GLuint m_fbo; int m_width; int m_height; QGLShaderProgram *m_program; }; QGLTextureGlyphCache::QGLTextureGlyphCache(QGLContext *context, QFontEngineGlyphCache::Type type, const QTransform &matrix) : QTextureGlyphCache(type, matrix) , ctx(context) , m_width(0) , m_height(0) { glGenFramebuffers(1, &m_fbo); } QGLTextureGlyphCache::~QGLTextureGlyphCache() { glDeleteFramebuffers(1, &m_fbo); if (m_width || m_height) glDeleteTextures(1, &m_texture); } void QGLTextureGlyphCache::createTextureData(int width, int height) { glGenTextures(1, &m_texture); glBindTexture(GL_TEXTURE_2D, m_texture); m_width = width; m_height = height; QVarLengthArray data(width * height); for (int i = 0; i < width * height; ++i) data[i] = 0; if (m_type == QFontEngineGlyphCache::Raster_RGBMask) glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, &data[0]); else glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, &data[0]); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } void QGLTextureGlyphCache::resizeTextureData(int width, int height) { // ### the QTextureGlyphCache API needs to be reworked to allow // ### resizeTextureData to fail int oldWidth = m_width; int oldHeight = m_height; GLuint oldTexture = m_texture; createTextureData(width, height); glBindFramebuffer(GL_FRAMEBUFFER_EXT, m_fbo); GLuint colorBuffer; glGenRenderbuffers(1, &colorBuffer); glBindRenderbuffer(GL_RENDERBUFFER_EXT, colorBuffer); glRenderbufferStorage(GL_RENDERBUFFER_EXT, GL_RGBA, oldWidth, oldHeight); glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, colorBuffer); glBindRenderbuffer(GL_RENDERBUFFER_EXT, 0); glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT); glBindTexture(GL_TEXTURE_2D, oldTexture); pex->transferMode(BrushDrawingMode); glDisable(GL_SCISSOR_TEST); glDisable(GL_DEPTH_TEST); glViewport(0, 0, oldWidth, oldHeight); float vertexCoordinateArray[] = { -1, -1, 1, -1, 1, 1, -1, 1 }; float textureCoordinateArray[] = { 0, 0, 1, 0, 1, 1, 0, 1 }; glEnableVertexAttribArray(QT_VERTEX_COORDS_ATTR); glEnableVertexAttribArray(QT_TEXTURE_COORDS_ATTR); glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, vertexCoordinateArray); glVertexAttribPointer(QT_TEXTURE_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, textureCoordinateArray); pex->shaderManager->blitProgram()->enable(); pex->shaderManager->blitProgram()->setUniformValue("imageTexture", QT_IMAGE_TEXTURE_UNIT); pex->shaderManager->setDirty(); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); glDisableVertexAttribArray(QT_VERTEX_COORDS_ATTR); glDisableVertexAttribArray(QT_TEXTURE_COORDS_ATTR); glBindTexture(GL_TEXTURE_2D, m_texture); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, oldWidth, oldHeight); glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, 0); glDeleteRenderbuffers(1, &colorBuffer); glDeleteTextures(1, &oldTexture); glBindFramebuffer(GL_FRAMEBUFFER_EXT, ctx->d_ptr->current_fbo); glViewport(0, 0, pex->width, pex->height); pex->updateDepthClip(); } void QGLTextureGlyphCache::fillTexture(const Coord &c, glyph_t glyph) { QImage mask = textureMapForGlyph(glyph); const uint maskWidth = mask.width(); const uint maskHeight = mask.height(); glBindTexture(GL_TEXTURE_2D, m_texture); if (mask.format() == QImage::Format_RGB32) { glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, m_height - c.y, maskWidth, maskHeight, GL_BGRA, GL_UNSIGNED_BYTE, mask.bits()); } else { mask = mask.convertToFormat(QImage::Format_Indexed8); glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y, maskWidth, maskHeight, GL_ALPHA, GL_UNSIGNED_BYTE, mask.bits()); } } extern QImage qt_imageForBrush(int brushStyle, bool invert); ////////////////////////////////// Private Methods ////////////////////////////////////////// QGL2PaintEngineExPrivate::~QGL2PaintEngineExPrivate() { if (shaderManager) { delete shaderManager; shaderManager = 0; } } void QGL2PaintEngineExPrivate::updateTextureFilter(GLenum target, GLenum wrapMode, bool smoothPixmapTransform) { // glActiveTexture(GL_TEXTURE0 + QT_BRUSH_TEXTURE_UNIT); //### Is it always this texture unit? if (smoothPixmapTransform) { glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } else { glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } glTexParameterf(target, GL_TEXTURE_WRAP_S, wrapMode); glTexParameterf(target, GL_TEXTURE_WRAP_T, wrapMode); } QColor QGL2PaintEngineExPrivate::premultiplyColor(QColor c, GLfloat opacity) { uint alpha = qRound(c.alpha() * opacity); return QColor ( ((c.red() * alpha + 128) >> 8), ((c.green() * alpha + 128) >> 8), ((c.blue() * alpha + 128) >> 8), alpha); } void QGL2PaintEngineExPrivate::setBrush(const QBrush* brush) { currentBrush = brush; brushTextureDirty = true; brushUniformsDirty = true; shaderManager->setSrcPixelType(currentBrush->style()); shaderManager->optimiseForBrushTransform(currentBrush->transform()); } // Unless this gets used elsewhere, it's probably best to merge it into fillStencilWithVertexArray void QGL2PaintEngineExPrivate::useSimpleShader() { shaderManager->simpleProgram()->enable(); shaderManager->setDirty(); if (matrixDirty) updateMatrix(); if (simpleShaderMatrixUniformDirty) { shaderManager->simpleProgram()->setUniformValue("pmvMatrix", pmvMatrix); simpleShaderMatrixUniformDirty = false; } } Q_GLOBAL_STATIC(QGL2GradientCache, qt_opengl_gradient_cache) void QGL2PaintEngineExPrivate::updateBrushTexture() { // qDebug("QGL2PaintEngineExPrivate::updateBrushTexture()"); Qt::BrushStyle style = currentBrush->style(); if ( (style >= Qt::Dense1Pattern) && (style <= Qt::DiagCrossPattern) ) { // Get the image data for the pattern QImage texImage = qt_imageForBrush(style, true); glActiveTexture(GL_TEXTURE0 + QT_BRUSH_TEXTURE_UNIT); ctx->d_func()->bindTexture(texImage, GL_TEXTURE_2D, GL_RGBA, true); updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, true); } else if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern) { // Gradiant brush: All the gradiants use the same texture const QGradient* g = currentBrush->gradient(); // We apply global opacity in the fragment shaders, so we always pass 1.0 // for opacity to the cache. GLuint texId = qt_opengl_gradient_cache()->getBuffer(*g, 1.0, ctx); if (g->spread() == QGradient::RepeatSpread || g->type() == QGradient::ConicalGradient) updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, true); else if (g->spread() == QGradient::ReflectSpread) updateTextureFilter(GL_TEXTURE_2D, GL_MIRRORED_REPEAT_IBM, true); else updateTextureFilter(GL_TEXTURE_2D, GL_CLAMP_TO_EDGE, true); glActiveTexture(GL_TEXTURE0 + QT_BRUSH_TEXTURE_UNIT); glBindTexture(GL_TEXTURE_2D, texId); } else if (style == Qt::TexturePattern) { const QPixmap& texPixmap = currentBrush->texture(); glActiveTexture(GL_TEXTURE0 + QT_BRUSH_TEXTURE_UNIT); ctx->d_func()->bindTexture(texPixmap, GL_TEXTURE_2D, GL_RGBA, true); updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, true); } brushTextureDirty = false; } void QGL2PaintEngineExPrivate::updateBrushUniforms() { // qDebug("QGL2PaintEngineExPrivate::updateBrushUniforms()"); Qt::BrushStyle style = currentBrush->style(); if (style == Qt::NoBrush) return; QTransform brushQTransform = currentBrush->transform(); if (style == Qt::SolidPattern) { QColor col = premultiplyColor(currentBrush->color(), (GLfloat)q->state()->opacity); shaderManager->currentProgram()->setUniformValue("fragmentColor", col); } else { // All other brushes have a transform and thus need the translation point: QPointF translationPoint; if (style <= Qt::DiagCrossPattern) { translationPoint = q->state()->brushOrigin; QColor col = premultiplyColor(currentBrush->color(), (GLfloat)q->state()->opacity); shaderManager->currentProgram()->setUniformValue("patternColor", col); QVector2D halfViewportSize(width*0.5, height*0.5); shaderManager->currentProgram()->setUniformValue("halfViewportSize", halfViewportSize); } else if (style == Qt::LinearGradientPattern) { const QLinearGradient *g = static_cast(currentBrush->gradient()); QPointF realStart = g->start(); QPointF realFinal = g->finalStop(); translationPoint = realStart; QPointF l = realFinal - realStart; QVector3D linearData( l.x(), l.y(), 1.0f / (l.x() * l.x() + l.y() * l.y()) ); shaderManager->currentProgram()->setUniformValue("linearData", linearData); QVector2D halfViewportSize(width*0.5, height*0.5); shaderManager->currentProgram()->setUniformValue("halfViewportSize", halfViewportSize); } else if (style == Qt::ConicalGradientPattern) { const QConicalGradient *g = static_cast(currentBrush->gradient()); translationPoint = g->center(); GLfloat angle = -(g->angle() * 2 * Q_PI) / 360.0; shaderManager->currentProgram()->setUniformValue("angle", angle); QVector2D halfViewportSize(width*0.5, height*0.5); shaderManager->currentProgram()->setUniformValue("halfViewportSize", halfViewportSize); } else if (style == Qt::RadialGradientPattern) { const QRadialGradient *g = static_cast(currentBrush->gradient()); QPointF realCenter = g->center(); QPointF realFocal = g->focalPoint(); qreal realRadius = g->radius(); translationPoint = realFocal; QPointF fmp = realCenter - realFocal; shaderManager->currentProgram()->setUniformValue("fmp", fmp); GLfloat fmp2_m_radius2 = -fmp.x() * fmp.x() - fmp.y() * fmp.y() + realRadius*realRadius; shaderManager->currentProgram()->setUniformValue("fmp2_m_radius2", fmp2_m_radius2); shaderManager->currentProgram()->setUniformValue("inverse_2_fmp2_m_radius2", GLfloat(1.0 / (2.0*fmp2_m_radius2))); QVector2D halfViewportSize(width*0.5, height*0.5); shaderManager->currentProgram()->setUniformValue("halfViewportSize", halfViewportSize); } else if (style == Qt::TexturePattern) { translationPoint = q->state()->brushOrigin; const QPixmap& texPixmap = currentBrush->texture(); QSizeF invertedTextureSize( 1.0 / texPixmap.width(), 1.0 / texPixmap.height() ); shaderManager->currentProgram()->setUniformValue("invertedTextureSize", invertedTextureSize); QVector2D halfViewportSize(width*0.5, height*0.5); shaderManager->currentProgram()->setUniformValue("halfViewportSize", halfViewportSize); } else qWarning("QGL2PaintEngineEx: Unimplemented fill style"); QTransform translate(1, 0, 0, 1, -translationPoint.x(), -translationPoint.y()); QTransform gl_to_qt(1, 0, 0, -1, 0, height); QTransform inv_matrix = gl_to_qt * (brushQTransform * q->state()->matrix).inverted() * translate; shaderManager->currentProgram()->setUniformValue("brushTransform", inv_matrix); shaderManager->currentProgram()->setUniformValue("brushTexture", QT_BRUSH_TEXTURE_UNIT); } brushUniformsDirty = false; } // This assumes the shader manager has already setup the correct shader program void QGL2PaintEngineExPrivate::updateMatrix() { // qDebug("QGL2PaintEngineExPrivate::updateMatrix()"); // We setup the Projection matrix to be the equivilant of glOrtho(0, w, h, 0, -1, 1): GLfloat P[4][4] = { {2.0/width, 0.0, 0.0, -1.0}, {0.0, -2.0/height, 0.0, 1.0}, {0.0, 0.0, -1.0, 0.0}, {0.0, 0.0, 0.0, 1.0} }; const QTransform& transform = q->state()->matrix; if (mode == TextDrawingMode) { // Text drawing mode is only used for non-scaling transforms for (int row = 0; row < 4; ++row) for (int col = 0; col < 4; ++col) pmvMatrix[col][row] = P[row][col]; pmvMatrix[3][0] += P[0][0] * qRound(transform.dx()); pmvMatrix[3][1] += P[1][1] * qRound(transform.dy()); inverseScale = 1; } else { // Use the (3x3) transform for the Model~View matrix: GLfloat MV[4][4] = { {transform.m11(), transform.m21(), 0.0, transform.dx()}, {transform.m12(), transform.m22(), 0.0, transform.dy()}, {0.0, 0.0, 1.0, 0.0}, {transform.m13(), transform.m23(), 0.0, transform.m33()} }; // NOTE: OpenGL ES works with column-major matrices, so when we multiply the matrices, // we also transpose them ready for GL. for (int row = 0; row < 4; ++row) { for (int col = 0; col < 4; ++col) { pmvMatrix[col][row] = 0.0; // P[row][n] is 0.0 for n < row for (int n = row; n < 4; ++n) pmvMatrix[col][row] += P[row][n] * MV[n][col]; } } // 1/10000 == 0.0001, so we have good enough res to cover curves // that span the entire widget... inverseScale = qMax(1 / qMax( qMax(qAbs(transform.m11()), qAbs(transform.m22())), qMax(qAbs(transform.m12()), qAbs(transform.m21())) ), qreal(0.0001)); } matrixDirty = false; // The actual data has been updated so both shader program's uniforms need updating simpleShaderMatrixUniformDirty = true; shaderMatrixUniformDirty = true; } void QGL2PaintEngineExPrivate::updateCompositionMode() { // NOTE: The entire paint engine works on pre-multiplied data - which is why some of these // composition modes look odd. // qDebug() << "QGL2PaintEngineExPrivate::updateCompositionMode() - Setting GL composition mode for " << q->state()->composition_mode; switch(q->state()->composition_mode) { case QPainter::CompositionMode_SourceOver: glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); break; case QPainter::CompositionMode_DestinationOver: glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE); break; case QPainter::CompositionMode_Clear: glBlendFunc(GL_ZERO, GL_ZERO); break; case QPainter::CompositionMode_Source: glBlendFunc(GL_ONE, GL_ZERO); break; case QPainter::CompositionMode_Destination: glBlendFunc(GL_ZERO, GL_ONE); break; case QPainter::CompositionMode_SourceIn: glBlendFunc(GL_DST_ALPHA, GL_ZERO); break; case QPainter::CompositionMode_DestinationIn: glBlendFunc(GL_ZERO, GL_SRC_ALPHA); break; case QPainter::CompositionMode_SourceOut: glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ZERO); break; case QPainter::CompositionMode_DestinationOut: glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA); break; case QPainter::CompositionMode_SourceAtop: glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA); break; case QPainter::CompositionMode_DestinationAtop: glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA); break; case QPainter::CompositionMode_Xor: glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA); break; case QPainter::CompositionMode_Plus: glBlendFunc(GL_ONE, GL_ONE); break; default: qWarning("Unsupported composition mode"); break; } compositionModeDirty = false; } static inline void setCoords(GLfloat *coords, const QGLRect &rect) { coords[0] = rect.left; coords[1] = rect.top; coords[2] = rect.right; coords[3] = rect.top; coords[4] = rect.right; coords[5] = rect.bottom; coords[6] = rect.left; coords[7] = rect.bottom; } void QGL2PaintEngineExPrivate::drawTexture(const QGLRect& dest, const QGLRect& src, const QSize &textureSize, bool opaque) { transferMode(ImageDrawingMode); updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, q->state()->renderHints & QPainter::SmoothPixmapTransform); // Setup for texture drawing shaderManager->setSrcPixelType(QGLEngineShaderManager::ImageSrc); shaderManager->setTextureCoordsEnabled(true); prepareForDraw(opaque); shaderManager->currentProgram()->setUniformValue("imageTexture", QT_IMAGE_TEXTURE_UNIT); GLfloat dx = 1.0 / textureSize.width(); GLfloat dy = 1.0 / textureSize.height(); QGLRect srcTextureRect(src.left*dx, 1.0 - src.top*dy, src.right*dx, 1.0 - src.bottom*dy); setCoords(staticVertexCoordinateArray, dest); setCoords(staticTextureCoordinateArray, srcTextureRect); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } void QGL2PaintEngineEx::sync() { Q_D(QGL2PaintEngineEx); ensureActive(); d->transferMode(BrushDrawingMode); QGLContext *ctx = d->ctx; glUseProgram(0); #ifndef QT_OPENGL_ES_2 // be nice to people who mix OpenGL 1.x code with QPainter commands // by setting modelview and projection matrices to mirror the GL 1 // paint engine const QTransform& mtx = state()->matrix; float mv_matrix[4][4] = { { mtx.m11(), mtx.m12(), 0, mtx.m13() }, { mtx.m21(), mtx.m22(), 0, mtx.m23() }, { 0, 0, 1, 0 }, { mtx.dx(), mtx.dy(), 0, mtx.m33() } }; const QSize sz = d->drawable.size(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, sz.width(), sz.height(), 0, -999999, 999999); glMatrixMode(GL_MODELVIEW); glLoadMatrixf(&mv_matrix[0][0]); #endif glDisable(GL_BLEND); glActiveTexture(GL_TEXTURE0); } void QGL2PaintEngineExPrivate::transferMode(EngineMode newMode) { if (newMode == mode) return; if (mode == TextDrawingMode || mode == ImageDrawingMode) { glDisableVertexAttribArray(QT_TEXTURE_COORDS_ATTR); glDisableVertexAttribArray(QT_VERTEX_COORDS_ATTR); } if (mode == TextDrawingMode) matrixDirty = true; if (newMode == TextDrawingMode) { glEnableVertexAttribArray(QT_VERTEX_COORDS_ATTR); glEnableVertexAttribArray(QT_TEXTURE_COORDS_ATTR); glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, vertexCoordinateArray.data()); glVertexAttribPointer(QT_TEXTURE_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, textureCoordinateArray.data()); matrixDirty = true; } if (newMode == ImageDrawingMode) { glEnableVertexAttribArray(QT_VERTEX_COORDS_ATTR); glEnableVertexAttribArray(QT_TEXTURE_COORDS_ATTR); glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, staticVertexCoordinateArray); glVertexAttribPointer(QT_TEXTURE_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, staticTextureCoordinateArray); } // This needs to change when we implement high-quality anti-aliasing... if (newMode != TextDrawingMode) shaderManager->setMaskType(QGLEngineShaderManager::NoMask); mode = newMode; } void QGL2PaintEngineExPrivate::drawOutline(const QVectorPath& path) { transferMode(BrushDrawingMode); // Might need to call updateMatrix to re-calculate inverseScale if (matrixDirty) updateMatrix(); vertexCoordinateArray.clear(); vertexCoordinateArray.addPath(path, inverseScale); if (path.hasImplicitClose()) { // Close the path's outline vertexCoordinateArray.lineToArray(path.points()[0], path.points()[1]); vertexCoordinateArray.stops().last() += 1; } prepareForDraw(currentBrush->isOpaque()); drawVertexArrays(vertexCoordinateArray, GL_LINE_STRIP); } // Assumes everything is configured for the brush you want to use void QGL2PaintEngineExPrivate::fill(const QVectorPath& path) { transferMode(BrushDrawingMode); // Might need to call updateMatrix to re-calculate inverseScale if (matrixDirty) updateMatrix(); const QPointF* const points = reinterpret_cast(path.points()); // Check to see if there's any hints if (path.shape() == QVectorPath::RectangleHint) { QGLRect rect(points[0].x(), points[0].y(), points[2].x(), points[2].y()); prepareForDraw(currentBrush->isOpaque()); composite(rect); } else if (path.shape() == QVectorPath::EllipseHint) { vertexCoordinateArray.clear(); vertexCoordinateArray.addPath(path, inverseScale); prepareForDraw(currentBrush->isOpaque()); drawVertexArrays(vertexCoordinateArray, GL_TRIANGLE_FAN); } else { // The path is too complicated & needs the stencil technique vertexCoordinateArray.clear(); vertexCoordinateArray.addPath(path, inverseScale); fillStencilWithVertexArray(vertexCoordinateArray, path.hasWindingFill()); // Stencil the brush onto the dest buffer glStencilFunc(GL_NOTEQUAL, 0, 0xFFFF); // Pass if stencil buff value != 0 glEnable(GL_STENCIL_TEST); prepareForDraw(currentBrush->isOpaque()); composite(vertexCoordinateArray.boundingRect()); glDisable(GL_STENCIL_TEST); cleanStencilBuffer(vertexCoordinateArray.boundingRect()); } } void QGL2PaintEngineExPrivate::fillStencilWithVertexArray(QGL2PEXVertexArray& vertexArray, bool useWindingFill) { // qDebug("QGL2PaintEngineExPrivate::fillStencilWithVertexArray()"); if (stencilBuferDirty) { // Clear the stencil buffer to zeros glDisable(GL_STENCIL_TEST); glStencilMask(0xFFFF); // Enable writing to stencil buffer, otherwise glClear wont do anything. glClearStencil(0); // Clear to zero glClear(GL_STENCIL_BUFFER_BIT); stencilBuferDirty = false; } glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // Disable color writes glStencilMask(0xFFFF); // Enable stencil writes glStencilFunc(GL_ALWAYS, 0, 0xFFFF); // Always pass the stencil test // Setup the stencil op: if (useWindingFill) { glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_INCR_WRAP); // Inc. for front-facing triangle glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_DECR_WRAP); //Dec. for back-facing "holes" } else glStencilOp(GL_KEEP, GL_KEEP, GL_INVERT); // Simply invert the stencil bit // No point in using a fancy gradiant shader for writing into the stencil buffer! useSimpleShader(); glEnable(GL_STENCIL_TEST); // For some reason, this has to happen _after_ the simple shader is use()'d glDisable(GL_BLEND); // Draw the vertecies into the stencil buffer: drawVertexArrays(vertexArray, GL_TRIANGLE_FAN); // Enable color writes & disable stencil writes glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glStencilMask(0); } void QGL2PaintEngineExPrivate::cleanStencilBuffer(const QGLRect& area) { // qDebug("QGL2PaintEngineExPrivate::cleanStencilBuffer()"); useSimpleShader(); GLfloat rectVerts[] = { area.left, area.top, area.left, area.bottom, area.right, area.bottom, area.right, area.top }; glEnableVertexAttribArray(QT_VERTEX_COORDS_ATTR); glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, rectVerts); glEnable(GL_STENCIL_TEST); glStencilFunc(GL_ALWAYS, 0, 0xFFFF); // Always pass the stencil test glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // Disable color writes glStencilMask(0xFFFF); // Enable writing to stencil buffer glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO); // Write 0's to stencil buffer glDisable(GL_BLEND); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); glDisableVertexAttribArray(QT_VERTEX_COORDS_ATTR); // Enable color writes & disable stencil writes glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glStencilMask(0); glDisable(GL_STENCIL_TEST); } void QGL2PaintEngineExPrivate::prepareForDraw(bool srcPixelsAreOpaque) { if (brushTextureDirty && mode != ImageDrawingMode) updateBrushTexture(); if (compositionModeDirty) updateCompositionMode(); if (matrixDirty) updateMatrix(); const bool stateHasOpacity = q->state()->opacity < 0.99f; if (q->state()->compositionMode() == QPainter::CompositionMode_Source || (q->state()->compositionMode() == QPainter::CompositionMode_SourceOver && srcPixelsAreOpaque && !stateHasOpacity)) glDisable(GL_BLEND); else glEnable(GL_BLEND); bool useGlobalOpacityUniform = stateHasOpacity; if (stateHasOpacity && (mode != ImageDrawingMode)) { // Using a brush bool brushIsPattern = (currentBrush->style() >= Qt::Dense1Pattern) && (currentBrush->style() <= Qt::DiagCrossPattern); if ((currentBrush->style() == Qt::SolidPattern) || brushIsPattern) useGlobalOpacityUniform = false; // Global opacity handled by srcPixel shader } shaderManager->setUseGlobalOpacity(useGlobalOpacityUniform); // If the shader program needs changing, we change it and mark all uniforms as dirty if (shaderManager->useCorrectShaderProg()) { // The shader program has changed so mark all uniforms as dirty: brushUniformsDirty = true; shaderMatrixUniformDirty = true; } if (brushUniformsDirty && mode != ImageDrawingMode) updateBrushUniforms(); if (shaderMatrixUniformDirty) { shaderManager->currentProgram()->setUniformValue("pmvMatrix", pmvMatrix); shaderMatrixUniformDirty = false; } if (useGlobalOpacityUniform) shaderManager->currentProgram()->setUniformValue("globalOpacity", (GLfloat)q->state()->opacity); } void QGL2PaintEngineExPrivate::composite(const QGLRect& boundingRect) { // Setup a vertex array for the bounding rect: GLfloat rectVerts[] = { boundingRect.left, boundingRect.top, boundingRect.left, boundingRect.bottom, boundingRect.right, boundingRect.bottom, boundingRect.right, boundingRect.top }; glEnableVertexAttribArray(QT_VERTEX_COORDS_ATTR); glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, rectVerts); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); glDisableVertexAttribArray(QT_VERTEX_COORDS_ATTR); } // Draws the vertex array as a set of triangle fans. void QGL2PaintEngineExPrivate::drawVertexArrays(QGL2PEXVertexArray& vertexArray, GLenum primitive) { // Now setup the pointer to the vertex array: glEnableVertexAttribArray(QT_VERTEX_COORDS_ATTR); glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, vertexArray.data()); int previousStop = 0; foreach(int stop, vertexArray.stops()) { /* qDebug("Drawing triangle fan for vertecies %d -> %d:", previousStop, stop-1); for (int i=previousStop; isetBrush(&brush); d->fill(path); d->setBrush(&(state()->brush)); // reset back to the state's brush } void QGL2PaintEngineEx::stroke(const QVectorPath &path, const QPen &pen) { Q_D(QGL2PaintEngineEx); if (pen.style() == Qt::NoPen) return; ensureActive(); if ( (pen.isCosmetic() && (pen.style() == Qt::SolidLine)) && (pen.widthF() < 2.5f) ) { // We only handle solid, cosmetic pens with a width of 1 pixel const QBrush& brush = pen.brush(); d->setBrush(&brush); if (pen.widthF() < 0.01f) glLineWidth(1.0); else glLineWidth(pen.widthF()); d->drawOutline(path); d->setBrush(&(state()->brush)); } else return QPaintEngineEx::stroke(path, pen); } void QGL2PaintEngineEx::penChanged() { // qDebug("QGL2PaintEngineEx::penChanged() not implemented!"); } void QGL2PaintEngineEx::brushChanged() { // qDebug("QGL2PaintEngineEx::brushChanged()"); Q_D(QGL2PaintEngineEx); d->setBrush(&(state()->brush)); } void QGL2PaintEngineEx::brushOriginChanged() { // qDebug("QGL2PaintEngineEx::brushOriginChanged()"); Q_D(QGL2PaintEngineEx); d->brushUniformsDirty = true; } void QGL2PaintEngineEx::opacityChanged() { // qDebug("QGL2PaintEngineEx::opacityChanged()"); Q_D(QGL2PaintEngineEx); Q_ASSERT(d->shaderManager); d->brushUniformsDirty = true; } void QGL2PaintEngineEx::compositionModeChanged() { // qDebug("QGL2PaintEngineEx::compositionModeChanged()"); Q_D(QGL2PaintEngineEx); d->compositionModeDirty = true; } void QGL2PaintEngineEx::renderHintsChanged() { // qDebug("QGL2PaintEngineEx::renderHintsChanged() not implemented!"); } void QGL2PaintEngineEx::transformChanged() { Q_D(QGL2PaintEngineEx); d->matrixDirty = true; } void QGL2PaintEngineEx::drawPixmap(const QRectF& dest, const QPixmap & pixmap, const QRectF & src) { Q_D(QGL2PaintEngineEx); ensureActive(); d->transferMode(ImageDrawingMode); QGLContext *ctx = d->ctx; glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT); ctx->d_func()->bindTexture(pixmap, GL_TEXTURE_2D, GL_RGBA, true); //FIXME: we should use hasAlpha() instead, but that's SLOW at the moment d->drawTexture(dest, src, pixmap.size(), !pixmap.hasAlphaChannel()); } void QGL2PaintEngineEx::drawImage(const QRectF& dest, const QImage& image, const QRectF& src, Qt::ImageConversionFlags) { Q_D(QGL2PaintEngineEx); ensureActive(); d->transferMode(ImageDrawingMode); QGLContext *ctx = d->ctx; glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT); ctx->d_func()->bindTexture(image, GL_TEXTURE_2D, GL_RGBA, true); d->drawTexture(dest, src, image.size(), !image.hasAlphaChannel()); } void QGL2PaintEngineEx::drawTextItem(const QPointF &p, const QTextItem &textItem) { Q_D(QGL2PaintEngineEx); ensureActive(); QOpenGL2PaintEngineState *s = state(); const QTextItemInt &ti = static_cast(textItem); bool drawCached = true; if (s->matrix.type() > QTransform::TxTranslate) drawCached = false; // don't try to cache huge fonts if (ti.fontEngine->fontDef.pixelSize * qSqrt(s->matrix.determinant()) >= 64) drawCached = false; if (drawCached) { d->drawCachedGlyphs(p, ti); return; } QPaintEngineEx::drawTextItem(p, ti); } void QGL2PaintEngineExPrivate::drawCachedGlyphs(const QPointF &p, const QTextItemInt &ti) { Q_Q(QGL2PaintEngineEx); QOpenGL2PaintEngineState *s = q->state(); QVarLengthArray positions; QVarLengthArray glyphs; QTransform matrix; matrix.translate(p.x(), p.y()); ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions); QFontEngineGlyphCache::Type glyphType = ti.fontEngine->glyphFormat >= 0 ? QFontEngineGlyphCache::Type(ti.fontEngine->glyphFormat) : QFontEngineGlyphCache::Raster_A8; QGLTextureGlyphCache *cache = (QGLTextureGlyphCache *) ti.fontEngine->glyphCache(ctx, s->matrix); if (!cache) { cache = new QGLTextureGlyphCache(ctx, glyphType, s->matrix); ti.fontEngine->setGlyphCache(ctx, cache); } cache->setPaintEnginePrivate(this); cache->populate(ti, glyphs, positions); if (cache->width() == 0 || cache->height() == 0) return; transferMode(TextDrawingMode); if (glyphType == QFontEngineGlyphCache::Raster_A8) shaderManager->setMaskType(QGLEngineShaderManager::PixelMask); else if (glyphType == QFontEngineGlyphCache::Raster_RGBMask) shaderManager->setMaskType(QGLEngineShaderManager::SubPixelMask); //### TODO: Gamma correction shaderManager->setTextureCoordsEnabled(true); int margin = cache->glyphMargin(); GLfloat dx = 1.0 / cache->width(); GLfloat dy = 1.0 / cache->height(); QGLPoint *oldVertexCoordinateDataPtr = vertexCoordinateArray.data(); QGLPoint *oldTextureCoordinateDataPtr = textureCoordinateArray.data(); vertexCoordinateArray.clear(); textureCoordinateArray.clear(); for (int i=0; icoords.value(glyphs[i]); int x = positions[i].x.toInt() + c.baseLineX - margin; int y = positions[i].y.toInt() - c.baseLineY - margin; vertexCoordinateArray.addRect(QRectF(x, y, c.w, c.h)); textureCoordinateArray.addRect(QRectF(c.x*dx, c.y*dy, c.w * dx, c.h * dy)); } glActiveTexture(GL_TEXTURE0 + QT_MASK_TEXTURE_UNIT); glBindTexture(GL_TEXTURE_2D, cache->texture()); updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, false); QBrush pensBrush = q->state()->pen.brush(); setBrush(&pensBrush); prepareForDraw(false); // Text always causes src pixels to be transparent shaderManager->currentProgram()->setUniformValue("maskTexture", QT_MASK_TEXTURE_UNIT); if (vertexCoordinateArray.data() != oldVertexCoordinateDataPtr) glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, vertexCoordinateArray.data()); if (textureCoordinateArray.data() != oldTextureCoordinateDataPtr) glVertexAttribPointer(QT_TEXTURE_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, textureCoordinateArray.data()); glDrawArrays(GL_TRIANGLES, 0, 6 * glyphs.size()); setBrush(&(q->state()->brush)); //### } bool QGL2PaintEngineEx::begin(QPaintDevice *pdev) { Q_D(QGL2PaintEngineEx); // qDebug("QGL2PaintEngineEx::begin()"); d->drawable.setDevice(pdev); d->ctx = d->drawable.context(); if (d->ctx->d_ptr->active_engine) { QGL2PaintEngineEx *engine = static_cast(d->ctx->d_ptr->active_engine); QGL2PaintEngineExPrivate *p = static_cast(engine->d_ptr); p->transferMode(BrushDrawingMode); p->drawable.doneCurrent(); } d->ctx->d_ptr->active_engine = this; d->drawable.makeCurrent(); QSize sz = d->drawable.size(); d->width = sz.width(); d->height = sz.height(); d->mode = BrushDrawingMode; #if !defined(QT_OPENGL_ES_2) qt_resolve_version_2_0_functions(d->ctx); #endif if (!d->shaderManager) d->shaderManager = new QGLEngineShaderManager(d->ctx); glViewport(0, 0, d->width, d->height); // glClearColor(0.0, 1.0, 0.0, 1.0); // glClear(GL_COLOR_BUFFER_BIT); // d->ctx->swapBuffers(); // qDebug("You should see green now"); // sleep(5); d->brushTextureDirty = true; d->brushUniformsDirty = true; d->matrixDirty = true; d->compositionModeDirty = true; d->stencilBuferDirty = true; d->use_system_clip = !systemClip().isEmpty(); glDisable(GL_DEPTH_TEST); glDisable(GL_SCISSOR_TEST); QGLPixmapData *source = d->drawable.copyOnBegin(); if (d->drawable.context()->d_func()->clear_on_painter_begin && d->drawable.autoFillBackground()) { if (d->drawable.hasTransparentBackground()) glClearColor(0.0, 0.0, 0.0, 0.0); else { const QColor &c = d->drawable.backgroundColor(); float alpha = c.alphaF(); glClearColor(c.redF() * alpha, c.greenF() * alpha, c.blueF() * alpha, alpha); } glClear(GL_COLOR_BUFFER_BIT); } else if (source) { QGLContext *ctx = d->ctx; d->transferMode(ImageDrawingMode); glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT); source->bind(false); QRect rect(0, 0, source->width(), source->height()); d->drawTexture(QRectF(rect), QRectF(rect), rect.size(), true); } updateClipRegion(QRegion(), Qt::NoClip); return true; } bool QGL2PaintEngineEx::end() { Q_D(QGL2PaintEngineEx); QGLContext *ctx = d->ctx; if (ctx->d_ptr->active_engine != this) { QGL2PaintEngineEx *engine = static_cast(ctx->d_ptr->active_engine); if (engine && engine->isActive()) { QGL2PaintEngineExPrivate *p = static_cast(engine->d_ptr); p->transferMode(BrushDrawingMode); p->drawable.doneCurrent(); } d->drawable.makeCurrent(); } glUseProgram(0); d->transferMode(BrushDrawingMode); d->drawable.swapBuffers(); d->drawable.doneCurrent(); d->ctx->d_ptr->active_engine = 0; return false; } void QGL2PaintEngineEx::ensureActive() { Q_D(QGL2PaintEngineEx); QGLContext *ctx = d->ctx; if (isActive() && ctx->d_ptr->active_engine != this) { QGL2PaintEngineEx *engine = static_cast(ctx->d_ptr->active_engine); if (engine && engine->isActive()) { QGL2PaintEngineExPrivate *p = static_cast(engine->d_ptr); p->transferMode(BrushDrawingMode); p->drawable.doneCurrent(); } d->drawable.makeCurrent(); ctx->d_ptr->active_engine = this; glDisable(GL_DEPTH_TEST); glDisable(GL_SCISSOR_TEST); glViewport(0, 0, d->width, d->height); setState(state()); d->updateDepthClip(); } } /////////////////////////////////// State/Clipping stolen from QOpenGLPaintEngine ////////////////////////////////////////// void QGL2PaintEngineEx::clipEnabledChanged() { Q_D(QGL2PaintEngineEx); d->updateDepthClip(); } void QGL2PaintEngineEx::clip(const QVectorPath &path, Qt::ClipOperation op) { // qDebug("QGL2PaintEngineEx::clip()"); const qreal *points = path.points(); const QPainterPath::ElementType *types = path.elements(); if (!types && path.shape() == QVectorPath::RectangleHint) { QRectF r(points[0], points[1], points[4]-points[0], points[5]-points[1]); updateClipRegion(QRegion(r.toRect()), op); return; } QPainterPath p; if (types) { int id = 0; for (int i=0; iuse_system_clip) { state()->hasClipping = false; state()->clipRegion = QRegion(); d->updateDepthClip(); return; } bool isScreenClip = false; if (!d->use_system_clip) { QVector untransformedRects = clipRegion.rects(); if (untransformedRects.size() == 1) { QPainterPath path; path.addRect(untransformedRects[0]); //path = d->matrix.map(path); path = state()->matrix.map(path); // if (path.contains(QRectF(QPointF(), d->drawable.size()))) // isScreenClip = true; if (path.contains(QRectF(0.0, 0.0, d->width, d->height))) isScreenClip = true; } } // QRegion region = isScreenClip ? QRegion() : clipRegion * d->matrix; QRegion region = isScreenClip ? QRegion() : clipRegion * state()->matrix; switch (op) { case Qt::NoClip: if (!d->use_system_clip) break; state()->clipRegion = sysClip; break; case Qt::IntersectClip: if (isScreenClip) return; if (state()->hasClipping) { state()->clipRegion &= region; break; } // fall through case Qt::ReplaceClip: if (d->use_system_clip && !sysClip.isEmpty()) state()->clipRegion = region & sysClip; else state()->clipRegion = region; break; case Qt::UniteClip: state()->clipRegion |= region; if (d->use_system_clip && !sysClip.isEmpty()) state()->clipRegion &= sysClip; break; default: break; } if (isScreenClip) { state()->hasClipping = false; state()->clipRegion = QRegion(); } else { state()->hasClipping = op != Qt::NoClip || d->use_system_clip; } d->updateDepthClip(); } void QGL2PaintEngineExPrivate::systemStateChanged() { Q_Q(QGL2PaintEngineEx); use_system_clip = !systemClip.isEmpty(); if (q->painter()->hasClipping()) q->updateClipRegion(q->painter()->clipRegion(), Qt::ReplaceClip); else q->updateClipRegion(QRegion(), Qt::NoClip); } void QGL2PaintEngineExPrivate::updateDepthClip() { // qDebug("QGL2PaintEngineExPrivate::updateDepthClip()"); Q_Q(QGL2PaintEngineEx); q->ensureActive(); glDisable(GL_DEPTH_TEST); glDisable(GL_SCISSOR_TEST); if (!q->state()->hasClipping) return; const QVector rects = q->state()->clipEnabled ? q->state()->clipRegion.rects() : q->systemClip().rects(); if (rects.size() == 1) { QRect fastClip = rects.at(0); glEnable(GL_SCISSOR_TEST); const int left = fastClip.left(); const int width = fastClip.width(); const int bottom = height - (fastClip.bottom() + 1); const int height = fastClip.height(); glScissor(left, bottom, width, height); return; } glClearDepth(0x0); glDepthMask(true); glClear(GL_DEPTH_BUFFER_BIT); glClearDepth(0x1); glEnable(GL_SCISSOR_TEST); for (int i = 0; i < rects.size(); ++i) { QRect rect = rects.at(i); const int left = rect.left(); const int width = rect.width(); const int bottom = height - (rect.bottom() + 1); const int height = rect.height(); glScissor(left, bottom, width, height); glClear(GL_DEPTH_BUFFER_BIT); } glDisable(GL_SCISSOR_TEST); glDepthMask(false); glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); } void QGL2PaintEngineEx::setState(QPainterState *new_state) { // qDebug("QGL2PaintEngineEx::setState()"); Q_D(QGL2PaintEngineEx); QOpenGL2PaintEngineState *s = static_cast(new_state); QOpenGL2PaintEngineState *old_state = state(); const bool needsDepthClipUpdate = !old_state || s->clipEnabled != old_state->clipEnabled || (s->clipEnabled && s->clipRegion != old_state->clipRegion); QPaintEngineEx::setState(s); if (needsDepthClipUpdate) d->updateDepthClip(); d->matrixDirty = true; d->compositionModeDirty = true; d->brushTextureDirty = true; d->brushUniformsDirty = true; d->simpleShaderMatrixUniformDirty = true; d->shaderMatrixUniformDirty = true; } QPainterState *QGL2PaintEngineEx::createState(QPainterState *orig) const { QOpenGL2PaintEngineState *s; if (!orig) s = new QOpenGL2PaintEngineState(); else s = new QOpenGL2PaintEngineState(*static_cast(orig)); return s; } QOpenGL2PaintEngineState::QOpenGL2PaintEngineState(QOpenGL2PaintEngineState &other) : QPainterState(other) { clipRegion = other.clipRegion; hasClipping = other.hasClipping; } QOpenGL2PaintEngineState::QOpenGL2PaintEngineState() { hasClipping = false; } QOpenGL2PaintEngineState::~QOpenGL2PaintEngineState() { } QT_END_NAMESPACE