Use shader traits API for lanczos filter's shader
This commit is contained in:
parent
99739106d1
commit
b366f0ac01
4 changed files with 25 additions and 18 deletions
|
@ -33,6 +33,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
#include <kwineffects.h>
|
||||
|
||||
#include <QFile>
|
||||
|
||||
#include <qmath.h>
|
||||
#include <cmath>
|
||||
|
||||
|
@ -45,7 +47,6 @@ LanczosFilter::LanczosFilter(QObject* parent)
|
|||
, m_offscreenTarget(0)
|
||||
, m_inited(false)
|
||||
, m_shader(0)
|
||||
, m_uTexUnit(0)
|
||||
, m_uOffsets(0)
|
||||
, m_uKernel(0)
|
||||
{
|
||||
|
@ -84,13 +85,16 @@ void LanczosFilter::init()
|
|||
if (gl->isRadeon() && gl->chipClass() < R600)
|
||||
return;
|
||||
}
|
||||
m_shader.reset(ShaderManager::instance()->loadFragmentShader(ShaderManager::SimpleShader,
|
||||
gl->glslVersion() >= kVersionNumber(1, 40) ?
|
||||
QStringLiteral(":/resources/shaders/1.40/lanczos-fragment.glsl") :
|
||||
QStringLiteral(":/resources/shaders/1.10/lanczos-fragment.glsl")));
|
||||
QFile ff(gl->glslVersion() >= kVersionNumber(1, 40) ?
|
||||
QStringLiteral(":/resources/shaders/1.40/lanczos-fragment.glsl") :
|
||||
QStringLiteral(":/resources/shaders/1.10/lanczos-fragment.glsl"));
|
||||
if (!ff.open(QIODevice::ReadOnly)) {
|
||||
qCDebug(KWIN_CORE) << "Failed to open lanczos shader";
|
||||
return;
|
||||
}
|
||||
m_shader.reset(ShaderManager::instance()->generateCustomShader(ShaderTrait::MapTexture, QByteArray(), ff.readAll()));
|
||||
if (m_shader->isValid()) {
|
||||
ShaderBinder binder(m_shader.data());
|
||||
m_uTexUnit = m_shader->uniformLocation("texUnit");
|
||||
m_uKernel = m_shader->uniformLocation("kernel");
|
||||
m_uOffsets = m_shader->uniformLocation("offsets");
|
||||
} else {
|
||||
|
@ -251,6 +255,10 @@ void LanczosFilter::performPaint(EffectWindowImpl* w, int mask, QRegion region,
|
|||
updateOffscreenSurfaces();
|
||||
GLRenderTarget::pushRenderTarget(m_offscreenTarget);
|
||||
|
||||
QMatrix4x4 modelViewProjectionMatrix;
|
||||
modelViewProjectionMatrix.ortho(0, m_offscreenTex->width(), m_offscreenTex->height(), 0 , 0, 65535);
|
||||
thumbData.setProjectionMatrix(modelViewProjectionMatrix);
|
||||
|
||||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
w->sceneWindow()->performPaint(mask, infiniteRegion(), thumbData);
|
||||
|
@ -270,6 +278,7 @@ void LanczosFilter::performPaint(EffectWindowImpl* w, int mask, QRegion region,
|
|||
createOffsets(kernelSize, sw, Qt::Horizontal);
|
||||
|
||||
ShaderManager::instance()->pushShader(m_shader.data());
|
||||
m_shader->setUniform(GLShader::ModelViewProjectionMatrix, modelViewProjectionMatrix);
|
||||
setUniforms();
|
||||
|
||||
// Draw the window back into the FBO, this time scaled horizontally
|
||||
|
@ -408,7 +417,6 @@ void LanczosFilter::discardCacheTexture(EffectWindow *w)
|
|||
|
||||
void LanczosFilter::setUniforms()
|
||||
{
|
||||
glUniform1i(m_uTexUnit, 0);
|
||||
glUniform2fv(m_uOffsets, 16, (const GLfloat*)m_offsets);
|
||||
glUniform4fv(m_uKernel, 16, (const GLfloat*)m_kernel);
|
||||
}
|
||||
|
|
|
@ -65,7 +65,6 @@ private:
|
|||
QBasicTimer m_timer;
|
||||
bool m_inited;
|
||||
QScopedPointer<GLShader> m_shader;
|
||||
int m_uTexUnit;
|
||||
int m_uOffsets;
|
||||
int m_uKernel;
|
||||
QVector2D m_offsets[16];
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
uniform sampler2D texUnit;
|
||||
uniform sampler2D sampler;
|
||||
uniform vec2 offsets[16];
|
||||
uniform vec4 kernel[16];
|
||||
|
||||
varying vec2 varyingTexCoords;
|
||||
varying vec2 texcoord0;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec4 sum = texture2D(texUnit, varyingTexCoords.st) * kernel[0];
|
||||
vec4 sum = texture2D(sampler, texcoord0.st) * kernel[0];
|
||||
for (int i = 1; i < 16; i++) {
|
||||
sum += texture2D(texUnit, varyingTexCoords.st - offsets[i]) * kernel[i];
|
||||
sum += texture2D(texUnit, varyingTexCoords.st + offsets[i]) * kernel[i];
|
||||
sum += texture2D(sampler, texcoord0.st - offsets[i]) * kernel[i];
|
||||
sum += texture2D(sampler, texcoord0.st + offsets[i]) * kernel[i];
|
||||
}
|
||||
gl_FragColor = sum;
|
||||
}
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
#version 140
|
||||
|
||||
uniform sampler2D texUnit;
|
||||
uniform sampler2D sampler;
|
||||
uniform vec2 offsets[16];
|
||||
uniform vec4 kernel[16];
|
||||
|
||||
in vec2 varyingTexCoords;
|
||||
in vec2 texcoord0;
|
||||
out vec4 fragColor;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec4 sum = texture(texUnit, varyingTexCoords.st) * kernel[0];
|
||||
vec4 sum = texture(sampler, texcoord0.st) * kernel[0];
|
||||
for (int i = 1; i < 16; i++) {
|
||||
sum += texture(texUnit, varyingTexCoords.st - offsets[i]) * kernel[i];
|
||||
sum += texture(texUnit, varyingTexCoords.st + offsets[i]) * kernel[i];
|
||||
sum += texture(sampler, texcoord0.st - offsets[i]) * kernel[i];
|
||||
sum += texture(sampler, texcoord0.st + offsets[i]) * kernel[i];
|
||||
}
|
||||
fragColor = sum;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue