[effects] Use shader traits generated shader for invert effect
Source code needs minor adjustment to be compatible with the shader traits variable naming.
This commit is contained in:
parent
7facdb67ee
commit
f13622a914
4 changed files with 12 additions and 20 deletions
|
@ -2,11 +2,11 @@ uniform sampler2D sampler;
|
|||
uniform vec4 modulation;
|
||||
uniform float saturation;
|
||||
|
||||
varying vec2 varyingTexCoords;
|
||||
varying vec2 texcoord0;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 tex = texture2D(sampler, varyingTexCoords);
|
||||
vec4 tex = texture2D(sampler, texcoord0);
|
||||
|
||||
if (saturation != 1.0) {
|
||||
vec3 desaturated = tex.rgb * vec3( 0.30, 0.59, 0.11 );
|
||||
|
|
|
@ -3,13 +3,13 @@ uniform sampler2D sampler;
|
|||
uniform vec4 modulation;
|
||||
uniform float saturation;
|
||||
|
||||
in vec2 varyingTexCoords;
|
||||
in vec2 texcoord0;
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 tex = texture(sampler, varyingTexCoords);
|
||||
vec4 tex = texture(sampler, texcoord0);
|
||||
|
||||
if (saturation != 1.0) {
|
||||
vec3 desaturated = tex.rgb * vec3( 0.30, 0.59, 0.11 );
|
||||
|
|
|
@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include "invert.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QFile>
|
||||
#include <kwinglutils.h>
|
||||
#include <kwinglplatform.h>
|
||||
#include <KGlobalAccel>
|
||||
|
@ -56,7 +57,6 @@ InvertEffect::InvertEffect()
|
|||
connect(b, SIGNAL(triggered(bool)), this, SLOT(toggleWindow()));
|
||||
|
||||
connect(effects, SIGNAL(windowClosed(KWin::EffectWindow*)), this, SLOT(slotWindowClosed(KWin::EffectWindow*)));
|
||||
connect(effects, SIGNAL(screenGeometryChanged(const QSize&)), this, SLOT(resetShader()));
|
||||
}
|
||||
|
||||
InvertEffect::~InvertEffect()
|
||||
|
@ -79,7 +79,13 @@ bool InvertEffect::loadData()
|
|||
shadersDir = QStringLiteral("kwin/shaders/1.40/");
|
||||
const QString fragmentshader = QStandardPaths::locate(QStandardPaths::GenericDataLocation, shadersDir + QStringLiteral("invert.frag"));
|
||||
|
||||
m_shader = ShaderManager::instance()->loadFragmentShader(ShaderManager::GenericShader, fragmentshader);
|
||||
QFile ff(fragmentshader);
|
||||
if (!ff.open(QIODevice::ReadOnly)) {
|
||||
qCCritical(KWINEFFECTS) << "Couldn't open" << fragmentshader << "for reading!";
|
||||
return false;
|
||||
}
|
||||
|
||||
m_shader = ShaderManager::instance()->generateCustomShader(ShaderTrait::MapTexture, QByteArray(), ff.readAll());
|
||||
if (!m_shader->isValid()) {
|
||||
qCCritical(KWINEFFECTS) << "The shader failed to load!";
|
||||
return false;
|
||||
|
@ -110,11 +116,7 @@ void InvertEffect::drawWindow(EffectWindow* w, int mask, QRegion region, WindowP
|
|||
bool useShader = m_valid && (m_allWindows != m_windows.contains(w));
|
||||
if (useShader) {
|
||||
ShaderManager *shaderManager = ShaderManager::instance();
|
||||
GLShader *genericShader = shaderManager->pushShader(ShaderManager::GenericShader);
|
||||
QMatrix4x4 screenTransformation = genericShader->getUniformMatrix4x4("screenTransformation");
|
||||
shaderManager->popShader();
|
||||
shaderManager->pushShader(m_shader);
|
||||
m_shader->setUniform("screenTransformation", screenTransformation);
|
||||
|
||||
data.shader = m_shader;
|
||||
}
|
||||
|
@ -131,8 +133,6 @@ void InvertEffect::paintEffectFrame(KWin::EffectFrame* frame, QRegion region, do
|
|||
if (m_valid && m_allWindows) {
|
||||
frame->setShader(m_shader);
|
||||
ShaderBinder binder(m_shader);
|
||||
m_shader->setUniform("screenTransformation", QMatrix4x4());
|
||||
m_shader->setUniform("windowTransformation", QMatrix4x4());
|
||||
effects->paintEffectFrame(frame, region, opacity, frameOpacity);
|
||||
} else {
|
||||
effects->paintEffectFrame(frame, region, opacity, frameOpacity);
|
||||
|
@ -172,11 +172,6 @@ bool InvertEffect::provides(Feature f)
|
|||
return f == ScreenInversion;
|
||||
}
|
||||
|
||||
void InvertEffect::resetShader()
|
||||
{
|
||||
ShaderManager::instance()->resetShader(m_shader, ShaderManager::GenericShader);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
#include "invert.moc"
|
||||
|
|
|
@ -54,9 +54,6 @@ public Q_SLOTS:
|
|||
void toggleWindow();
|
||||
void slotWindowClosed(KWin::EffectWindow *w);
|
||||
|
||||
private Q_SLOTS:
|
||||
void resetShader();
|
||||
|
||||
protected:
|
||||
bool loadData();
|
||||
|
||||
|
|
Loading…
Reference in a new issue