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>
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
// 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;
|
2010-03-05 20:42:10 +00:00
|
|
|
|
|
|
|
// The opacity of the resulting pixels is multiplied by this value
|
2010-03-08 20:45:58 +00:00
|
|
|
virtual void setOpacity(float val) = 0;
|
|
|
|
|
|
|
|
virtual void bind() = 0;
|
|
|
|
virtual void unbind() = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
float gaussian(float x, float sigma) const;
|
|
|
|
QVector<float> gaussianKernel() const;
|
|
|
|
virtual void init() = 0;
|
|
|
|
virtual void reset() = 0;
|
|
|
|
|
|
|
|
private:
|
|
|
|
int mRadius;
|
|
|
|
Qt::Orientation mDirection;
|
|
|
|
};
|
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);
|
|
|
|
void setOpacity(float val);
|
2010-03-05 20:42:10 +00:00
|
|
|
void bind();
|
|
|
|
void unbind();
|
|
|
|
|
2010-03-08 20:45:58 +00:00
|
|
|
protected:
|
|
|
|
void init();
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
GLuint compile(GLenum type, const QByteArray &source);
|
|
|
|
GLuint link(GLuint vertexShader, GLuint fragmentShader);
|
|
|
|
|
2010-03-05 20:42:10 +00:00
|
|
|
private:
|
2010-03-08 20:45:58 +00:00
|
|
|
GLuint program;
|
|
|
|
int uTexUnit;
|
|
|
|
int uPixelSize;
|
|
|
|
int uOpacity;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ARBBlurShader : public BlurShader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ARBBlurShader();
|
|
|
|
~ARBBlurShader();
|
|
|
|
|
|
|
|
void setPixelDistance(float val);
|
|
|
|
void setOpacity(float val);
|
|
|
|
void bind();
|
|
|
|
void unbind();
|
|
|
|
|
|
|
|
protected:
|
2010-03-05 20:42:10 +00:00
|
|
|
void init();
|
2010-03-08 20:45:58 +00:00
|
|
|
void reset();
|
2010-03-05 20:42:10 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
GLuint program;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace KWin
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|