~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kwin/effects/blur/blurshader.h

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright © 2010 Fredrik Höglund <fredrik@kde.org>
 
3
 *
 
4
 *   This program is free software; you can redistribute it and/or modify
 
5
 *   it under the terms of the GNU General Public License as published by
 
6
 *   the Free Software Foundation; either version 2 of the License, or
 
7
 *   (at your option) any later version.
 
8
 *
 
9
 *   This program is distributed in the hope that it will be useful,
 
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 *   General Public License for more details.
 
13
 *
 
14
 *   You should have received a copy of the GNU General Public License
 
15
 *   along with this program; see the file COPYING.  if not, write to
 
16
 *   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
17
 *   Boston, MA 02110-1301, USA.
 
18
 */
 
19
 
 
20
#ifndef BLURSHADER_H
 
21
#define BLURSHADER_H
 
22
 
 
23
#include <kwinglutils.h>
 
24
 
 
25
class QMatrix4x4;
 
26
 
 
27
namespace KWin
 
28
{
 
29
 
 
30
class BlurShader
 
31
{
 
32
public:
 
33
    BlurShader();
 
34
    virtual ~BlurShader();
 
35
 
 
36
    static BlurShader *create();
 
37
 
 
38
    bool isValid() const {
 
39
        return mValid;
 
40
    }
 
41
 
 
42
    // Sets the radius in pixels
 
43
    void setRadius(int radius);
 
44
    int radius() const {
 
45
        return mRadius;
 
46
    }
 
47
 
 
48
    // Sets the blur direction
 
49
    void setDirection(Qt::Orientation direction);
 
50
    Qt::Orientation direction() const {
 
51
        return mDirection;
 
52
    }
 
53
 
 
54
    // Sets the distance between two pixels
 
55
    virtual void setPixelDistance(float val) = 0;
 
56
    virtual void setTextureMatrix(const QMatrix4x4 &matrix) = 0;
 
57
 
 
58
    virtual void bind() = 0;
 
59
    virtual void unbind() = 0;
 
60
 
 
61
protected:
 
62
    float gaussian(float x, float sigma) const;
 
63
    QVector<float> gaussianKernel() const;
 
64
    void setIsValid(bool value) {
 
65
        mValid = value;
 
66
    }
 
67
    virtual void init() = 0;
 
68
    virtual void reset() = 0;
 
69
    virtual int maxKernelSize() const = 0;
 
70
 
 
71
private:
 
72
    int mRadius;
 
73
    Qt::Orientation mDirection;
 
74
    bool mValid;
 
75
};
 
76
 
 
77
 
 
78
// ----------------------------------------------------------------------------
 
79
 
 
80
 
 
81
 
 
82
class GLSLBlurShader : public BlurShader
 
83
{
 
84
public:
 
85
    GLSLBlurShader();
 
86
    ~GLSLBlurShader();
 
87
 
 
88
    void setPixelDistance(float val);
 
89
    void bind();
 
90
    void unbind();
 
91
    void setTextureMatrix(const QMatrix4x4 &matrix);
 
92
 
 
93
    static bool supported();
 
94
 
 
95
protected:
 
96
    void init();
 
97
    void reset();
 
98
    int maxKernelSize() const;
 
99
 
 
100
private:
 
101
    GLShader *shader;
 
102
};
 
103
 
 
104
 
 
105
 
 
106
// ----------------------------------------------------------------------------
 
107
 
 
108
 
 
109
 
 
110
class ARBBlurShader : public BlurShader
 
111
{
 
112
public:
 
113
    ARBBlurShader();
 
114
    ~ARBBlurShader();
 
115
 
 
116
    void setPixelDistance(float val);
 
117
    void bind();
 
118
    void unbind();
 
119
    void setTextureMatrix(const QMatrix4x4 &) {};
 
120
 
 
121
    static bool supported();
 
122
 
 
123
protected:
 
124
    void init();
 
125
    void reset();
 
126
    int maxKernelSize() const;
 
127
 
 
128
private:
 
129
    GLuint program;
 
130
};
 
131
 
 
132
} // namespace KWin
 
133
 
 
134
#endif
 
135