diff options
author | Samuel Rødal <sroedal@trolltech.com> | 2009-06-12 12:05:22 (GMT) |
---|---|---|
committer | Samuel Rødal <sroedal@trolltech.com> | 2009-06-12 12:41:52 (GMT) |
commit | d834d94bde645d43dd981154bd0ba99d8e81f040 (patch) | |
tree | 5164895fa6ba6582b40fe285296a680c409ff420 /src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp | |
parent | 8a2993a6c53e1a5641bd1c500ad4bd54e799299b (diff) | |
download | Qt-d834d94bde645d43dd981154bd0ba99d8e81f040.zip Qt-d834d94bde645d43dd981154bd0ba99d8e81f040.tar.gz Qt-d834d94bde645d43dd981154bd0ba99d8e81f040.tar.bz2 |
Fixed incorrect rendering of bitmap/pattern brushes in GL 2 engine.
The pen color should be used when drawPixmap is called with a bitmap,
and the brush color should be used for texture patterns that are
bitmaps.
Task-number: 245802
Reviewed-by: Trond
Diffstat (limited to 'src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp')
-rw-r--r-- | src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index bdea187..d1c6e9f 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -279,7 +279,13 @@ void QGL2PaintEngineExPrivate::setBrush(const QBrush* brush) currentBrush = brush; brushTextureDirty = true; brushUniformsDirty = true; - shaderManager->setSrcPixelType(currentBrush->style()); + if (currentBrush->style() == Qt::TexturePattern + && qHasPixmapTexture(*brush) && brush->texture().isQBitmap()) + { + shaderManager->setSrcPixelType(QGLEngineShaderManager::TextureSrcWithPattern); + } else { + shaderManager->setSrcPixelType(currentBrush->style()); + } shaderManager->optimiseForBrushTransform(currentBrush->transform()); } @@ -314,7 +320,7 @@ void QGL2PaintEngineExPrivate::updateBrushTexture() if ( (style >= Qt::Dense1Pattern) && (style <= Qt::DiagCrossPattern) ) { // Get the image data for the pattern - QImage texImage = qt_imageForBrush(style, true); + QImage texImage = qt_imageForBrush(style, false); glActiveTexture(GL_TEXTURE0 + QT_BRUSH_TEXTURE_UNIT); ctx->d_func()->bindTexture(texImage, GL_TEXTURE_2D, GL_RGBA, true); @@ -432,6 +438,11 @@ void QGL2PaintEngineExPrivate::updateBrushUniforms() const QPixmap& texPixmap = currentBrush->texture(); + if (qHasPixmapTexture(*currentBrush) && currentBrush->texture().isQBitmap()) { + QColor col = premultiplyColor(currentBrush->color(), (GLfloat)q->state()->opacity); + shaderManager->currentProgram()->setUniformValue("patternColor", col); + } + QSizeF invertedTextureSize( 1.0 / texPixmap.width(), 1.0 / texPixmap.height() ); shaderManager->currentProgram()->setUniformValue("invertedTextureSize", invertedTextureSize); @@ -578,17 +589,22 @@ static inline void setCoords(GLfloat *coords, const QGLRect &rect) coords[7] = rect.bottom; } -void QGL2PaintEngineExPrivate::drawTexture(const QGLRect& dest, const QGLRect& src, const QSize &textureSize, bool opaque) +void QGL2PaintEngineExPrivate::drawTexture(const QGLRect& dest, const QGLRect& src, const QSize &textureSize, bool opaque, bool pattern) { transferMode(ImageDrawingMode); updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, q->state()->renderHints & QPainter::SmoothPixmapTransform); // Setup for texture drawing - shaderManager->setSrcPixelType(QGLEngineShaderManager::ImageSrc); + shaderManager->setSrcPixelType(pattern ? QGLEngineShaderManager::PatternSrc : QGLEngineShaderManager::ImageSrc); shaderManager->setTextureCoordsEnabled(true); prepareForDraw(opaque); + if (pattern) { + QColor col = premultiplyColor(q->state()->pen.color(), (GLfloat)q->state()->opacity); + shaderManager->currentProgram()->setUniformValue("patternColor", col); + } + shaderManager->currentProgram()->setUniformValue("imageTexture", QT_IMAGE_TEXTURE_UNIT); GLfloat dx = 1.0 / textureSize.width(); @@ -987,7 +1003,7 @@ void QGL2PaintEngineEx::drawPixmap(const QRectF& dest, const QPixmap & pixmap, c 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()); + d->drawTexture(dest, src, pixmap.size(), !pixmap.hasAlphaChannel(), pixmap.depth() == 1); } void QGL2PaintEngineEx::drawImage(const QRectF& dest, const QImage& image, const QRectF& src, |