no subclass for the shader

* get rid of the strength property
* this effect doesn't have config
icc-effect-5.14.5
Marco Martin 2014-01-05 17:20:50 +01:00
parent 4036f179fc
commit 4f2d2e469d
3 changed files with 26 additions and 83 deletions

View File

@ -74,11 +74,6 @@ void ContrastEffect::reconfigure(ReconfigureFlags flags)
{
Q_UNUSED(flags)
ContrastConfig::self()->readConfig();
int strength = 4;
if (shader)
shader->setStrength(strength);
if (!shader || !shader->isValid())
XDeleteProperty(display(), rootWindow(), net_wm_contrast_region);
}
@ -136,7 +131,7 @@ bool ContrastEffect::enabledByDefault()
bool ContrastEffect::supported()
{
bool supported = GLRenderTarget::supported() && GLTexture::NPOTTextureSupported() && GLSLContrastShader::supported();
bool supported = GLRenderTarget::supported() && GLTexture::NPOTTextureSupported() && ContrastShader::supported();
if (supported) {
int maxTexSize;

View File

@ -34,48 +34,28 @@ using namespace KWin;
ContrastShader::ContrastShader()
: mStrength(0), mValid(false)
: shader(NULL), mValid(false)
{
}
ContrastShader::~ContrastShader()
{
reset();
}
ContrastShader *ContrastShader::create()
{
if (GLSLContrastShader::supported())
return new GLSLContrastShader();
if (ContrastShader::supported()) {
ContrastShader *s = new ContrastShader();
s->reset();
s->init();
return s;
}
return NULL;
}
void ContrastShader::setStrength(int radius)
{
const int r = qMax(radius, 2);
if (mStrength != r) {
mStrength = r;
reset();
init();
}
}
// ----------------------------------------------------------------------------
GLSLContrastShader::GLSLContrastShader()
: ContrastShader(), shader(NULL)
{
}
GLSLContrastShader::~GLSLContrastShader()
{
reset();
}
void GLSLContrastShader::reset()
void ContrastShader::reset()
{
delete shader;
shader = NULL;
@ -83,7 +63,7 @@ void GLSLContrastShader::reset()
setIsValid(false);
}
bool GLSLContrastShader::supported()
bool ContrastShader::supported()
{
if (!GLPlatform::instance()->supports(GLSL))
return false;
@ -115,7 +95,7 @@ bool GLSLContrastShader::supported()
return true;
}
void GLSLContrastShader::setColorMatrix(const QMatrix4x4 &matrix)
void ContrastShader::setColorMatrix(const QMatrix4x4 &matrix)
{
if (!isValid())
return;
@ -125,7 +105,7 @@ void GLSLContrastShader::setColorMatrix(const QMatrix4x4 &matrix)
ShaderManager::instance()->popShader();
}
void GLSLContrastShader::setTextureMatrix(const QMatrix4x4 &matrix)
void ContrastShader::setTextureMatrix(const QMatrix4x4 &matrix)
{
if (!isValid())
return;
@ -133,7 +113,7 @@ void GLSLContrastShader::setTextureMatrix(const QMatrix4x4 &matrix)
shader->setUniform(textureMatrixLocation, matrix);
}
void GLSLContrastShader::setModelViewProjectionMatrix(const QMatrix4x4 &matrix)
void ContrastShader::setModelViewProjectionMatrix(const QMatrix4x4 &matrix)
{
if (!isValid())
return;
@ -141,7 +121,7 @@ void GLSLContrastShader::setModelViewProjectionMatrix(const QMatrix4x4 &matrix)
shader->setUniform(mvpMatrixLocation, matrix);
}
void GLSLContrastShader::bind()
void ContrastShader::bind()
{
if (!isValid())
return;
@ -149,12 +129,12 @@ void GLSLContrastShader::bind()
ShaderManager::instance()->pushShader(shader);
}
void GLSLContrastShader::unbind()
void ContrastShader::unbind()
{
ShaderManager::instance()->popShader();
}
void GLSLContrastShader::init()
void ContrastShader::init()
{

View File

@ -39,57 +39,25 @@ public:
return mValid;
}
// Sets the radius in pixels
void setStrength(int strength);
int strength() const {
return mStrength;
}
virtual void setColorMatrix(const QMatrix4x4 &matrix) = 0;
void setColorMatrix(const QMatrix4x4 &matrix);
virtual void setTextureMatrix(const QMatrix4x4 &matrix) = 0;
virtual void setModelViewProjectionMatrix(const QMatrix4x4 &matrix) = 0;
virtual void bind() = 0;
virtual void unbind() = 0;
protected:
float gaussian(float x, float sigma) const;
void setIsValid(bool value) {
mValid = value;
}
virtual void init() = 0;
virtual void reset() = 0;
private:
int mStrength;
bool mValid;
};
// ----------------------------------------------------------------------------
class GLSLContrastShader : public ContrastShader
{
public:
GLSLContrastShader();
~GLSLContrastShader();
void setTextureMatrix(const QMatrix4x4 &matrix);
void setModelViewProjectionMatrix(const QMatrix4x4 &matrix);
void bind();
void unbind();
void setColorMatrix(const QMatrix4x4 &matrix);
void setTextureMatrix(const QMatrix4x4 &matrix);
void setModelViewProjectionMatrix(const QMatrix4x4 &matrix);
static bool supported();
protected:
void init();
void reset();
void setIsValid(bool value) {
mValid = value;
}
virtual void init();
virtual void reset();
private:
bool mValid;
GLShader *shader;
int mvpMatrixLocation;
int textureMatrixLocation;