[effects] Port startupfeedback to shader trait api
The blinking shader is adjusted to use a shader trait vertex shader and gets generated with a shader trait variant. Overall the code is simplified to ensure that we always have a shader bound with the correct mvp matrix when rendering the icon.
This commit is contained in:
parent
f13622a914
commit
712e46e468
2 changed files with 23 additions and 25 deletions
|
@ -1,13 +1,13 @@
|
||||||
uniform sampler2D sampler;
|
uniform sampler2D sampler;
|
||||||
uniform vec4 u_color;
|
uniform vec4 geometryColor;
|
||||||
|
|
||||||
varying vec2 varyingTexCoords;
|
varying vec2 texcoord0;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 tex = texture2D(sampler, varyingTexCoords);
|
vec4 tex = texture2D(sampler, texcoord0);
|
||||||
if (tex.a != 1.0) {
|
if (tex.a != 1.0) {
|
||||||
tex = u_color;
|
tex = geometryColor;
|
||||||
}
|
}
|
||||||
gl_FragColor = tex;
|
gl_FragColor = tex;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#include "startupfeedback.h"
|
#include "startupfeedback.h"
|
||||||
// Qt
|
// Qt
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QFile>
|
||||||
#include <QSize>
|
#include <QSize>
|
||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
#include <QtCore/QStandardPaths>
|
#include <QtCore/QStandardPaths>
|
||||||
|
@ -131,11 +132,17 @@ void StartupFeedbackEffect::reconfigure(Effect::ReconfigureFlags flags)
|
||||||
delete m_blinkingShader;
|
delete m_blinkingShader;
|
||||||
m_blinkingShader = 0;
|
m_blinkingShader = 0;
|
||||||
const QString shader = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kwin/blinking-startup-fragment.glsl"));
|
const QString shader = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kwin/blinking-startup-fragment.glsl"));
|
||||||
m_blinkingShader = ShaderManager::instance()->loadFragmentShader(ShaderManager::SimpleShader, shader);
|
|
||||||
if (m_blinkingShader->isValid()) {
|
QFile ff(shader);
|
||||||
qCDebug(KWINEFFECTS) << "Blinking Shader is valid";
|
if (ff.open(QIODevice::ReadOnly)) {
|
||||||
|
m_blinkingShader = ShaderManager::instance()->generateCustomShader(ShaderTrait::MapTexture, QByteArray(), ff.readAll());
|
||||||
|
if (m_blinkingShader->isValid()) {
|
||||||
|
qCDebug(KWINEFFECTS) << "Blinking Shader is valid";
|
||||||
|
} else {
|
||||||
|
qCDebug(KWINEFFECTS) << "Blinking Shader is not valid";
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
qCDebug(KWINEFFECTS) << "Blinking Shader is not valid";
|
qCCritical(KWINEFFECTS) << "Couldn't open" << shader << "for reading!";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
|
@ -187,27 +194,18 @@ void StartupFeedbackEffect::paintScreen(int mask, QRegion region, ScreenPaintDat
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
texture->bind();
|
texture->bind();
|
||||||
bool useShader = false;
|
if (m_type == BlinkingFeedback && m_blinkingShader && m_blinkingShader->isValid()) {
|
||||||
if (m_type == BlinkingFeedback) {
|
|
||||||
const QColor& blinkingColor = BLINKING_COLORS[ FRAME_TO_BLINKING_COLOR[ m_frame ]];
|
const QColor& blinkingColor = BLINKING_COLORS[ FRAME_TO_BLINKING_COLOR[ m_frame ]];
|
||||||
if (m_blinkingShader && m_blinkingShader->isValid()) {
|
ShaderManager::instance()->pushShader(m_blinkingShader);
|
||||||
useShader = true;
|
m_blinkingShader->setUniform(GLShader::Color, blinkingColor);
|
||||||
ShaderManager::instance()->pushShader(m_blinkingShader);
|
|
||||||
m_blinkingShader->setUniform("u_color", blinkingColor);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
useShader = true;
|
ShaderManager::instance()->pushShader(ShaderTrait::MapTexture);
|
||||||
auto s = ShaderManager::instance()->pushShader(ShaderTrait::MapTexture);
|
|
||||||
QMatrix4x4 mvp;
|
|
||||||
const QSize size = effects->virtualScreenSize();
|
|
||||||
mvp.ortho(0, size.width(), size.height(), 0, 0, 65535);
|
|
||||||
mvp.translate(m_currentGeometry.x(), m_currentGeometry.y());
|
|
||||||
s->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
|
|
||||||
}
|
}
|
||||||
|
QMatrix4x4 mvp = data.projectionMatrix();
|
||||||
|
mvp.translate(m_currentGeometry.x(), m_currentGeometry.y());
|
||||||
|
ShaderManager::instance()->getBoundShader()->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
|
||||||
texture->render(m_currentGeometry, m_currentGeometry);
|
texture->render(m_currentGeometry, m_currentGeometry);
|
||||||
if (useShader) {
|
ShaderManager::instance()->popShader();
|
||||||
ShaderManager::instance()->popShader();
|
|
||||||
}
|
|
||||||
texture->unbind();
|
texture->unbind();
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue