2010-03-05 20:42:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2010 Fredrik Höglund <fredrik@kde.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. if not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BLURSHADER_H
|
|
|
|
#define BLURSHADER_H
|
|
|
|
|
|
|
|
#include <kwinglutils.h>
|
|
|
|
|
2011-01-08 18:56:22 +00:00
|
|
|
class QMatrix4x4;
|
|
|
|
|
2010-03-05 20:42:10 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
class BlurShader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BlurShader();
|
2010-03-08 20:45:58 +00:00
|
|
|
virtual ~BlurShader();
|
|
|
|
|
|
|
|
static BlurShader *create();
|
2010-03-05 20:42:10 +00:00
|
|
|
|
2010-03-12 15:56:19 +00:00
|
|
|
bool isValid() const { return mValid; }
|
|
|
|
|
2010-03-05 20:42:10 +00:00
|
|
|
// Sets the radius in pixels
|
|
|
|
void setRadius(int radius);
|
2010-03-08 20:45:58 +00:00
|
|
|
int radius() const { return mRadius; }
|
2010-03-05 20:42:10 +00:00
|
|
|
|
|
|
|
// Sets the blur direction
|
2010-03-08 20:45:58 +00:00
|
|
|
void setDirection(Qt::Orientation direction);
|
|
|
|
Qt::Orientation direction() const { return mDirection; }
|
2010-03-05 20:42:10 +00:00
|
|
|
|
|
|
|
// Sets the distance between two pixels
|
2010-03-08 20:45:58 +00:00
|
|
|
virtual void setPixelDistance(float val) = 0;
|
2011-01-08 18:56:22 +00:00
|
|
|
virtual void setTextureMatrix(const QMatrix4x4 &matrix) = 0;
|
2010-03-05 20:42:10 +00:00
|
|
|
|
2010-03-08 20:45:58 +00:00
|
|
|
virtual void bind() = 0;
|
|
|
|
virtual void unbind() = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
float gaussian(float x, float sigma) const;
|
|
|
|
QVector<float> gaussianKernel() const;
|
2010-03-12 15:56:19 +00:00
|
|
|
void setIsValid(bool value) { mValid = value; }
|
2010-03-08 20:45:58 +00:00
|
|
|
virtual void init() = 0;
|
|
|
|
virtual void reset() = 0;
|
2010-03-10 18:16:18 +00:00
|
|
|
virtual int maxKernelSize() const = 0;
|
2010-03-08 20:45:58 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
int mRadius;
|
|
|
|
Qt::Orientation mDirection;
|
2010-03-12 15:56:19 +00:00
|
|
|
bool mValid;
|
2010-03-08 20:45:58 +00:00
|
|
|
};
|
2010-03-05 20:42:10 +00:00
|
|
|
|
2010-03-08 20:45:58 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GLSLBlurShader : public BlurShader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GLSLBlurShader();
|
|
|
|
~GLSLBlurShader();
|
|
|
|
|
|
|
|
void setPixelDistance(float val);
|
2010-03-05 20:42:10 +00:00
|
|
|
void bind();
|
|
|
|
void unbind();
|
2011-01-08 18:56:22 +00:00
|
|
|
void setTextureMatrix(const QMatrix4x4 &matrix);
|
2010-03-05 20:42:10 +00:00
|
|
|
|
2010-06-14 00:18:04 +00:00
|
|
|
static bool supported();
|
|
|
|
|
2010-03-08 20:45:58 +00:00
|
|
|
protected:
|
|
|
|
void init();
|
|
|
|
void reset();
|
2010-03-10 18:16:18 +00:00
|
|
|
int maxKernelSize() const;
|
2010-03-08 20:45:58 +00:00
|
|
|
|
2010-03-05 20:42:10 +00:00
|
|
|
private:
|
2011-01-08 18:56:22 +00:00
|
|
|
GLShader *shader;
|
2010-03-08 20:45:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ARBBlurShader : public BlurShader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ARBBlurShader();
|
|
|
|
~ARBBlurShader();
|
|
|
|
|
|
|
|
void setPixelDistance(float val);
|
|
|
|
void bind();
|
|
|
|
void unbind();
|
2011-01-08 18:56:22 +00:00
|
|
|
void setTextureMatrix(const QMatrix4x4 &) {};
|
2010-03-08 20:45:58 +00:00
|
|
|
|
2010-06-14 00:18:04 +00:00
|
|
|
static bool supported();
|
|
|
|
|
2010-03-08 20:45:58 +00:00
|
|
|
protected:
|
2010-03-05 20:42:10 +00:00
|
|
|
void init();
|
2010-03-08 20:45:58 +00:00
|
|
|
void reset();
|
2010-03-10 18:16:18 +00:00
|
|
|
int maxKernelSize() const;
|
2010-03-05 20:42:10 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
GLuint program;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace KWin
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|