Support Atlas textures in FadingNode

Summary:
Previously IconItem would create icons in new textures for animating. By
keeping them in the atlas not only do we avoid that, but we should
implicitly share the QSGTexture used for non-animating item.

Test Plan:
Moused over icon, it changed correctly
Set core profile, moused over an icon it changed correctly

Reviewers: #plasma

Subscribers: #frameworks

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D11091
This commit is contained in:
David Edmundson 2018-03-06 11:09:55 +00:00
parent 188be131bc
commit 02c4194534
4 changed files with 19 additions and 6 deletions

View File

@ -1,10 +1,12 @@
varying highp vec2 v_coord;
uniform sampler2D u_src;
uniform vec4 u_src_rect;
uniform sampler2D u_target;
uniform vec4 u_target_rect;
uniform highp float u_transitionProgress;
uniform lowp float qt_Opacity;
void main() {
lowp vec4 tex1 = texture2D(u_target, v_coord);
lowp vec4 tex2 = texture2D(u_src, v_coord);
lowp vec4 tex1 = texture2D(u_target, u_target_rect.xy + u_target_rect.zw * v_coord);
lowp vec4 tex2 = texture2D(u_src, u_src_rect.xy + u_src_rect.zw * v_coord);
gl_FragColor = mix(tex2, tex1, u_transitionProgress) * qt_Opacity;
}

View File

@ -2,11 +2,13 @@
in highp vec2 v_coord;
out vec4 fragColor;
uniform sampler2D u_src;
uniform vec4 u_src_rect;
uniform sampler2D u_target;
uniform vec4 u_target_rect;
uniform highp float u_transitionProgress;
uniform lowp float qt_Opacity;
void main() {
lowp vec4 tex1 = texture2D(u_target, v_coord);
lowp vec4 tex2 = texture2D(u_src, v_coord);
lowp vec4 tex1 = texture2D(u_target, u_target_rect.xy + u_target_rect.zw * v_coord);
lowp vec4 tex2 = texture2D(u_src, u_src_rect.xy + u_src_rect.zw * v_coord);
fragColor = mix(tex2, tex1, u_transitionProgress) * qt_Opacity;
}

View File

@ -43,6 +43,8 @@ public:
private:
QOpenGLFunctions *glFuncs = nullptr;
int m_progressId = 0;
int m_sourceRectId = 0;
int m_targetRectId = 0;
};
@ -62,6 +64,8 @@ void FadingMaterialShader::updateState(const FadingMaterialState* newState, cons
if (!oldState || oldState->source != newState->source) {
glFuncs->glActiveTexture(GL_TEXTURE1);
newState->source->bind();
QRectF rect = newState->source->normalizedTextureSubRect();
program()->setUniformValue(m_sourceRectId, QVector4D(rect.x(), rect.y(), rect.width(), rect.height()));
// reset the active texture back to 0 after we changed it to something else
glFuncs->glActiveTexture(GL_TEXTURE0);
}
@ -69,6 +73,8 @@ void FadingMaterialShader::updateState(const FadingMaterialState* newState, cons
if (!oldState || oldState->target != newState->target) {
glFuncs->glActiveTexture(GL_TEXTURE0);
newState->target->bind();
QRectF rect = newState->target->normalizedTextureSubRect();
program()->setUniformValue(m_targetRectId, QVector4D(rect.x(), rect.y(), rect.width(), rect.height()));
}
if (!oldState || oldState->progress != newState->progress) {
@ -87,7 +93,10 @@ void FadingMaterialShader::initialize()
program()->bind();
program()->setUniformValue("u_src", 0);
program()->setUniformValue("u_target", 1);
m_progressId = program()->uniformLocation("u_transitionProgress");
m_sourceRectId = program()->uniformLocation("u_src_rect");
m_targetRectId = program()->uniformLocation("u_target_rect");
}

View File

@ -481,9 +481,9 @@ QSGNode* IconItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *update
if (!animatingNode || m_textureChanged) {
delete oldNode;
QSGTexture *source = window()->createTextureFromImage(m_iconPixmap.toImage());
QSGTexture *source = window()->createTextureFromImage(m_oldIconPixmap.toImage(), QQuickWindow::TextureCanUseAtlas);
source->setFiltering(m_smooth ? QSGTexture::Linear : QSGTexture::Nearest);
QSGTexture *target = window()->createTextureFromImage(m_oldIconPixmap.toImage());
QSGTexture *target = window()->createTextureFromImage(m_iconPixmap.toImage(), QQuickWindow::TextureCanUseAtlas);
target->setFiltering(m_smooth ? QSGTexture::Linear : QSGTexture::Nearest);
animatingNode = new FadingNode(source, target);
m_sizeChanged = true;