diff options
Diffstat (limited to 'src/opengl')
-rw-r--r-- | src/opengl/gl2paintengineex/qglengineshadermanager.cpp | 12 | ||||
-rw-r--r-- | src/opengl/gl2paintengineex/qglengineshadermanager_p.h | 8 | ||||
-rw-r--r-- | src/opengl/gl2paintengineex/qglengineshadersource_p.h | 33 | ||||
-rw-r--r-- | src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp | 136 | ||||
-rw-r--r-- | src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h | 2 | ||||
-rw-r--r-- | src/opengl/qgl.cpp | 4 | ||||
-rw-r--r-- | src/opengl/qglextensions.cpp | 3 | ||||
-rw-r--r-- | src/opengl/qglextensions_p.h | 9 |
8 files changed, 23 insertions, 184 deletions
diff --git a/src/opengl/gl2paintengineex/qglengineshadermanager.cpp b/src/opengl/gl2paintengineex/qglengineshadermanager.cpp index eceed06..b3458af 100644 --- a/src/opengl/gl2paintengineex/qglengineshadermanager.cpp +++ b/src/opengl/gl2paintengineex/qglengineshadermanager.cpp @@ -134,8 +134,7 @@ QGLEngineSharedShaders::QGLEngineSharedShaders(const QGLContext* context) code[ShockingPinkSrcFragmentShader] = qglslShockingPinkSrcFragmentShader; code[MaskFragmentShader] = qglslMaskFragmentShader; - code[RgbMaskFragmentShaderPass1] = qglslRgbMaskFragmentShaderPass1; - code[RgbMaskFragmentShaderPass2] = qglslRgbMaskFragmentShaderPass2; + code[RgbMaskFragmentShader] = ""; //### code[RgbMaskWithGammaFragmentShader] = ""; //### code[MultiplyCompositionModeFragmentShader] = ""; //### @@ -588,15 +587,10 @@ bool QGLEngineShaderManager::useCorrectShaderProg() if (maskType == PixelMask) { maskShaderName = QGLEngineSharedShaders::MaskFragmentShader; texCoords = true; - } else if (maskType == SubPixelMaskPass1) { - maskShaderName = QGLEngineSharedShaders::RgbMaskFragmentShaderPass1; - texCoords = true; - } else if (maskType == SubPixelMaskPass2) { - maskShaderName = QGLEngineSharedShaders::RgbMaskFragmentShaderPass2; - texCoords = true; + } else if (maskType == SubPixelMask) { + maskShaderName = QGLEngineSharedShaders::RgbMaskFragmentShader; } else if (maskType == SubPixelWithGammaMask) { maskShaderName = QGLEngineSharedShaders::RgbMaskWithGammaFragmentShader; - texCoords = true; } else { qCritical("QGLEngineShaderManager::useCorrectShaderProg() - Unknown mask type"); } diff --git a/src/opengl/gl2paintengineex/qglengineshadermanager_p.h b/src/opengl/gl2paintengineex/qglengineshadermanager_p.h index 47d9a2a..3c5a5f5 100644 --- a/src/opengl/gl2paintengineex/qglengineshadermanager_p.h +++ b/src/opengl/gl2paintengineex/qglengineshadermanager_p.h @@ -142,8 +142,7 @@ Masks are implementations of "qcolorp vec4 applyMask(qcolorp vec4 src)": qglslMaskFragmentShader - qglslRgbMaskFragmentShaderPass1 - qglslRgbMaskFragmentShaderPass2 + qglslRgbMaskFragmentShader qglslRgbMaskWithGammaFragmentShader Composition modes are "qcolorp vec4 compose(qcolorp vec4 src)": @@ -322,8 +321,7 @@ public: ShockingPinkSrcFragmentShader, MaskFragmentShader, - RgbMaskFragmentShaderPass1, - RgbMaskFragmentShaderPass2, + RgbMaskFragmentShader, RgbMaskWithGammaFragmentShader, MultiplyCompositionModeFragmentShader, @@ -378,7 +376,7 @@ public: QGLEngineShaderManager(QGLContext* context); ~QGLEngineShaderManager(); - enum MaskType {NoMask, PixelMask, SubPixelMaskPass1, SubPixelMaskPass2, SubPixelWithGammaMask}; + enum MaskType {NoMask, PixelMask, SubPixelMask, SubPixelWithGammaMask}; enum PixelSrcType { ImageSrc = Qt::TexturePattern+1, NonPremultipliedImageSrc = Qt::TexturePattern+2, diff --git a/src/opengl/gl2paintengineex/qglengineshadersource_p.h b/src/opengl/gl2paintengineex/qglengineshadersource_p.h index 8ae86d3..6bcf010 100644 --- a/src/opengl/gl2paintengineex/qglengineshadersource_p.h +++ b/src/opengl/gl2paintengineex/qglengineshadersource_p.h @@ -401,39 +401,6 @@ static const char* const qglslMaskFragmentShader = "\ return src * mask.a; \ }"; -// For source over with subpixel antialiasing, the final color is calculated per component as follows -// (.a is alpha component, .c is red, green or blue component): -// alpha = src.a * mask.c * opacity -// dest.c = dest.c * (1 - alpha) + src.c * alpha -// -// In the first pass, calculate: dest.c = dest.c * (1 - alpha) with blend funcs: zero, 1 - source color -// In the second pass, calculate: dest.c = dest.c + src.c * alpha with blend funcs: one, one -// -// If source is a solid color (src is constant), only the first pass is needed, with blend funcs: constant, 1 - source color - -// For source composition with subpixel antialiasing, the final color is calculated per component as follows: -// alpha = src.a * mask.c * opacity -// dest.c = dest.c * (1 - mask.c) + src.c * alpha -// - -static const char* const qglslRgbMaskFragmentShaderPass1 = "\ - varying highp vec2 textureCoords;\ - uniform lowp sampler2D maskTexture;\ - lowp vec4 applyMask(lowp vec4 src) \ - {\ - lowp vec4 mask = texture2D(maskTexture, textureCoords); \ - return src.a * mask; \ - }"; - -static const char* const qglslRgbMaskFragmentShaderPass2 = "\ - varying highp vec2 textureCoords;\ - uniform lowp sampler2D maskTexture;\ - lowp vec4 applyMask(lowp vec4 src) \ - {\ - lowp vec4 mask = texture2D(maskTexture, textureCoords); \ - return src * mask; \ - }"; - /* Left to implement: RgbMaskFragmentShader, diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index 20bbc1e..837d055 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -90,10 +90,6 @@ static const GLuint QT_IMAGE_TEXTURE_UNIT = 0; //Can be the same as brush static const GLuint QT_MASK_TEXTURE_UNIT = 1; static const GLuint QT_BACKGROUND_TEXTURE_UNIT = 2; -#ifdef Q_WS_WIN -extern Q_GUI_EXPORT bool qt_cleartype_enabled; -#endif - class QGLTextureGlyphCache : public QObject, public QTextureGlyphCache { Q_OBJECT @@ -104,7 +100,6 @@ public: virtual void createTextureData(int width, int height); virtual void resizeTextureData(int width, int height); virtual void fillTexture(const Coord &c, glyph_t glyph); - virtual int glyphMargin() const; inline GLuint texture() const { return m_texture; } @@ -295,7 +290,7 @@ void QGLTextureGlyphCache::fillTexture(const Coord &c, glyph_t glyph) glBindTexture(GL_TEXTURE_2D, m_texture); if (mask.format() == QImage::Format_RGB32) { - glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y, maskWidth, maskHeight, GL_BGRA, GL_UNSIGNED_BYTE, mask.bits()); + glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, m_height - c.y, maskWidth, maskHeight, GL_BGRA, GL_UNSIGNED_BYTE, mask.bits()); } else { #ifdef QT_OPENGL_ES2 glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y, maskWidth, maskHeight, GL_ALPHA, GL_UNSIGNED_BYTE, mask.bits()); @@ -315,15 +310,6 @@ void QGLTextureGlyphCache::fillTexture(const Coord &c, glyph_t glyph) } } -int QGLTextureGlyphCache::glyphMargin() const -{ -#ifdef Q_WS_MAC - return 2; -#else - return m_type == QFontEngineGlyphCache::Raster_RGBMask ? 2 : 0; -#endif -} - extern QImage qt_imageForBrush(int brushStyle, bool invert); ////////////////////////////////// Private Methods ////////////////////////////////////////// @@ -1210,12 +1196,6 @@ void QGL2PaintEngineEx::drawTextItem(const QPointF &p, const QTextItem &textItem if (ti.fontEngine->fontDef.pixelSize * qSqrt(s->matrix.determinant()) >= 64) drawCached = false; - if (d->glyphCacheType == QFontEngineGlyphCache::Raster_RGBMask - && state()->composition_mode != QPainter::CompositionMode_Source - && state()->composition_mode != QPainter::CompositionMode_SourceOver) { - drawCached = false; - } - if (drawCached) { d->drawCachedGlyphs(p, ti); return; @@ -1236,7 +1216,7 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(const QPointF &p, const QTextIte QFontEngineGlyphCache::Type glyphType = ti.fontEngine->glyphFormat >= 0 ? QFontEngineGlyphCache::Type(ti.fontEngine->glyphFormat) - : glyphCacheType; + : QFontEngineGlyphCache::Raster_A8; QGLTextureGlyphCache *cache = (QGLTextureGlyphCache *) ti.fontEngine->glyphCache(ctx, s->matrix); @@ -1255,6 +1235,12 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(const QPointF &p, const QTextIte transferMode(BrushDrawingMode); transferMode(TextDrawingMode); + if (glyphType == QFontEngineGlyphCache::Raster_A8) + shaderManager->setMaskType(QGLEngineShaderManager::PixelMask); + else if (glyphType == QFontEngineGlyphCache::Raster_RGBMask) + shaderManager->setMaskType(QGLEngineShaderManager::SubPixelMask); + //### TODO: Gamma correction + int margin = cache->glyphMargin(); GLfloat dx = 1.0 / cache->width(); @@ -1275,96 +1261,10 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(const QPointF &p, const QTextIte textureCoordinateArray.addRect(QRectF(c.x*dx, c.y*dy, c.w * dx, c.h * dy)); } - 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()); - QBrush pensBrush = q->state()->pen.brush(); setBrush(&pensBrush); - if (glyphType == QFontEngineGlyphCache::Raster_A8) { - - // Greyscale antialiasing - - shaderManager->setMaskType(QGLEngineShaderManager::PixelMask); - prepareForDraw(false); // Text always causes src pixels to be transparent - } else if (glyphType == QFontEngineGlyphCache::Raster_RGBMask) { - - // Subpixel antialiasing without gamma correction - - QPainter::CompositionMode compMode = q->state()->composition_mode; - Q_ASSERT(compMode == QPainter::CompositionMode_Source - || compMode == QPainter::CompositionMode_SourceOver); - - shaderManager->setMaskType(QGLEngineShaderManager::SubPixelMaskPass1); - - if (pensBrush.style() == Qt::SolidPattern) { - // Solid patterns can get away with only one pass. - QColor c = pensBrush.color(); - qreal oldOpacity = q->state()->opacity; - if (compMode == QPainter::CompositionMode_Source) { - c = premultiplyColor(c, q->state()->opacity); - q->state()->opacity = 1; - opacityUniformDirty = true; - } - - compositionModeDirty = false; // I can handle this myself, thank you very much - prepareForDraw(false); // Text always causes src pixels to be transparent - - // prepareForDraw() have set the opacity on the current shader, so the opacity state can now be reset. - if (compMode == QPainter::CompositionMode_Source) { - q->state()->opacity = oldOpacity; - opacityUniformDirty = true; - } - - glEnable(GL_BLEND); - glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_SRC_COLOR); - glBlendColor(c.redF(), c.greenF(), c.blueF(), c.alphaF()); - } else { - // Other brush styles need two passes. - - qreal oldOpacity = q->state()->opacity; - if (compMode == QPainter::CompositionMode_Source) { - q->state()->opacity = 1; - opacityUniformDirty = true; - pensBrush = Qt::white; - setBrush(&pensBrush); - } - - compositionModeDirty = false; // I can handle this myself, thank you very much - prepareForDraw(false); // Text always causes src pixels to be transparent - glEnable(GL_BLEND); - glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR); - - glActiveTexture(GL_TEXTURE0 + QT_MASK_TEXTURE_UNIT); - glBindTexture(GL_TEXTURE_2D, cache->texture()); - updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, false); - -#ifndef QT_OPENGL_ES_2 - if (inRenderText) - shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::Depth), zValueForRenderText()); -#endif - shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::MaskTexture), QT_MASK_TEXTURE_UNIT); - glDrawArrays(GL_TRIANGLES, 0, 6 * glyphs.size()); - - shaderManager->setMaskType(QGLEngineShaderManager::SubPixelMaskPass2); - - if (compMode == QPainter::CompositionMode_Source) { - q->state()->opacity = oldOpacity; - opacityUniformDirty = true; - pensBrush = q->state()->pen.brush(); - setBrush(&pensBrush); - } - - compositionModeDirty = false; - prepareForDraw(false); // Text always causes src pixels to be transparent - glEnable(GL_BLEND); - glBlendFunc(GL_ONE, GL_ONE); - } - compositionModeDirty = true; - } - //### TODO: Gamma correction + prepareForDraw(false); // Text always causes src pixels to be transparent glActiveTexture(GL_TEXTURE0 + QT_MASK_TEXTURE_UNIT); glBindTexture(GL_TEXTURE_2D, cache->texture()); @@ -1374,7 +1274,14 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(const QPointF &p, const QTextIte if (inRenderText) shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::Depth), zValueForRenderText()); #endif + shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::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()); } @@ -1433,17 +1340,6 @@ bool QGL2PaintEngineEx::begin(QPaintDevice *pdev) glDisable(GL_MULTISAMPLE); #endif - if (d->device->format().alpha() -#if defined(Q_WS_WIN) - || !qt_cleartype_enabled -#endif - ) { - d->glyphCacheType = QFontEngineGlyphCache::Raster_A8; - } else { - d->glyphCacheType = QFontEngineGlyphCache::Raster_RGBMask; - } - - d->systemStateChanged(); return true; } diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h b/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h index 8b09f41..a44be90 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h @@ -60,7 +60,6 @@ #include <private/qgl2pexvertexarray_p.h> #include <private/qglpaintdevice_p.h> #include <private/qglpixmapfilter_p.h> -#include <private/qfontengine_p.h> enum EngineMode { ImageDrawingMode, @@ -206,7 +205,6 @@ public: int width, height; QGLContext *ctx; EngineMode mode; - QFontEngineGlyphCache::Type glyphCacheType; mutable QOpenGL2PaintEngineState *last_created_state; diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index 1a0957c..fe676ea 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -2560,8 +2560,6 @@ static void qDrawTextureRect(const QRectF &target, GLint textureWidth, GLint tex Draws the given texture, \a textureId, to the given target rectangle, \a target, in OpenGL model space. The \a textureTarget should be a 2D texture target. - - Equivalent to the corresponding QGLContext::drawTexture(). */ void QGLContext::drawTexture(const QRectF &target, GLuint textureId, GLenum textureTarget) { @@ -2603,8 +2601,6 @@ void QGLContext::drawTexture(const QRectF &target, QMacCompatGLuint textureId, Q Draws the given texture at the given \a point in OpenGL model space. The \a textureTarget should be a 2D texture target. - - Equivalent to the corresponding QGLContext::drawTexture(). */ void QGLContext::drawTexture(const QPointF &point, GLuint textureId, GLenum textureTarget) { diff --git a/src/opengl/qglextensions.cpp b/src/opengl/qglextensions.cpp index c785d8a..3699d62 100644 --- a/src/opengl/qglextensions.cpp +++ b/src/opengl/qglextensions.cpp @@ -391,9 +391,8 @@ bool qt_resolve_version_2_0_functions(QGLContext *ctx) if (glStencilOpSeparate) return gl2supported; - glBlendColor = (_glBlendColor) ctx->getProcAddress(QLatin1String("glBlendColor")); glStencilOpSeparate = (_glStencilOpSeparate) ctx->getProcAddress(QLatin1String("glStencilOpSeparate")); - if (!glBlendColor || !glStencilOpSeparate) + if (!glStencilOpSeparate) gl2supported = false; return gl2supported; diff --git a/src/opengl/qglextensions_p.h b/src/opengl/qglextensions_p.h index 3510765..40840b5 100644 --- a/src/opengl/qglextensions_p.h +++ b/src/opengl/qglextensions_p.h @@ -152,7 +152,6 @@ typedef void (APIENTRY *_glActiveStencilFaceEXT) (GLenum ); // Needed for GL2 engine: typedef void (APIENTRY *_glStencilOpSeparate) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); typedef void (APIENTRY *_glActiveTexture) (GLenum); -typedef void (APIENTRY *_glBlendColor) (GLclampf, GLclampf, GLclampf, GLclampf); // EXT_GL_framebuffer_object @@ -248,7 +247,6 @@ struct QGLExtensionFuncs // Extras for GL2 engine: qt_glActiveTexture = 0; qt_glStencilOpSeparate = 0; - qt_glBlendColor = 0; qt_glActiveStencilFaceEXT = 0; qt_glMultiTexCoord4f = 0; @@ -362,8 +360,6 @@ struct QGLExtensionFuncs // Extras needed for GL2 engine: _glActiveTexture qt_glActiveTexture; _glStencilOpSeparate qt_glStencilOpSeparate; - _glBlendColor qt_glBlendColor; - #endif // FBOs @@ -578,10 +574,6 @@ struct QGLExtensionFuncs #endif #ifndef GL_VERSION_1_4 -#define GL_CONSTANT_COLOR 0x8001 -#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002 -#define GL_CONSTANT_ALPHA 0x8003 -#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004 #define GL_INCR_WRAP 0x8507 #define GL_DECR_WRAP 0x8508 #endif @@ -725,7 +717,6 @@ struct QGLExtensionFuncs #if !defined(QT_OPENGL_ES_2) #define glStencilOpSeparate QGLContextPrivate::extensionFuncs(ctx).qt_glStencilOpSeparate -#define glBlendColor QGLContextPrivate::extensionFuncs(ctx).qt_glBlendColor #endif #if defined(QT_OPENGL_ES_2) |