diff options
Diffstat (limited to 'src/quick/scenegraph')
-rw-r--r-- | src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp | 5 | ||||
-rw-r--r-- | src/quick/scenegraph/qsgdefaultglyphnode_p.cpp | 49 | ||||
-rw-r--r-- | src/quick/scenegraph/qsgdefaultrectanglenode.cpp | 8 | ||||
-rw-r--r-- | src/quick/scenegraph/scenegraph.qrc | 2 | ||||
-rw-r--r-- | src/quick/scenegraph/shaders/32bitcolortext.frag | 9 | ||||
-rw-r--r-- | src/quick/scenegraph/shaders/32bitcolortext_core.frag | 13 | ||||
-rw-r--r-- | src/quick/scenegraph/shaders/smoothtexture_core.vert | 7 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgatlastexture.cpp | 11 |
8 files changed, 90 insertions, 14 deletions
diff --git a/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp b/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp index 136f23f339..dcc485ce17 100644 --- a/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp +++ b/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp @@ -38,6 +38,7 @@ #include <QtQml/private/qqmlglobal_p.h> #include <QtQuick/private/qsgdistancefieldutil_p.h> #include <qopenglfunctions.h> +#include <qopenglframebufferobject.h> #include <qmath.h> #if !defined(QT_OPENGL_ES_2) @@ -324,7 +325,7 @@ void QSGDefaultDistanceFieldGlyphCache::resizeTexture(TextureInfo *texInfo, int GL_COLOR_BUFFER_BIT, GL_NEAREST); // Reset the default framebuffer - m_coreFuncs->glBindFramebuffer(GL_FRAMEBUFFER, 0); + QOpenGLFramebufferObject::bindDefault(); return; } else if (useTextureResizeWorkaround()) { @@ -449,7 +450,7 @@ void QSGDefaultDistanceFieldGlyphCache::resizeTexture(TextureInfo *texInfo, int m_funcs->glDeleteTextures(1, &tmp_texture); m_funcs->glDeleteTextures(1, &oldTexture); - m_funcs->glBindFramebuffer(GL_FRAMEBUFFER, 0); + QOpenGLFramebufferObject::bindDefault(); // restore render states if (stencilTestEnabled) diff --git a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp index 9f1a44154c..14bc0fad07 100644 --- a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp +++ b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp @@ -267,6 +267,30 @@ void QSG24BitTextMaskShader::updateState(const RenderState &state, QSGMaterial * } } +class QSG32BitColorTextShader : public QSGTextMaskShader +{ +public: + QSG32BitColorTextShader(QFontEngine::GlyphFormat glyphFormat) + : QSGTextMaskShader(glyphFormat) + { + setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/scenegraph/shaders/32bitcolortext.frag")); + } + + void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) Q_DECL_OVERRIDE; +}; + +void QSG32BitColorTextShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) +{ + QSGTextMaskShader::updateState(state, newEffect, oldEffect); + QSGTextMaskMaterial *material = static_cast<QSGTextMaskMaterial *>(newEffect); + QSGTextMaskMaterial *oldMaterial = static_cast<QSGTextMaskMaterial *>(oldEffect); + + if (oldMaterial == Q_NULLPTR || material->color() != oldMaterial->color() || state.isOpacityDirty()) { + float opacity = material->color().w() * state.opacity(); + program()->setUniformValue(m_color_id, opacity); + } +} + class QSGStyledTextShader : public QSG8BitTextMaskShader { public: @@ -497,8 +521,16 @@ void QSGTextMaskMaterial::populate(const QPointF &p, QSGMaterialType *QSGTextMaskMaterial::type() const { - static QSGMaterialType rgb, gray; - return glyphCache()->glyphFormat() == QFontEngine::Format_A32 ? &rgb : &gray; + static QSGMaterialType argb, rgb, gray; + switch (glyphCache()->glyphFormat()) { + case QFontEngine::Format_ARGB: + return &argb; + case QFontEngine::Format_A32: + return &rgb; + case QFontEngine::Format_A8: + default: + return &gray; + } } QOpenGLTextureGlyphCache *QSGTextMaskMaterial::glyphCache() const @@ -508,10 +540,15 @@ QOpenGLTextureGlyphCache *QSGTextMaskMaterial::glyphCache() const QSGMaterialShader *QSGTextMaskMaterial::createShader() const { - QFontEngine::GlyphFormat glyphFormat = glyphCache()->glyphFormat(); - return glyphFormat == QFontEngine::Format_A32 - ? (QSGMaterialShader *) new QSG24BitTextMaskShader(glyphFormat) - : (QSGMaterialShader *) new QSG8BitTextMaskShader(glyphFormat); + switch (QFontEngine::GlyphFormat glyphFormat = glyphCache()->glyphFormat()) { + case QFontEngine::Format_ARGB: + return new QSG32BitColorTextShader(glyphFormat); + case QFontEngine::Format_A32: + return new QSG24BitTextMaskShader(glyphFormat); + case QFontEngine::Format_A8: + default: + return new QSG8BitTextMaskShader(glyphFormat); + } } static inline int qsg_colorDiff(const QVector4D &a, const QVector4D &b) diff --git a/src/quick/scenegraph/qsgdefaultrectanglenode.cpp b/src/quick/scenegraph/qsgdefaultrectanglenode.cpp index 3e251a4051..f3f5c7f79f 100644 --- a/src/quick/scenegraph/qsgdefaultrectanglenode.cpp +++ b/src/quick/scenegraph/qsgdefaultrectanglenode.cpp @@ -323,11 +323,11 @@ void QSGDefaultRectangleNode::updateGeometry() const QGradientStops &stops = m_gradient_stops; int nextGradientStop = 0; - float gradientPos = 0.5f * penWidth / height; + float gradientPos = penWidth / height; while (nextGradientStop < stops.size() && stops.at(nextGradientStop).first <= gradientPos) ++nextGradientStop; int lastGradientStop = stops.size() - 1; - float lastGradientPos = 1.0f - 0.5f * penWidth / height; + float lastGradientPos = 1.0f - penWidth / height; while (lastGradientStop >= nextGradientStop && stops.at(lastGradientStop).first >= lastGradientPos) --lastGradientStop; int gradientIntersections = (lastGradientStop - nextGradientStop + 1); @@ -643,11 +643,11 @@ void QSGDefaultRectangleNode::updateGeometry() for (int part = -1; part <= 1; part += 2) { float y = (part == 1 ? innerRect.bottom() : innerRect.top()); float Y = (part == 1 ? outerRect.bottom() : outerRect.top()); - gradientPos = (y - innerRect.top() + 0.5f * penWidth) / height; + gradientPos = (y - innerRect.top() + penWidth) / height; while (nextGradientStop <= lastGradientStop && stops.at(nextGradientStop).first <= gradientPos) { // Insert vertices at gradient stops. - float gy = (innerRect.top() - 0.5f * penWidth) + stops.at(nextGradientStop).first * height; + float gy = (innerRect.top() - penWidth) + stops.at(nextGradientStop).first * height; fillColor = colorToColor4ub(stops.at(nextGradientStop).second); diff --git a/src/quick/scenegraph/scenegraph.qrc b/src/quick/scenegraph/scenegraph.qrc index e6a90c9120..5db242e46b 100644 --- a/src/quick/scenegraph/scenegraph.qrc +++ b/src/quick/scenegraph/scenegraph.qrc @@ -4,6 +4,7 @@ <file>shaders/flatcolor.vert</file> <file>shaders/8bittextmask.frag</file> <file>shaders/24bittextmask.frag</file> + <file>shaders/32bitcolortext.frag</file> <file>shaders/opaquetexture.frag</file> <file>shaders/opaquetexture.vert</file> <file>shaders/outlinedtext.frag</file> @@ -34,6 +35,7 @@ <file>shaders/stencilclip.vert</file> <file>shaders/8bittextmask_core.frag</file> <file>shaders/24bittextmask_core.frag</file> + <file>shaders/32bitcolortext_core.frag</file> <file>shaders/distancefieldoutlinetext_core.frag</file> <file>shaders/distancefieldshiftedtext_core.frag</file> <file>shaders/distancefieldshiftedtext_core.vert</file> diff --git a/src/quick/scenegraph/shaders/32bitcolortext.frag b/src/quick/scenegraph/shaders/32bitcolortext.frag new file mode 100644 index 0000000000..6fdb6e6aeb --- /dev/null +++ b/src/quick/scenegraph/shaders/32bitcolortext.frag @@ -0,0 +1,9 @@ +varying highp vec2 sampleCoord; + +uniform sampler2D _qt_texture; +uniform lowp float color; // just the alpha, really... + +void main() +{ + gl_FragColor = texture2D(_qt_texture, sampleCoord) * color; +} diff --git a/src/quick/scenegraph/shaders/32bitcolortext_core.frag b/src/quick/scenegraph/shaders/32bitcolortext_core.frag new file mode 100644 index 0000000000..010aca97b4 --- /dev/null +++ b/src/quick/scenegraph/shaders/32bitcolortext_core.frag @@ -0,0 +1,13 @@ +#version 150 core + +in vec2 sampleCoord; + +out vec4 fragColor; + +uniform sampler2D _qt_texture; +uniform float color; // just the alpha, really... + +void main() +{ + fragColor = texture(_qt_texture, sampleCoord) * color; +} diff --git a/src/quick/scenegraph/shaders/smoothtexture_core.vert b/src/quick/scenegraph/shaders/smoothtexture_core.vert index a2489a39c5..6821398e57 100644 --- a/src/quick/scenegraph/shaders/smoothtexture_core.vert +++ b/src/quick/scenegraph/shaders/smoothtexture_core.vert @@ -50,5 +50,8 @@ void main() bool onEdge = any(notEqual(vertexOffset, vec2(0.))); bool outerEdge = all(equal(texCoordOffset, vec2(0.))); - vertexOpacity = onEdge && outerEdge ? 0. : opacity; -}
\ No newline at end of file + if (onEdge && outerEdge) + vertexOpacity = 0.; + else + vertexOpacity = opacity; +} diff --git a/src/quick/scenegraph/util/qsgatlastexture.cpp b/src/quick/scenegraph/util/qsgatlastexture.cpp index 7a2587dacd..8c649fb6bd 100644 --- a/src/quick/scenegraph/util/qsgatlastexture.cpp +++ b/src/quick/scenegraph/util/qsgatlastexture.cpp @@ -148,8 +148,15 @@ Atlas::Atlas(const QSize &size) || deviceName->compare(QStringLiteral("samsung SM-T215"), Qt::CaseInsensitive) == 0); #else static bool wrongfullyReportsBgra8888Support = false; + // The Raspberry Pi (both 1 and 2) GPU refuses framebuffers with BGRA color attachments. + const GLubyte *renderer = QOpenGLContext::currentContext()->functions()->glGetString(GL_RENDERER); + if (renderer && strstr((const char *) renderer, "VideoCore IV")) + wrongfullyReportsBgra8888Support = true; #endif // ANDROID + if (qEnvironmentVariableIsSet("QSG_ATLAS_NO_BGRA_WORKAROUNDS")) + wrongfullyReportsBgra8888Support = false; + const char *ext = (const char *) QOpenGLContext::currentContext()->functions()->glGetString(GL_EXTENSIONS); if (!wrongfullyReportsBgra8888Support && (strstr(ext, "GL_EXT_bgra") @@ -484,7 +491,11 @@ QSGTexture *Texture::removedFromAtlas() const f->glBindTexture(GL_TEXTURE_2D, texture); QRect r = atlasSubRectWithoutPadding(); // and copy atlas into our texture. + while (f->glGetError() != GL_NO_ERROR) ; f->glCopyTexImage2D(GL_TEXTURE_2D, 0, m_atlas->internalFormat(), r.x(), r.y(), r.width(), r.height(), 0); + // BGRA may have been rejected by some GLES implementations + if (f->glGetError() != GL_NO_ERROR) + f->glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, r.x(), r.y(), r.width(), r.height(), 0); m_nonatlas_texture = new QSGPlainTexture(); m_nonatlas_texture->setTextureId(texture); |