From 4f2d2e469d5485aefbbea243b1dec032f9b58a6e Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Sun, 5 Jan 2014 17:20:50 +0100 Subject: [PATCH] no subclass for the shader * get rid of the strength property * this effect doesn't have config --- effects/backgroundcontrast/contrast.cpp | 7 +-- effects/backgroundcontrast/contrastshader.cpp | 52 ++++++------------- effects/backgroundcontrast/contrastshader.h | 50 ++++-------------- 3 files changed, 26 insertions(+), 83 deletions(-) diff --git a/effects/backgroundcontrast/contrast.cpp b/effects/backgroundcontrast/contrast.cpp index 932cb14bc9..2d8d7485bf 100644 --- a/effects/backgroundcontrast/contrast.cpp +++ b/effects/backgroundcontrast/contrast.cpp @@ -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; diff --git a/effects/backgroundcontrast/contrastshader.cpp b/effects/backgroundcontrast/contrastshader.cpp index 5f81df5c5a..a2968ee820 100644 --- a/effects/backgroundcontrast/contrastshader.cpp +++ b/effects/backgroundcontrast/contrastshader.cpp @@ -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() { diff --git a/effects/backgroundcontrast/contrastshader.h b/effects/backgroundcontrast/contrastshader.h index 525b2916a2..5fa863ce31 100644 --- a/effects/backgroundcontrast/contrastshader.h +++ b/effects/backgroundcontrast/contrastshader.h @@ -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;