Changeset View
Changeset View
Standalone View
Standalone View
effects/blur/blurshader.h
Show All 16 Lines | |||||
17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | * Boston, MA 02110-1301, USA. | 18 | * Boston, MA 02110-1301, USA. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #ifndef BLURSHADER_H | 21 | #ifndef BLURSHADER_H | ||
22 | #define BLURSHADER_H | 22 | #define BLURSHADER_H | ||
23 | 23 | | |||
24 | #include <kwinglutils.h> | 24 | #include <kwinglutils.h> | ||
25 | | ||||
26 | #include <QMatrix4x4> | ||||
27 | #include <QObject> | ||||
28 | #include <QScopedPointer> | ||||
25 | #include <QVector2D> | 29 | #include <QVector2D> | ||
26 | #include <QVector4D> | 30 | #include <QVector4D> | ||
27 | 31 | | |||
28 | | ||||
29 | class QMatrix4x4; | | |||
30 | | ||||
31 | namespace KWin | 32 | namespace KWin | ||
32 | { | 33 | { | ||
33 | 34 | | |||
34 | class BlurShader | 35 | class BlurShader : public QObject | ||
35 | { | 36 | { | ||
36 | public: | 37 | Q_OBJECT | ||
37 | BlurShader(); | | |||
38 | virtual ~BlurShader(); | | |||
39 | | ||||
40 | static BlurShader *create(); | | |||
41 | 38 | | |||
42 | bool isValid() const { | 39 | public: | ||
43 | return mValid; | 40 | BlurShader(QObject *parent = nullptr); | ||
44 | } | 41 | ~BlurShader() override; | ||
45 | 42 | | |||
46 | virtual void setModelViewProjectionMatrix(const QMatrix4x4 &matrix) = 0; | 43 | bool isValid() const; | ||
47 | virtual void setOffset(float offset) = 0; | | |||
48 | virtual void setTargetTextureSize(QSize renderTextureSize) = 0; | | |||
49 | virtual void setNoiseTextureSize(QSize noiseTextureSize) = 0; | | |||
50 | virtual void setTexturePosition(QPoint texPos) = 0; | | |||
51 | virtual void setBlurRect(QRect blurRect, QSize screenSize) = 0; | | |||
52 | 44 | | |||
53 | enum SampleType { | 45 | enum SampleType { | ||
54 | DownSampleType, | 46 | DownSampleType, | ||
55 | UpSampleType, | 47 | UpSampleType, | ||
56 | CopySampleType, | 48 | CopySampleType, | ||
57 | NoiseSampleType | 49 | NoiseSampleType | ||
58 | }; | 50 | }; | ||
59 | 51 | | |||
60 | virtual void bind(SampleType sampleType) = 0; | 52 | void bind(SampleType sampleType); | ||
61 | virtual void unbind() = 0; | 53 | void unbind(); | ||
62 | | ||||
63 | protected: | | |||
64 | void setIsValid(bool value) { | | |||
65 | mValid = value; | | |||
66 | } | | |||
67 | virtual void init() = 0; | | |||
68 | virtual void reset() = 0; | | |||
69 | | ||||
70 | private: | | |||
71 | bool mValid; | | |||
72 | }; | | |||
73 | | ||||
74 | | ||||
75 | // ---------------------------------------------------------------------------- | | |||
76 | | ||||
77 | | ||||
78 | | ||||
79 | class GLSLBlurShader : public BlurShader | | |||
80 | { | | |||
81 | public: | | |||
82 | GLSLBlurShader(); | | |||
83 | ~GLSLBlurShader(); | | |||
84 | 54 | | |||
85 | void bind(SampleType sampleType) override final; | 55 | void setModelViewProjectionMatrix(const QMatrix4x4 &matrix); | ||
86 | void unbind() override final; | 56 | void setOffset(float offset); | ||
87 | void setModelViewProjectionMatrix(const QMatrix4x4 &matrix) override final; | 57 | void setTargetTextureSize(const QSize &renderTextureSize); | ||
88 | void setOffset(float offset) override final; | 58 | void setNoiseTextureSize(const QSize &noiseTextureSize); | ||
89 | void setTargetTextureSize(QSize renderTextureSize) override final; | 59 | void setTexturePosition(const QPoint &texPos); | ||
90 | void setNoiseTextureSize(QSize noiseTextureSize) override final; | 60 | void setBlurRect(const QRect &blurRect, const QSize &screenSize); | ||
91 | void setTexturePosition(QPoint texPos) override final; | | |||
92 | void setBlurRect(QRect blurRect, QSize screenSize) override final; | | |||
93 | | ||||
94 | protected: | | |||
95 | void init() override final; | | |||
96 | void reset() override final; | | |||
97 | 61 | | |||
98 | private: | 62 | private: | ||
99 | GLShader *m_shaderDownsample = nullptr; | 63 | QScopedPointer<GLShader> m_shaderDownsample; | ||
100 | GLShader *m_shaderUpsample = nullptr; | 64 | QScopedPointer<GLShader> m_shaderUpsample; | ||
101 | GLShader *m_shaderCopysample = nullptr; | 65 | QScopedPointer<GLShader> m_shaderCopysample; | ||
102 | GLShader *m_shaderNoisesample = nullptr; | 66 | QScopedPointer<GLShader> m_shaderNoisesample; | ||
103 | 67 | | |||
104 | int m_mvpMatrixLocationDownsample; | 68 | int m_mvpMatrixLocationDownsample; | ||
105 | int m_offsetLocationDownsample; | 69 | int m_offsetLocationDownsample; | ||
106 | int m_renderTextureSizeLocationDownsample; | 70 | int m_renderTextureSizeLocationDownsample; | ||
107 | int m_halfpixelLocationDownsample; | 71 | int m_halfpixelLocationDownsample; | ||
108 | 72 | | |||
109 | int m_mvpMatrixLocationUpsample; | 73 | int m_mvpMatrixLocationUpsample; | ||
110 | int m_offsetLocationUpsample; | 74 | int m_offsetLocationUpsample; | ||
111 | int m_renderTextureSizeLocationUpsample; | 75 | int m_renderTextureSizeLocationUpsample; | ||
112 | int m_halfpixelLocationUpsample; | 76 | int m_halfpixelLocationUpsample; | ||
113 | 77 | | |||
114 | int m_mvpMatrixLocationCopysample; | 78 | int m_mvpMatrixLocationCopysample; | ||
115 | int m_renderTextureSizeLocationCopysample; | 79 | int m_renderTextureSizeLocationCopysample; | ||
116 | int m_blurRectLocationCopysample; | 80 | int m_blurRectLocationCopysample; | ||
117 | 81 | | |||
118 | int m_mvpMatrixLocationNoisesample; | 82 | int m_mvpMatrixLocationNoisesample; | ||
119 | int m_offsetLocationNoisesample; | 83 | int m_offsetLocationNoisesample; | ||
120 | int m_renderTextureSizeLocationNoisesample; | 84 | int m_renderTextureSizeLocationNoisesample; | ||
121 | int m_noiseTextureSizeLocationNoisesample; | 85 | int m_noiseTextureSizeLocationNoisesample; | ||
122 | int m_texStartPosLocationNoisesample; | 86 | int m_texStartPosLocationNoisesample; | ||
123 | int m_halfpixelLocationNoisesample; | 87 | int m_halfpixelLocationNoisesample; | ||
124 | 88 | | |||
125 | | ||||
126 | //Caching uniform values to aviod unnecessary setUniform calls | 89 | //Caching uniform values to aviod unnecessary setUniform calls | ||
127 | int m_activeSampleType; | 90 | int m_activeSampleType = -1; | ||
128 | 91 | | |||
129 | float m_offsetDownsample; | 92 | float m_offsetDownsample = 0.0; | ||
130 | QMatrix4x4 m_matrixDownsample; | 93 | QMatrix4x4 m_matrixDownsample; | ||
131 | 94 | | |||
132 | float m_offsetUpsample; | 95 | float m_offsetUpsample = 0.0; | ||
133 | QMatrix4x4 m_matrixUpsample; | 96 | QMatrix4x4 m_matrixUpsample; | ||
134 | 97 | | |||
135 | QMatrix4x4 m_matrixCopysample; | 98 | QMatrix4x4 m_matrixCopysample; | ||
136 | 99 | | |||
137 | float m_offsetNoisesample; | 100 | float m_offsetNoisesample = 0.0; | ||
138 | QVector2D m_noiseTextureSizeNoisesample; | 101 | QVector2D m_noiseTextureSizeNoisesample; | ||
139 | QMatrix4x4 m_matrixNoisesample; | 102 | QMatrix4x4 m_matrixNoisesample; | ||
140 | 103 | | |||
104 | bool m_valid = false; | ||||
105 | | ||||
106 | Q_DISABLE_COPY(BlurShader); | ||||
141 | }; | 107 | }; | ||
142 | 108 | | |||
109 | inline bool BlurShader::isValid() const | ||||
110 | { | ||||
111 | return m_valid; | ||||
112 | } | ||||
113 | | ||||
143 | } // namespace KWin | 114 | } // namespace KWin | ||
144 | 115 | | |||
145 | #endif | 116 | #endif |