Changeset View
Standalone View
effects/blur/blur.cpp
| Show All 20 Lines | |||||
| 21 | #include "blur.h" | 21 | #include "blur.h" | ||
| 22 | #include "effects.h" | 22 | #include "effects.h" | ||
| 23 | #include "blurshader.h" | 23 | #include "blurshader.h" | ||
| 24 | // KConfigSkeleton | 24 | // KConfigSkeleton | ||
| 25 | #include "blurconfig.h" | 25 | #include "blurconfig.h" | ||
| 26 | 26 | | |||
| 27 | #include <QMatrix4x4> | 27 | #include <QMatrix4x4> | ||
| 28 | #include <QLinkedList> | 28 | #include <QLinkedList> | ||
| 29 | 29 | | |||
fredrik: Is this still needed when qPow() is not used? | |||||
fredrik: Nitpick, but it should be <cmath> and std::ceil() in C++. | |||||
| 30 | #include <KWayland/Server/surface_interface.h> | 30 | #include <KWayland/Server/surface_interface.h> | ||
| 31 | #include <KWayland/Server/blur_interface.h> | 31 | #include <KWayland/Server/blur_interface.h> | ||
| 32 | #include <KWayland/Server/shadow_interface.h> | 32 | #include <KWayland/Server/shadow_interface.h> | ||
| 33 | #include <KWayland/Server/display.h> | 33 | #include <KWayland/Server/display.h> | ||
| 34 | 34 | | |||
| 35 | #define BORDER_SIZE 5 | ||||
romangg: `static const` and in the KWin namespace please. Also camel case then. | |||||
| 36 | | ||||
| 35 | namespace KWin | 37 | namespace KWin | ||
| 36 | { | 38 | { | ||
| 37 | 39 | | |||
| 38 | static const QByteArray s_blurAtomName = QByteArrayLiteral("_KDE_NET_WM_BLUR_BEHIND_REGION"); | 40 | static const QByteArray s_blurAtomName = QByteArrayLiteral("_KDE_NET_WM_BLUR_BEHIND_REGION"); | ||
| 39 | 41 | | |||
| 40 | BlurEffect::BlurEffect() | 42 | BlurEffect::BlurEffect() | ||
| 41 | { | 43 | { | ||
| 42 | initConfig<BlurConfig>(); | 44 | initConfig<BlurConfig>(); | ||
| 43 | shader = BlurShader::create(); | 45 | shader = BlurShader::create(); | ||
| 44 | m_simpleShader = ShaderManager::instance()->generateShaderFromResources(ShaderTrait::MapTexture, QString(), QStringLiteral("logout-blur.frag")); | 46 | m_simpleShader = ShaderManager::instance()->generateShaderFromResources(ShaderTrait::MapTexture, QString(), QStringLiteral("logout-blur.frag")); | ||
| 47 | m_simpleTarget = new GLRenderTarget(GLTexture(GL_RGBA8, 1, 1)); | ||||
You should add a GLRenderTarget constructor that takes no arguments. fredrik: You should add a GLRenderTarget constructor that takes no arguments.
This is working around… | |||||
| 48 | | ||||
| 45 | if (!m_simpleShader->isValid()) { | 49 | if (!m_simpleShader->isValid()) { | ||
| 46 | qCDebug(KWINEFFECTS) << "Simple blur shader failed to load"; | 50 | qCDebug(KWINEFFECTS) << "Simple blur shader failed to load"; | ||
| 47 | } | 51 | } | ||
| 48 | 52 | | |||
| 49 | updateTexture(); | 53 | initBlurStrengthData(); | ||
| 50 | reconfigure(ReconfigureAll); | 54 | reconfigure(ReconfigureAll); | ||
| 51 | 55 | | |||
| 52 | // ### Hackish way to announce support. | 56 | // ### Hackish way to announce support. | ||
| 53 | // Should be included in _NET_SUPPORTED instead. | 57 | // Should be included in _NET_SUPPORTED instead. | ||
| 54 | if (shader && shader->isValid() && target->valid()) { | 58 | if (shader && shader->isValid() && renderTargetsValid()) { | ||
| 55 | net_wm_blur_region = effects->announceSupportProperty(s_blurAtomName, this); | 59 | net_wm_blur_region = effects->announceSupportProperty(s_blurAtomName, this); | ||
| 56 | KWayland::Server::Display *display = effects->waylandDisplay(); | 60 | KWayland::Server::Display *display = effects->waylandDisplay(); | ||
| 57 | if (display) { | 61 | if (display) { | ||
| 58 | m_blurManager = display->createBlurManager(this); | 62 | m_blurManager = display->createBlurManager(this); | ||
| 59 | m_blurManager->create(); | 63 | m_blurManager->create(); | ||
| 60 | } | 64 | } | ||
| 61 | } else { | 65 | } else { | ||
| 62 | net_wm_blur_region = 0; | 66 | net_wm_blur_region = 0; | ||
| 63 | } | 67 | } | ||
| 64 | 68 | | |||
| 65 | connect(effects, SIGNAL(windowAdded(KWin::EffectWindow*)), this, SLOT(slotWindowAdded(KWin::EffectWindow*))); | 69 | connect(effects, SIGNAL(windowAdded(KWin::EffectWindow*)), this, SLOT(slotWindowAdded(KWin::EffectWindow*))); | ||
| 66 | connect(effects, SIGNAL(windowDeleted(KWin::EffectWindow*)), this, SLOT(slotWindowDeleted(KWin::EffectWindow*))); | 70 | connect(effects, SIGNAL(windowDeleted(KWin::EffectWindow*)), this, SLOT(slotWindowDeleted(KWin::EffectWindow*))); | ||
| 67 | connect(effects, SIGNAL(propertyNotify(KWin::EffectWindow*,long)), this, SLOT(slotPropertyNotify(KWin::EffectWindow*,long))); | 71 | connect(effects, SIGNAL(propertyNotify(KWin::EffectWindow*,long)), this, SLOT(slotPropertyNotify(KWin::EffectWindow*,long))); | ||
| 68 | connect(effects, SIGNAL(screenGeometryChanged(QSize)), this, SLOT(slotScreenGeometryChanged())); | 72 | connect(effects, SIGNAL(screenGeometryChanged(QSize)), this, SLOT(slotScreenGeometryChanged())); | ||
| 69 | connect(effects, &EffectsHandler::xcbConnectionChanged, this, | 73 | connect(effects, &EffectsHandler::xcbConnectionChanged, this, | ||
| 70 | [this] { | 74 | [this] { | ||
| 71 | if (shader && shader->isValid() && target->valid()) { | 75 | if (shader && shader->isValid() && renderTargetsValid()) { | ||
| 72 | net_wm_blur_region = effects->announceSupportProperty(s_blurAtomName, this); | 76 | net_wm_blur_region = effects->announceSupportProperty(s_blurAtomName, this); | ||
| 73 | } | 77 | } | ||
| 74 | } | 78 | } | ||
| 75 | ); | 79 | ); | ||
| 76 | 80 | | |||
| 77 | // Fetch the blur regions for all windows | 81 | // Fetch the blur regions for all windows | ||
| 78 | foreach (EffectWindow *window, effects->stackingOrder()) | 82 | foreach (EffectWindow *window, effects->stackingOrder()) | ||
| 79 | updateBlurRegion(window); | 83 | updateBlurRegion(window); | ||
| 80 | } | 84 | } | ||
| 81 | 85 | | |||
| 82 | BlurEffect::~BlurEffect() | 86 | BlurEffect::~BlurEffect() | ||
| 83 | { | 87 | { | ||
| 84 | windows.clear(); | 88 | windows.clear(); | ||
| 85 | 89 | | |||
| 86 | delete m_simpleShader; | 90 | delete m_simpleShader; | ||
| 91 | m_simpleShader = NULL; | ||||
| 92 | | ||||
zzag: Please use `nullptr`. | |||||
| 87 | delete shader; | 93 | delete shader; | ||
davidedmundson: m_simpleTarget needs deleting | |||||
| 88 | delete target; | 94 | shader = NULL; | ||
anthonyfieroni: m_simpleTarget should be deleted too | |||||
| 95 | | ||||
| 96 | for (int i = 0; i < renderTargets.size(); i++) { | ||||
| 97 | delete renderTargets[i]; | ||||
zzag: Please use `nullptr`. | |||||
| 98 | renderTargets[i] = NULL; | ||||
| 99 | | ||||
| 100 | renderTextures[i].discard(); | ||||
| 101 | } | ||||
| 102 | | ||||
| 103 | renderTargets.clear(); | ||||
| 104 | renderTextures.clear(); | ||||
anthonyfieroni: Make a function that clears them. | |||||
zzag: Please use `nullptr`. | |||||
| 89 | } | 105 | } | ||
| 90 | 106 | | |||
| 91 | void BlurEffect::slotScreenGeometryChanged() | 107 | void BlurEffect::slotScreenGeometryChanged() | ||
| 92 | { | 108 | { | ||
| 93 | effects->makeOpenGLContextCurrent(); | 109 | effects->makeOpenGLContextCurrent(); | ||
| 94 | updateTexture(); | 110 | updateTexture(); | ||
| 95 | // Fetch the blur regions for all windows | 111 | // Fetch the blur regions for all windows | ||
| 96 | foreach (EffectWindow *window, effects->stackingOrder()) | 112 | foreach (EffectWindow *window, effects->stackingOrder()) | ||
| 97 | updateBlurRegion(window); | 113 | updateBlurRegion(window); | ||
| 98 | effects->doneOpenGLContextCurrent(); | 114 | effects->doneOpenGLContextCurrent(); | ||
| 99 | } | 115 | } | ||
| 100 | 116 | | |||
| 101 | void BlurEffect::updateTexture() { | 117 | bool BlurEffect::renderTargetsValid() | ||
anthonyfieroni: Make it const. | |||||
| 102 | delete target; | 118 | { | ||
| 103 | // Offscreen texture that's used as the target for the horizontal blur pass | 119 | if (renderTargets.isEmpty()) { | ||
| 104 | // and the source for the vertical pass. | 120 | return false; | ||
| 105 | tex = GLTexture(GL_RGBA8, effects->virtualScreenSize()); | 121 | } | ||
| 106 | tex.setFilter(GL_LINEAR); | 122 | | ||
I suggest doing this check after creating the render targets, and caching the result. fredrik: I suggest doing this check after creating the render targets, and caching the result. | |||||
| 107 | tex.setWrapMode(GL_CLAMP_TO_EDGE); | 123 | for (int i = 0; i < renderTargets.size(); i++) { | ||
| 124 | if (!renderTargets[i]->valid()) { | ||||
| 125 | return false; | ||||
| 126 | } | ||||
| 127 | } | ||||
fredrik: You can use qDeleteAll() here. | |||||
| 128 | | ||||
| 129 | return true; | ||||
You can minimize it return !renderTargets.isEmpty()
&& std::find_if(renderTargets.cbegin(), renderTargets.cend(), [](const GLRenderTarget *target) {
return !target->valid(); }) == renderTarget.cend();anthonyfieroni: You can minimize it
```
return !renderTargets.isEmpty()
&& std::find_if(renderTargets. | |||||
zzag: `nullptr` | |||||
| 130 | } | ||||
| 131 | void BlurEffect::initBlurStrengthData() | ||||
fredrik: There is no need to call discard on the textures - just clear the vector. | |||||
| 132 | { | ||||
| 133 | /** | ||||
| 134 | * Explanation for the magic numbers: | ||||
| 135 | * | ||||
| 136 | * The texture blur amount is depends on the downsampling iterations and the offset value. | ||||
| 137 | * By changing the offset we can alter the blur amount without relying on further downsampling. | ||||
| 138 | * But there is a maximum value of offset per downsample iteration before we get artifacts. | ||||
| 139 | * For example the maximum value of offset before there is almost clearly visible artifacts: | ||||
| 140 | * - for 1 iteration is 2 | ||||
| 141 | * - for 2 iterations is 4 | ||||
fredrik: Call reserve() on m_renderTextures and m_renderTargets here. | |||||
| 142 | * - for 3 iterations is 8 | ||||
| 143 | * | ||||
romangg: The texture blur amount depends | |||||
fredrik: 1 << i | |||||
| 144 | * For good amount of blur (at current common resolutions) we need at least 4 iterations. | ||||
| 145 | * Offset value of 1 on 4 iterations is still too much blur to consider it using it as minimum. | ||||
| 146 | * This means we can't have constant iteration value. | ||||
| 147 | * If we left the offset value constant and only changed the iteration number then we would | ||||
| 148 | * have good minimum and maximum blur amount, but there would be around only 5 blur strength | ||||
| 149 | * steps. | ||||
| 150 | * This means we can't have constant offset value. | ||||
| 151 | * As a compromise we have to use hardcoded magic numbers. This works for common resolutions. | ||||
Why is this needed? I'm probably missing something here, but it looks to me as if the effect copies the contents of the framebuffer to the helper texture, then copies the contents of that texture to m_renderTextures[0], after which the contents of helper texture is not used again. Can't copyScreenSampleTexture() copy directly from the framebuffer to m_renderTextures[0]? fredrik: Why is this needed?
I'm probably missing something here, but it looks to me as if the effect… | |||||
This texture is only used by copyScreenSampleTexture() For example if we want to blur a window (red) we have to blur a bigger area. To avoid extended blur I use the copySample shader to create a GL_CLAMP_TO_EDGE effect (blue) when copying the texture from m_renderTextures.last() to m_renderTextures[0] Ideally we could specify to only disable extended blur on the taskbar, but I don't see a way to identify a window as the taskbar. anemeth: This texture is only used by `copyScreenSampleTexture()`
It could very well be a separate… | |||||
Okay, I see what you mean. I think this is a trade-off between two undesirable effects though, because the clamping causes abrupt changes near the edges of the blurred region when a window is moved. You can see this effect pretty clearly in the video you attached when the blur strength is set to strong. It really comes down to what you think is worse though. But my concern here is that a fullscreen texture consumes at least 8 MB of VRAM with an HD monitor, and 32 MB with a 4K monitor. I think it would be better to copy the framebuffer to m_renderTexture[0], and apply the clamping as a post-processing effect, using m_renderTexture[0] as both the source and destination, and targeting only the region outside the red rectangle for rendering. Using the same texture as both the source and destination is allowed in OpenGL when GL_ARB_texture_barrier or GL_NV_texture_barrier is supported, but unfortunately not in OpenGL ES. The taskbar (and other panels) can be identified by calling EffectWindow::isDock(). fredrik: Okay, I see what you mean. I think this is a trade-off between two undesirable effects though… | |||||
Now only the taskbar doesn't have the extended blur effect. GL_ARB_texture_barrier is supported since OpenGL 4.4, but KWin uses 3.0 I guess it's an unpopular opinion, but it's "only" 8 MB and since cards these days have at least like 1 GB of VRAM it's not a big concern. How do you suggest we handle this? anemeth: Now only the taskbar doesn't have the extended blur effect.
GL_ARB_texture_barrier is… | |||||
I checked if I have these extensions. Just to make sure it works I included another extension I know my card supports. qCDebug(KWINEFFECTS) << "NV_texture_barrier:" << hasGLExtension("NV_texture_barrier");
qCDebug(KWINEFFECTS) << "ARB_texture_barrier:" << hasGLExtension("ARB_texture_barrier");
qCDebug(KWINEFFECTS) << "GL_NV_texgen_reflection:" << hasGLExtension("GL_NV_texgen_reflection");And the output: kwineffects: NV_texture_barrier: false kwineffects: ARB_texture_barrier: false kwineffects: GL_NV_texgen_reflection: true If this works so unreliably I don't think we should use this. anemeth: I checked if I have these extensions. Just to make sure it works I included another extension I… | |||||
Ok I realize now that the extension name begins with GL_ and this is the reason it didn't find them. The red arrow is where they should be but they aren't present. So my point still stands. anemeth: Ok I realize now that the extension name begins with GL_ and this is the reason it didn't find… | |||||
The 3.1 backend can and does use some GL 4 extensions, but it must have a fallback path for when they are not available. The NV prefix only tells you which vendor created the extension, not which vendors support it. The AMD drivers in Mesa have supported texture_barrier since 2011, and the i965 driver has supported it since 2015. But as I said on IRC, don't worry about it if your driver doesn't support it. We can add a path that uses texture_barrier after this has landed. fredrik: > GL_ARB_texture_barrier is supported since OpenGL 4.4, but KWin uses 3.0
>… | |||||
| 152 | * In the future as we enter the age of high resolution monitors (8K and above) we have to | ||||
| 153 | * either increase the iterations or add more blur strength steps with increased iterations. | ||||
| 154 | * For now it would be pointless to add more blur strength, as the currently defined maximum | ||||
| 155 | * is (in my opinion) more than enough. | ||||
| 156 | **/ | ||||
I think 5 blur strength steps to select from is fine, if that means we can get rid off the magic numbers. Other opinions? romangg: I think 5 blur strength steps to select from is fine, if that means we can get rid off the… | |||||
anemeth: I'm working on a nicer solution with less magical numbers. | |||||
| 157 | | ||||
| 158 | // Dummy data needed, because the blur strength range is 1-15 | ||||
| 159 | blurConfigData.append({0, 0, 0}); | ||||
| 160 | | ||||
| 161 | blurConfigData.append({1, 1, 5}); | ||||
| 162 | blurConfigData.append({2, 1, 10}); | ||||
| 163 | blurConfigData.append({2, 2, 15}); | ||||
| 164 | blurConfigData.append({2, 3, 25}); | ||||
| 165 | blurConfigData.append({2, 4, 30}); | ||||
| 166 | blurConfigData.append({3, 3, 40}); | ||||
| 167 | blurConfigData.append({3, 4, 50}); | ||||
| 168 | blurConfigData.append({3, 5, 60}); | ||||
| 169 | blurConfigData.append({3, 6, 80}); | ||||
| 170 | blurConfigData.append({3, 7, 100}); | ||||
| 171 | blurConfigData.append({3, 8, 120}); | ||||
| 172 | blurConfigData.append({4, 5, 140}); | ||||
| 173 | blurConfigData.append({4, 6, 155}); | ||||
| 174 | blurConfigData.append({4, 7, 170}); | ||||
| 175 | blurConfigData.append({4, 8, 200}); | ||||
| 176 | } | ||||
| 177 | | ||||
| 178 | void BlurEffect::updateTexture() | ||||
| 179 | { | ||||
| 180 | for (int i = 0; i < renderTargets.size(); i++) { | ||||
| 181 | delete renderTargets[i]; | ||||
| 182 | renderTargets[i] = NULL; | ||||
| 183 | | ||||
| 184 | renderTextures[i].discard(); | ||||
| 185 | } | ||||
| 186 | | ||||
davidedmundson: m_simpleTarget no longer gets updated on screen changes. | |||||
What do you mean by this? anemeth: What do you mean by this?
m_simpleTarget works independently form the vector of rendertargets. | |||||
| 187 | renderTargets.clear(); | ||||
| 188 | renderTextures.clear(); | ||||
anthonyfieroni: Use same function from above. | |||||
| 189 | | ||||
| 190 | for (int i = 0; i <= m_downSampleIterations; i++) { | ||||
| 191 | renderTextures.append(GLTexture(GL_RGBA8, effects->virtualScreenSize() / qPow(2, i))); | ||||
| 192 | renderTextures.last().setFilter(GL_LINEAR); | ||||
| 193 | renderTextures.last().setWrapMode(GL_CLAMP_TO_EDGE); | ||||
| 194 | | ||||
zzag: Where did they come from? | |||||
I came up with these numbers by testing different iteration and offset values. anemeth: I came up with these numbers by testing different iteration and offset values. | |||||
| 195 | renderTargets.append(new GLRenderTarget(renderTextures.last())); | ||||
| 196 | } | ||||
All this data is constant, so it doesn't make sense to reinitialize it on every Blur instantiation and it is only a helper for reconfigure. Maybe instead as static const in the file? See here how to do it for a QVector: https://forum.qt.io/topic/32353/solved-creating-a-const-qvector-with-values romangg: All this data is constant, so it doesn't make sense to reinitialize it on every Blur… | |||||
fredrik: Typo: iteratoin | |||||
| 197 | | ||||
| 198 | // This last set is used as a temporary helper texture | ||||
| 199 | renderTextures.append(GLTexture(GL_RGBA8, effects->virtualScreenSize())); | ||||
| 200 | renderTextures.last().setFilter(GL_LINEAR); | ||||
| 201 | renderTextures.last().setWrapMode(GL_CLAMP_TO_EDGE); | ||||
| 108 | 202 | | |||
| 109 | target = new GLRenderTarget(tex); | 203 | renderTargets.append(new GLRenderTarget(renderTextures.last())); | ||
| 110 | } | 204 | } | ||
| 111 | 205 | | |||
| 112 | void BlurEffect::reconfigure(ReconfigureFlags flags) | 206 | void BlurEffect::reconfigure(ReconfigureFlags flags) | ||
| 113 | { | 207 | { | ||
| 114 | Q_UNUSED(flags) | 208 | Q_UNUSED(flags) | ||
| 115 | 209 | | |||
| 116 | BlurConfig::self()->read(); | 210 | BlurConfig::self()->read(); | ||
| 117 | int radius = qBound(2, BlurConfig::blurRadius(), 14); | | |||
| 118 | if (shader) | | |||
| 119 | shader->setRadius(radius); | | |||
| 120 | 211 | | |||
| 121 | m_shouldCache = BlurConfig::cacheTexture(); | 212 | m_shouldCache = BlurConfig::cacheTexture(); | ||
| 213 | m_useSimpleBlur = BlurConfig::useSimpleBlur(); | ||||
| 214 | | ||||
| 215 | int blurStrength = BlurConfig::blurRadius(); | ||||
Just a naming thing: maybe it should be blurRadius.. So, for given blur radius blurRadius lookup corresponding "Dual filter" params in a map (BlurRadius -> BlurParams). zzag: Just a naming thing: maybe it should be `blurRadius`.. So, for given blur radius `blurRadius`… | |||||
romangg: You need to guard against out of bounds values. | |||||
| 216 | m_downSampleIterations = blurConfigData[blurStrength].downSampleIterations; | ||||
| 217 | m_offset = blurConfigData[blurStrength].offset; | ||||
| 218 | m_expandSize = blurConfigData[blurStrength].expandSize; | ||||
| 219 | | ||||
Please add a comment explaining each number(e.g. the first number is the number of downsampling and upsampling iterations, and so on). Just for readability. zzag: Please add a comment explaining each number(e.g. the first number is the number of downsampling… | |||||
| 220 | updateTexture(); | ||||
| 122 | 221 | | |||
| 123 | windows.clear(); | 222 | windows.clear(); | ||
| 124 | 223 | | |||
| 125 | if (!shader || !shader->isValid()) { | 224 | if (!shader || !shader->isValid()) { | ||
| 126 | effects->removeSupportProperty(s_blurAtomName, this); | 225 | effects->removeSupportProperty(s_blurAtomName, this); | ||
| 127 | delete m_blurManager; | 226 | delete m_blurManager; | ||
| 128 | m_blurManager = nullptr; | 227 | m_blurManager = nullptr; | ||
| 129 | } | 228 | } | ||
| 130 | } | 229 | } | ||
| 131 | 230 | | |||
| 132 | void BlurEffect::updateBlurRegion(EffectWindow *w) const | 231 | void BlurEffect::updateBlurRegion(EffectWindow *w) const | ||
| 133 | { | 232 | { | ||
fredrik: Does calling effects->addRepaintFull() also work? | |||||
anemeth: It does.
Changed to that. | |||||
| 134 | QRegion region; | 233 | QRegion region; | ||
| 135 | QByteArray value; | 234 | QByteArray value; | ||
| 136 | 235 | | |||
| 137 | if (net_wm_blur_region != XCB_ATOM_NONE) { | 236 | if (net_wm_blur_region != XCB_ATOM_NONE) { | ||
| 138 | value = w->readProperty(net_wm_blur_region, XCB_ATOM_CARDINAL, 32); | 237 | value = w->readProperty(net_wm_blur_region, XCB_ATOM_CARDINAL, 32); | ||
| 139 | if (value.size() > 0 && !(value.size() % (4 * sizeof(uint32_t)))) { | 238 | if (value.size() > 0 && !(value.size() % (4 * sizeof(uint32_t)))) { | ||
| 140 | const uint32_t *cardinals = reinterpret_cast<const uint32_t*>(value.constData()); | 239 | const uint32_t *cardinals = reinterpret_cast<const uint32_t*>(value.constData()); | ||
| 141 | for (unsigned int i = 0; i < value.size() / sizeof(uint32_t);) { | 240 | for (unsigned int i = 0; i < value.size() / sizeof(uint32_t);) { | ||
| ▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Line(s) | 319 | if (supported) { | |||
| 225 | if (screenSize.width() > maxTexSize || screenSize.height() > maxTexSize) | 324 | if (screenSize.width() > maxTexSize || screenSize.height() > maxTexSize) | ||
| 226 | supported = false; | 325 | supported = false; | ||
| 227 | } | 326 | } | ||
| 228 | return supported; | 327 | return supported; | ||
| 229 | } | 328 | } | ||
| 230 | 329 | | |||
| 231 | QRect BlurEffect::expand(const QRect &rect) const | 330 | QRect BlurEffect::expand(const QRect &rect) const | ||
| 232 | { | 331 | { | ||
| 233 | const int radius = shader->radius(); | 332 | return rect.adjusted(-m_expandSize, -m_expandSize, m_expandSize, m_expandSize); | ||
| 234 | return rect.adjusted(-radius, -radius, radius, radius); | | |||
| 235 | } | 333 | } | ||
| 236 | 334 | | |||
| 237 | QRegion BlurEffect::expand(const QRegion ®ion) const | 335 | QRegion BlurEffect::expand(const QRegion ®ion) const | ||
| 238 | { | 336 | { | ||
| 239 | QRegion expanded; | 337 | QRegion expanded; | ||
| 240 | 338 | | |||
| 241 | for (const QRect &rect : region) { | 339 | for (const QRect &rect : region) { | ||
| 242 | expanded += expand(rect); | 340 | expanded += expand(rect); | ||
| Show All 26 Lines | 365 | } else if (w->decorationHasAlpha() && effects->decorationSupportsBlurBehind()) { | |||
| 269 | // the effect behind the decoration. | 367 | // the effect behind the decoration. | ||
| 270 | region = w->shape(); | 368 | region = w->shape(); | ||
| 271 | region -= w->decorationInnerRect(); | 369 | region -= w->decorationInnerRect(); | ||
| 272 | } | 370 | } | ||
| 273 | 371 | | |||
| 274 | return region; | 372 | return region; | ||
| 275 | } | 373 | } | ||
| 276 | 374 | | |||
| 277 | void BlurEffect::uploadRegion(QVector2D *&map, const QRegion ®ion) | 375 | void BlurEffect::uploadRegion(QVector2D *&map, const QRegion ®ion, const int downSampleIterations) | ||
| 278 | { | 376 | { | ||
| 377 | for (int i = 0; i <= downSampleIterations; i++) { | ||||
| 378 | const int divisionRatio = qPow(2, i); | ||||
fredrik: 1 << i | |||||
| 379 | | ||||
| 279 | for (const QRect &r : region) { | 380 | for (const QRect &r : region) { | ||
| 280 | const QVector2D topLeft(r.x(), r.y()); | 381 | const QVector2D topLeft( r.x() / divisionRatio, r.y() / divisionRatio); | ||
| 281 | const QVector2D topRight(r.x() + r.width(), r.y()); | 382 | const QVector2D topRight( (r.x() + r.width()) / divisionRatio, r.y() / divisionRatio); | ||
| 282 | const QVector2D bottomLeft(r.x(), r.y() + r.height()); | 383 | const QVector2D bottomLeft( r.x() / divisionRatio, (r.y() + r.height()) / divisionRatio); | ||
| 283 | const QVector2D bottomRight(r.x() + r.width(), r.y() + r.height()); | 384 | const QVector2D bottomRight((r.x() + r.width()) / divisionRatio, (r.y() + r.height()) / divisionRatio); | ||
| 284 | 385 | | |||
| 285 | // First triangle | 386 | // First triangle | ||
| 286 | *(map++) = topRight; | 387 | *(map++) = topRight; | ||
| 287 | *(map++) = topLeft; | 388 | *(map++) = topLeft; | ||
| 288 | *(map++) = bottomLeft; | 389 | *(map++) = bottomLeft; | ||
| 289 | 390 | | |||
| 290 | // Second triangle | 391 | // Second triangle | ||
| 291 | *(map++) = bottomLeft; | 392 | *(map++) = bottomLeft; | ||
| 292 | *(map++) = bottomRight; | 393 | *(map++) = bottomRight; | ||
| 293 | *(map++) = topRight; | 394 | *(map++) = topRight; | ||
| 294 | } | 395 | } | ||
| 295 | } | 396 | } | ||
| 397 | } | ||||
| 296 | 398 | | |||
| 297 | void BlurEffect::uploadGeometry(GLVertexBuffer *vbo, const QRegion &horizontal, const QRegion &vertical) | 399 | void BlurEffect::uploadGeometry(GLVertexBuffer *vbo, const QRegion &blurRegion, const QRegion &renderRegion, const QRegion &windowRegion) | ||
| 298 | { | 400 | { | ||
| 299 | const int vertexCount = (horizontal.rectCount() + vertical.rectCount()) * 6; | 401 | const int vertexCount = ((blurRegion.rectCount() * (m_downSampleIterations + 1)) + renderRegion.rectCount() + windowRegion.rectCount()) * 6; | ||
| 402 | | ||||
| 300 | if (!vertexCount) | 403 | if (!vertexCount) | ||
| 301 | return; | 404 | return; | ||
| 302 | 405 | | |||
| 303 | QVector2D *map = (QVector2D *) vbo->map(vertexCount * sizeof(QVector2D)); | 406 | QVector2D *map = (QVector2D *) vbo->map(vertexCount * sizeof(QVector2D)); | ||
| 304 | uploadRegion(map, horizontal); | 407 | | ||
| 305 | uploadRegion(map, vertical); | 408 | uploadRegion(map, blurRegion, m_downSampleIterations); | ||
| 409 | uploadRegion(map, renderRegion, 0); | ||||
| 410 | uploadRegion(map, windowRegion, 0); | ||||
| 411 | | ||||
| 306 | vbo->unmap(); | 412 | vbo->unmap(); | ||
| 307 | 413 | | |||
| 308 | const GLVertexAttrib layout[] = { | 414 | const GLVertexAttrib layout[] = { | ||
| 309 | { VA_Position, 2, GL_FLOAT, 0 }, | 415 | { VA_Position, 2, GL_FLOAT, 0 }, | ||
| 310 | { VA_TexCoord, 2, GL_FLOAT, 0 } | 416 | { VA_TexCoord, 2, GL_FLOAT, 0 } | ||
| 311 | }; | 417 | }; | ||
| 312 | 418 | | |||
| 313 | vbo->setAttribLayout(layout, 2, sizeof(QVector2D)); | 419 | vbo->setAttribLayout(layout, 2, sizeof(QVector2D)); | ||
| Show All 19 Lines | 432 | { | |||
| 333 | } | 439 | } | ||
| 334 | if (!shader || !shader->isValid()) { | 440 | if (!shader || !shader->isValid()) { | ||
| 335 | return; | 441 | return; | ||
| 336 | } | 442 | } | ||
| 337 | 443 | | |||
| 338 | // to blur an area partially we have to shrink the opaque area of a window | 444 | // to blur an area partially we have to shrink the opaque area of a window | ||
| 339 | QRegion newClip; | 445 | QRegion newClip; | ||
| 340 | const QRegion oldClip = data.clip; | 446 | const QRegion oldClip = data.clip; | ||
| 341 | const int radius = shader->radius(); | | |||
| 342 | for (const QRect &rect : data.clip) { | 447 | for (const QRect &rect : data.clip) { | ||
| 343 | newClip |= rect.adjusted(radius,radius,-radius,-radius); | 448 | newClip |= rect.adjusted(m_expandSize, m_expandSize, -m_expandSize, -m_expandSize); | ||
| 344 | } | 449 | } | ||
| 345 | data.clip = newClip; | 450 | data.clip = newClip; | ||
| 346 | 451 | | |||
| 347 | const QRegion oldPaint = data.paint; | 452 | const QRegion oldPaint = data.paint; | ||
| 348 | 453 | | |||
| 349 | // we don't have to blur a region we don't see | 454 | // we don't have to blur a region we don't see | ||
| 350 | m_currentBlur -= newClip; | 455 | m_currentBlur -= newClip; | ||
| 351 | // if we have to paint a non-opaque part of this window that intersects with the | 456 | // if we have to paint a non-opaque part of this window that intersects with the | ||
| 352 | // currently blurred region (which is not cached) we have to redraw the whole region | 457 | // currently blurred region (which is not cached) we have to redraw the whole region | ||
| 353 | if ((data.paint-oldClip).intersects(m_currentBlur)) { | 458 | if ((data.paint-oldClip).intersects(m_currentBlur)) { | ||
| 354 | data.paint |= m_currentBlur; | 459 | data.paint |= m_currentBlur; | ||
| 355 | } | 460 | } | ||
| 356 | 461 | | |||
| 357 | // in case this window has regions to be blurred | 462 | // in case this window has regions to be blurred | ||
| 358 | const QRect screen = effects->virtualScreenGeometry(); | 463 | const QRect screen = effects->virtualScreenGeometry(); | ||
| 359 | const QRegion blurArea = blurRegion(w).translated(w->pos()) & screen; | 464 | const QRegion blurArea = blurRegion(w).translated(w->pos()) & screen; | ||
| 360 | const QRegion expandedBlur = expand(blurArea) & screen; | 465 | const QRegion expandedBlur = expand(blurArea) & screen; | ||
| 361 | 466 | | |||
| 362 | if (m_shouldCache && !w->isDeleted()) { | 467 | if (m_shouldCache && !w->isDeleted()) { | ||
| 363 | // we are caching the horizontally blurred background texture | 468 | // we are caching the blurred background texture | ||
| 364 | 469 | | |||
| 365 | // if a window underneath the blurred area is damaged we have to | 470 | // if a window underneath the blurred area is damaged we have to | ||
| 366 | // update the cached texture | 471 | // update the cached texture | ||
| 367 | QRegion damagedCache; | 472 | QRegion damagedCache; | ||
| 368 | CacheEntry it = windows.find(w); | 473 | CacheEntry it = windows.find(w); | ||
| 369 | if (it != windows.end() && !it->dropCache && | 474 | if (it != windows.end() && !it->dropCache && | ||
| 370 | it->windowPos == w->pos() && | 475 | it->windowPos == w->pos() && | ||
| 371 | it->blurredBackground.size() == expandedBlur.boundingRect().size()) { | 476 | it->windowSize == expandedBlur.boundingRect().size()) { | ||
| 372 | damagedCache = (expand(expandedBlur & m_damagedArea) | | 477 | damagedCache = (expand(expandedBlur & m_damagedArea) | | ||
| 373 | (it->damagedRegion & data.paint)) & expandedBlur; | 478 | (it->damagedRegion & data.paint)) & expandedBlur; | ||
| 374 | } else { | 479 | } else { | ||
| 375 | damagedCache = expandedBlur; | 480 | damagedCache = expandedBlur; | ||
| 376 | } | 481 | } | ||
| 377 | if (!damagedCache.isEmpty()) { | 482 | if (!damagedCache.isEmpty()) { | ||
| 378 | // This is the area of the blurry window which really can change. | 483 | // This is the area of the blurry window which really can change. | ||
| 379 | const QRegion damagedArea = damagedCache & blurArea; | 484 | const QRegion damagedArea = damagedCache & blurArea; | ||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | |||||
| 421 | m_damagedArea -= data.clip; | 526 | m_damagedArea -= data.clip; | ||
| 422 | m_damagedArea |= oldPaint; | 527 | m_damagedArea |= oldPaint; | ||
| 423 | 528 | | |||
| 424 | // in contrast to m_damagedArea does m_paintedArea keep track of all repainted areas | 529 | // in contrast to m_damagedArea does m_paintedArea keep track of all repainted areas | ||
| 425 | m_paintedArea -= data.clip; | 530 | m_paintedArea -= data.clip; | ||
| 426 | m_paintedArea |= data.paint; | 531 | m_paintedArea |= data.paint; | ||
| 427 | } | 532 | } | ||
| 428 | 533 | | |||
| 429 | bool BlurEffect::shouldBlur(const EffectWindow *w, int mask, const WindowPaintData &data) const | 534 | bool BlurEffect::shouldBlur(const EffectWindow *w, int mask, const WindowPaintData &data) | ||
| 430 | { | 535 | { | ||
| 431 | if (!target->valid() || !shader || !shader->isValid()) | 536 | if (!renderTargetsValid() || !shader || !shader->isValid()) | ||
| 432 | return false; | 537 | return false; | ||
| 433 | 538 | | |||
| 434 | if (effects->activeFullScreenEffect() && !w->data(WindowForceBlurRole).toBool()) | 539 | if (effects->activeFullScreenEffect() && !w->data(WindowForceBlurRole).toBool()) | ||
| 435 | return false; | 540 | return false; | ||
| 436 | 541 | | |||
| 437 | if (w->isDesktop()) | 542 | if (w->isDesktop()) | ||
| 438 | return false; | 543 | return false; | ||
| 439 | 544 | | |||
| Show All 38 Lines | 563 | if (shouldBlur(w, mask, data)) { | |||
| 478 | } else if (translated) { | 583 | } else if (translated) { | ||
| 479 | shape = shape.translated(data.xTranslation(), data.yTranslation()); | 584 | shape = shape.translated(data.xTranslation(), data.yTranslation()); | ||
| 480 | shape = shape & region; | 585 | shape = shape & region; | ||
| 481 | } | 586 | } | ||
| 482 | 587 | | |||
| 483 | if (!shape.isEmpty()) { | 588 | if (!shape.isEmpty()) { | ||
| 484 | if (w->isFullScreen() && GLRenderTarget::blitSupported() && m_simpleShader->isValid() | 589 | if (w->isFullScreen() && GLRenderTarget::blitSupported() && m_simpleShader->isValid() | ||
| 485 | && !GLPlatform::instance()->supports(LimitedNPOT) && shape.boundingRect() == w->geometry()) { | 590 | && !GLPlatform::instance()->supports(LimitedNPOT) && shape.boundingRect() == w->geometry()) { | ||
| 591 | if (m_useSimpleBlur) { | ||||
| 486 | doSimpleBlur(w, data.opacity(), data.screenProjectionMatrix()); | 592 | doSimpleBlur(w, data.opacity(), data.screenProjectionMatrix()); | ||
| 593 | } else { | ||||
| 594 | doBlur(shape, screen, data.opacity(), data.screenProjectionMatrix()); | ||||
| 595 | } | ||||
| 487 | } else if (m_shouldCache && !translated && !w->isDeleted()) { | 596 | } else if (m_shouldCache && !translated && !w->isDeleted()) { | ||
| 488 | doCachedBlur(w, region, data.opacity(), data.screenProjectionMatrix()); | 597 | doCachedBlur(w, region, data.opacity(), data.screenProjectionMatrix()); | ||
| 489 | } else { | 598 | } else { | ||
| 490 | doBlur(shape, screen, data.opacity(), data.screenProjectionMatrix()); | 599 | doBlur(shape, screen, data.opacity(), data.screenProjectionMatrix()); | ||
| 491 | } | 600 | } | ||
| 492 | } | 601 | } | ||
| 493 | } | 602 | } | ||
| 494 | 603 | | |||
| 495 | // Draw the window over the blurred area | 604 | // Draw the window over the blurred area | ||
| 496 | effects->drawWindow(w, mask, region, data); | 605 | effects->drawWindow(w, mask, region, data); | ||
| 497 | } | 606 | } | ||
| 498 | 607 | | |||
| 499 | void BlurEffect::paintEffectFrame(EffectFrame *frame, QRegion region, double opacity, double frameOpacity) | 608 | void BlurEffect::paintEffectFrame(EffectFrame *frame, QRegion region, double opacity, double frameOpacity) | ||
| 500 | { | 609 | { | ||
| 501 | const QRect screen = effects->virtualScreenGeometry(); | 610 | const QRect screen = effects->virtualScreenGeometry(); | ||
| 502 | bool valid = target->valid() && shader && shader->isValid(); | 611 | bool valid = renderTargetsValid() && shader && shader->isValid(); | ||
| 503 | QRegion shape = frame->geometry().adjusted(-5, -5, 5, 5) & screen; | 612 | QRegion shape = frame->geometry().adjusted(-BORDER_SIZE, -BORDER_SIZE, BORDER_SIZE, BORDER_SIZE) & screen; | ||
| 613 | | ||||
| 504 | if (valid && !shape.isEmpty() && region.intersects(shape.boundingRect()) && frame->style() != EffectFrameNone) { | 614 | if (valid && !shape.isEmpty() && region.intersects(shape.boundingRect()) && frame->style() != EffectFrameNone) { | ||
| 505 | doBlur(shape, screen, opacity * frameOpacity, frame->screenProjectionMatrix()); | 615 | doBlur(shape, screen, opacity * frameOpacity, frame->screenProjectionMatrix()); | ||
| 506 | } | 616 | } | ||
| 507 | effects->paintEffectFrame(frame, region, opacity, frameOpacity); | 617 | effects->paintEffectFrame(frame, region, opacity, frameOpacity); | ||
| 508 | } | 618 | } | ||
| 509 | 619 | | |||
| 510 | void BlurEffect::doSimpleBlur(EffectWindow *w, const float opacity, const QMatrix4x4 &screenProjection) | 620 | void BlurEffect::doSimpleBlur(EffectWindow *w, const float opacity, const QMatrix4x4 &screenProjection) | ||
| 511 | { | 621 | { | ||
| 512 | // The fragment shader uses a LOD bias of 1.75, so we need 3 mipmap levels. | 622 | // The fragment shader uses a LOD bias of 1.75, so we need 3 mipmap levels. | ||
| 513 | GLTexture blurTexture = GLTexture(GL_RGBA8, w->size(), 3); | 623 | GLTexture blurTexture = GLTexture(GL_RGBA8, w->size(), 3); | ||
| 514 | blurTexture.setFilter(GL_LINEAR_MIPMAP_LINEAR); | 624 | blurTexture.setFilter(GL_LINEAR_MIPMAP_LINEAR); | ||
| 515 | blurTexture.setWrapMode(GL_CLAMP_TO_EDGE); | 625 | blurTexture.setWrapMode(GL_CLAMP_TO_EDGE); | ||
| 516 | 626 | | |||
| 517 | target->attachTexture(blurTexture); | 627 | m_simpleTarget->attachTexture(blurTexture); | ||
| 518 | target->blitFromFramebuffer(w->geometry(), QRect(QPoint(0, 0), w->size())); | 628 | m_simpleTarget->blitFromFramebuffer(w->geometry(), QRect(QPoint(0, 0), w->size())); | ||
Detach the texture from the render target before you return from this method - otherwise the FBO continues to hold a reference to the texture, preventing it from being deleted. fredrik: Detach the texture from the render target before you return from this method - otherwise the… | |||||
| 519 | 629 | | |||
| 520 | // Unmodified base image | 630 | // Unmodified base image | ||
| 521 | ShaderBinder binder(m_simpleShader); | 631 | ShaderBinder binder(m_simpleShader); | ||
| 522 | QMatrix4x4 mvp = screenProjection; | 632 | QMatrix4x4 mvp = screenProjection; | ||
| 523 | mvp.translate(w->x(), w->y()); | 633 | mvp.translate(w->x(), w->y()); | ||
| 524 | m_simpleShader->setUniform(GLShader::ModelViewProjectionMatrix, mvp); | 634 | m_simpleShader->setUniform(GLShader::ModelViewProjectionMatrix, mvp); | ||
| 525 | m_simpleShader->setUniform("u_alphaProgress", opacity); | 635 | m_simpleShader->setUniform("u_alphaProgress", opacity); | ||
| 526 | glEnable(GL_BLEND); | 636 | glEnable(GL_BLEND); | ||
| 527 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | 637 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | ||
| 528 | blurTexture.bind(); | 638 | blurTexture.bind(); | ||
| 529 | blurTexture.generateMipmaps(); | 639 | blurTexture.generateMipmaps(); | ||
| 530 | blurTexture.render(infiniteRegion(), w->geometry()); | 640 | blurTexture.render(infiniteRegion(), w->geometry()); | ||
| 531 | blurTexture.unbind(); | 641 | blurTexture.unbind(); | ||
| 532 | glDisable(GL_BLEND); | 642 | glDisable(GL_BLEND); | ||
| 533 | } | 643 | } | ||
| 534 | 644 | | |||
| 535 | void BlurEffect::doBlur(const QRegion& shape, const QRect& screen, const float opacity, const QMatrix4x4 &screenProjection) | 645 | void BlurEffect::doBlur(const QRegion& shape, const QRect& screen, const float opacity, const QMatrix4x4 &screenProjection) | ||
| 536 | { | 646 | { | ||
| 537 | const QRegion expanded = expand(shape) & screen; | 647 | QRegion expandedBlurRegion = expand(shape) & expand(screen); | ||
| 538 | const QRect r = expanded.boundingRect(); | 648 | QRect expandedBlurRect = expandedBlurRegion.boundingRect() & screen; | ||
| 539 | 649 | | |||
| 540 | // Upload geometry for the horizontal and vertical passes | 650 | // Upload geometry for the down and upsample iterations | ||
| 541 | GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer(); | 651 | GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer(); | ||
| 542 | uploadGeometry(vbo, expanded, shape); | 652 | uploadGeometry(vbo, expandedBlurRegion, QRegion(), shape); | ||
| 543 | vbo->bindArrays(); | 653 | vbo->bindArrays(); | ||
| 544 | 654 | | |||
| 545 | const qreal scale = GLRenderTarget::virtualScreenScale(); | 655 | int blurRectCount = expandedBlurRegion.rectCount() * 6; | ||
| 656 | | ||||
| 657 | // Copy part of the screen into this texture | ||||
| 658 | renderTextures.last().bind(); | ||||
| 659 | glCopyTexSubImage2D( | ||||
| 660 | GL_TEXTURE_2D, | ||||
| 661 | 0, | ||||
| 662 | expandedBlurRect.x(), | ||||
| 663 | effects->virtualScreenSize().height() - expandedBlurRect.y() - expandedBlurRect.height(), | ||||
| 664 | expandedBlurRect.x(), | ||||
| 665 | effects->virtualScreenSize().height() - expandedBlurRect.y() - expandedBlurRect.height(), | ||||
| 666 | expandedBlurRect.width(), | ||||
| 667 | expandedBlurRect.height() | ||||
| 668 | ); | ||||
| 669 | | ||||
| 670 | shader->bind(BlurShader::copySampleType); | ||||
| 671 | | ||||
| 672 | shader->setModelViewProjectionMatrix(screenProjection); | ||||
| 673 | shader->setTextureSize(screen.size()); | ||||
| 674 | shader->setBlurRect(shape.boundingRect().adjusted(BORDER_SIZE, BORDER_SIZE, -BORDER_SIZE, -BORDER_SIZE), screen.size()); | ||||
| 546 | 675 | | |||
| 547 | // Create a scratch texture and copy the area in the back buffer that we're | 676 | GLRenderTarget::pushRenderTarget(renderTargets[0]); | ||
| 548 | // going to blur into it | 677 | vbo->draw(GL_TRIANGLES, 0, blurRectCount); | ||
| 549 | // for HIGH DPI scratch is captured in native resolution, it is then implicitly downsampled | 678 | GLRenderTarget::popRenderTarget(); | ||
| 550 | // when rendering into tex | 679 | | ||
| 551 | GLTexture scratch(GL_RGBA8, r.width() * scale, r.height() * scale); | 680 | shader->unbind(); | ||
| 552 | scratch.setFilter(GL_LINEAR); | | |||
| 553 | scratch.setWrapMode(GL_CLAMP_TO_EDGE); | | |||
| 554 | scratch.bind(); | | |||
| 555 | | ||||
| 556 | const QRect sg = GLRenderTarget::virtualScreenGeometry(); | | |||
| 557 | glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, (r.x() - sg.x()) * scale, (sg.height() - sg.y() - r.y() - r.height()) * scale, | | |||
| 558 | scratch.width(), scratch.height()); | | |||
| 559 | | ||||
| 560 | // Draw the texture on the offscreen framebuffer object, while blurring it horizontally | | |||
| 561 | target->attachTexture(tex); | | |||
| 562 | GLRenderTarget::pushRenderTarget(target); | | |||
| 563 | | ||||
| 564 | shader->bind(); | | |||
| 565 | shader->setDirection(Qt::Horizontal); | | |||
| 566 | shader->setPixelDistance(1.0 / r.width()); | | |||
| 567 | 681 | | |||
| 568 | QMatrix4x4 modelViewProjectionMatrix; | 682 | QMatrix4x4 modelViewProjectionMatrix; | ||
| 569 | modelViewProjectionMatrix.ortho(0, tex.width(), tex.height(), 0 , 0, 65535); | | |||
| 570 | shader->setModelViewProjectionMatrix(modelViewProjectionMatrix); | | |||
| 571 | 683 | | |||
| 572 | // Set up the texture matrix to transform from screen coordinates | 684 | //Downsample | ||
| 573 | // to texture coordinates. | 685 | shader->bind(BlurShader::downSampleType); | ||
| 574 | QMatrix4x4 textureMatrix; | 686 | shader->setOffset(m_offset); | ||
| 575 | textureMatrix.scale(1.0 / r.width(), -1.0 / r.height(), 1); | 687 | | ||
| 576 | textureMatrix.translate(-r.x(), (-r.height() - r.y()), 0); | 688 | for (int i = 1; i <= m_downSampleIterations; i++) { | ||
| 577 | shader->setTextureMatrix(textureMatrix); | 689 | modelViewProjectionMatrix.setToIdentity(); | ||
| 690 | modelViewProjectionMatrix.ortho(0, renderTextures[i].width(), renderTextures[i].height(), 0 , 0, 65535); | ||||
| 578 | 691 | | |||
| 579 | vbo->draw(GL_TRIANGLES, 0, expanded.rectCount() * 6); | 692 | shader->setModelViewProjectionMatrix(modelViewProjectionMatrix); | ||
| 693 | shader->setTextureSize(renderTextures[i].size()); | ||||
| 694 | | ||||
| 695 | //Copy the image from this texture | ||||
| 696 | renderTextures[i - 1].bind(); | ||||
| 580 | 697 | | |||
| 698 | //Render to the texture attached to this FrameBufferObject | ||||
| 699 | GLRenderTarget::pushRenderTarget(renderTargets[i]); | ||||
| 700 | vbo->draw(GL_TRIANGLES, blurRectCount * i, blurRectCount); | ||||
| 581 | GLRenderTarget::popRenderTarget(); | 701 | GLRenderTarget::popRenderTarget(); | ||
| 582 | scratch.unbind(); | 702 | } | ||
| 583 | scratch.discard(); | 703 | | ||
| 704 | shader->unbind(); | ||||
| 705 | | ||||
| 706 | //Upsample | ||||
| 707 | shader->bind(BlurShader::upSampleType); | ||||
| 708 | shader->setOffset(m_offset); | ||||
| 709 | | ||||
| 710 | for (int i = m_downSampleIterations - 1; i > 0; i--) { | ||||
| 711 | modelViewProjectionMatrix.setToIdentity(); | ||||
| 712 | modelViewProjectionMatrix.ortho(0, renderTextures[i].width(), renderTextures[i].height(), 0 , 0, 65535); | ||||
| 713 | | ||||
| 714 | shader->setModelViewProjectionMatrix(modelViewProjectionMatrix); | ||||
| 715 | shader->setTextureSize(renderTextures[i].size()); | ||||
| 584 | 716 | | |||
| 585 | // Now draw the horizontally blurred area back to the backbuffer, while | 717 | //Copy the image from this texture | ||
| 586 | // blurring it vertically and clipping it to the window shape. | 718 | renderTextures[i + 1].bind(); | ||
| 587 | tex.bind(); | | |||
| 588 | 719 | | |||
| 589 | shader->setDirection(Qt::Vertical); | 720 | //Render to the texture attached to this FrameBufferObject | ||
| 590 | shader->setPixelDistance(1.0 / tex.height()); | 721 | GLRenderTarget::pushRenderTarget(renderTargets[i]); | ||
| 722 | vbo->draw(GL_TRIANGLES, blurRectCount * i, blurRectCount); | ||||
| 723 | GLRenderTarget::popRenderTarget(); | ||||
| 724 | } | ||||
Make a 3 function copySampleType, downSampleType, upSampleType with needed parameters. Call them here and in doCachedBlur anthonyfieroni: Make a 3 function copySampleType, downSampleType, upSampleType with needed parameters. Call… | |||||
| 591 | 725 | | |||
| 592 | // Modulate the blurred texture with the window opacity if the window isn't opaque | 726 | // Modulate the blurred texture with the window opacity if the window isn't opaque | ||
| 593 | if (opacity < 1.0) { | 727 | if (opacity < 1.0) { | ||
| 594 | glEnable(GL_BLEND); | 728 | glEnable(GL_BLEND); | ||
| 595 | #if 1 // bow shape, always above y = x | 729 | #if 1 // bow shape, always above y = x | ||
| 596 | float o = 1.0f-opacity; | 730 | float o = 1.0f-opacity; | ||
| 597 | o = 1.0f - o*o; | 731 | o = 1.0f - o*o; | ||
| 598 | #else // sigmoid shape, above y = x for x > 0.5, below y = x for x < 0.5 | 732 | #else // sigmoid shape, above y = x for x > 0.5, below y = x for x < 0.5 | ||
| 599 | float o = 2.0f*opacity - 1.0f; | 733 | float o = 2.0f*opacity - 1.0f; | ||
| 600 | o = 0.5f + o / (1.0f + qAbs(o)); | 734 | o = 0.5f + o / (1.0f + qAbs(o)); | ||
| 601 | #endif | 735 | #endif | ||
| 602 | glBlendColor(0, 0, 0, o); | 736 | glBlendColor(0, 0, 0, o); | ||
| 603 | glBlendFunc(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA); | 737 | glBlendFunc(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA); | ||
| 604 | } | 738 | } | ||
| 605 | 739 | | |||
| 606 | // Set the up the texture matrix to transform from screen coordinates | 740 | //Final upscale to the screen | ||
| 607 | // to texture coordinates. | | |||
| 608 | textureMatrix.setToIdentity(); | | |||
| 609 | textureMatrix.scale(1.0 / tex.width(), -1.0 / tex.height(), 1); | | |||
| 610 | textureMatrix.translate(0, -tex.height(), 0); | | |||
| 611 | shader->setTextureMatrix(textureMatrix); | | |||
| 612 | shader->setModelViewProjectionMatrix(screenProjection); | 741 | shader->setModelViewProjectionMatrix(screenProjection); | ||
| 742 | shader->setTextureSize(renderTextures[0].size()); | ||||
| 613 | 743 | | |||
| 614 | vbo->draw(GL_TRIANGLES, expanded.rectCount() * 6, shape.rectCount() * 6); | 744 | //Copy the image from this texture | ||
| 615 | vbo->unbindArrays(); | 745 | renderTextures[1].bind(); | ||
| 746 | | ||||
| 747 | //Render to the screen | ||||
| 748 | vbo->draw(GL_TRIANGLES, blurRectCount * (m_downSampleIterations + 1), shape.rectCount() * 6); | ||||
| 616 | 749 | | |||
| 617 | if (opacity < 1.0) { | 750 | if (opacity < 1.0) { | ||
| 618 | glDisable(GL_BLEND); | 751 | glDisable(GL_BLEND); | ||
| 619 | } | 752 | } | ||
| 620 | 753 | | |||
| 621 | tex.unbind(); | 754 | vbo->unbindArrays(); | ||
| 622 | shader->unbind(); | 755 | shader->unbind(); | ||
| 623 | } | 756 | } | ||
| 624 | 757 | | |||
| 625 | void BlurEffect::doCachedBlur(EffectWindow *w, const QRegion& region, const float opacity, const QMatrix4x4 &screenProjection) | 758 | void BlurEffect::doCachedBlur(EffectWindow *w, const QRegion& region, const float opacity, const QMatrix4x4 &screenProjection) | ||
| 626 | { | 759 | { | ||
| 627 | const QRect screen = effects->virtualScreenGeometry(); | 760 | const QRect screenRect = effects->virtualScreenGeometry(); | ||
| 628 | const QRegion blurredRegion = blurRegion(w).translated(w->pos()) & screen; | 761 | const QRegion blurredRegion = blurRegion(w).translated(w->pos()) & screenRect; | ||
| 629 | const QRegion expanded = expand(blurredRegion) & screen; | | |||
| 630 | const QRect r = expanded.boundingRect(); | | |||
| 631 | 762 | | |||
| 632 | // The background texture we get is only partially valid. | 763 | QRegion expandedBlurredRegion = expand(blurredRegion) & expand(screenRect); | ||
| 764 | QRect expandedBlurredRect = expandedBlurredRegion.boundingRect() & screenRect; | ||||
| 633 | 765 | | |||
| 634 | CacheEntry it = windows.find(w); | 766 | CacheEntry it = windows.find(w); | ||
| 635 | if (it == windows.end()) { | 767 | if (it == windows.end()) { | ||
| 636 | BlurWindowInfo bwi; | 768 | BlurWindowInfo bwi; | ||
| 637 | bwi.blurredBackground = GLTexture(GL_RGBA8, r.width(),r.height()); | 769 | bwi.blurredBackground = GLTexture(GL_RGBA8, screenRect.width(),screenRect.height()); | ||
| 638 | bwi.damagedRegion = expanded; | 770 | bwi.windowSize = expandedBlurredRect.size(); | ||
| 771 | bwi.damagedRegion = expandedBlurredRegion; | ||||
| 639 | bwi.dropCache = false; | 772 | bwi.dropCache = false; | ||
| 640 | bwi.windowPos = w->pos(); | 773 | bwi.windowPos = w->pos(); | ||
| 641 | it = windows.insert(w, bwi); | 774 | it = windows.insert(w, bwi); | ||
| 642 | } else if (it->blurredBackground.size() != r.size()) { | 775 | } else if (it->windowSize != expandedBlurredRect.size()) { | ||
| 643 | it->blurredBackground = GLTexture(GL_RGBA8, r.width(),r.height()); | 776 | it->windowSize = expandedBlurredRect.size(); | ||
| 644 | it->dropCache = false; | 777 | it->dropCache = false; | ||
| 645 | it->windowPos = w->pos(); | 778 | it->windowPos = w->pos(); | ||
| 646 | } else if (it->windowPos != w->pos()) { | 779 | } else if (it->windowPos != w->pos()) { | ||
| 647 | it->dropCache = false; | 780 | it->dropCache = false; | ||
| 648 | it->windowPos = w->pos(); | 781 | it->windowPos = w->pos(); | ||
| 649 | } | 782 | } | ||
| 650 | 783 | | |||
| 651 | GLTexture targetTexture = it->blurredBackground; | | |||
| 652 | targetTexture.setFilter(GL_LINEAR); | | |||
| 653 | targetTexture.setWrapMode(GL_CLAMP_TO_EDGE); | | |||
| 654 | shader->bind(); | | |||
| 655 | QMatrix4x4 textureMatrix; | | |||
| 656 | QMatrix4x4 modelViewProjectionMatrix; | | |||
| 657 | | ||||
| 658 | /** | 784 | /** | ||
| 659 | * Which part of the background texture can be updated ? | 785 | * Which part of the background texture can be updated ? | ||
| 660 | * | 786 | * | ||
| 661 | * Well this is a rather difficult question. We kind of rely on the fact, that | 787 | * Well this is a rather difficult question. We kind of rely on the fact, that | ||
| 662 | * we need a bigger background region being painted before, more precisely if we want to | 788 | * we need a bigger background region being painted before, more precisely if we want to | ||
| 663 | * blur region A we need the background region expand(A). This business logic is basically | 789 | * blur region A we need the background region expand(A). This business logic is basically | ||
| 664 | * done in prePaintWindow: | 790 | * done in prePaintWindow: | ||
| 665 | * data.paint |= expand(damagedArea); | 791 | * data.paint |= expand(damagedArea); | ||
| Show All 15 Lines | |||||
| 681 | * the opaque area of every window by a margin of the blurring radius (c.f. prePaintWindow). | 807 | * the opaque area of every window by a margin of the blurring radius (c.f. prePaintWindow). | ||
| 682 | * This way we are sure that this area is overpainted by a higher opaque window. | 808 | * This way we are sure that this area is overpainted by a higher opaque window. | ||
| 683 | * | 809 | * | ||
| 684 | * Apparently paintSimpleScreen is not the only function that can influence "region". | 810 | * Apparently paintSimpleScreen is not the only function that can influence "region". | ||
| 685 | * In fact every effect's paintWindow that is called before Blur::paintWindow | 811 | * In fact every effect's paintWindow that is called before Blur::paintWindow | ||
| 686 | * can do so (e.g. SlidingPopups). Hence we have to make the compromise that we update | 812 | * can do so (e.g. SlidingPopups). Hence we have to make the compromise that we update | ||
| 687 | * "damagedRegion & region" of the cache but only mark "validUpdate" as valid. | 813 | * "damagedRegion & region" of the cache but only mark "validUpdate" as valid. | ||
| 688 | **/ | 814 | **/ | ||
| 689 | const QRegion damagedRegion = it->damagedRegion; | | |||
| 690 | const QRegion updateBackground = damagedRegion & region; | | |||
| 691 | const QRegion validUpdate = damagedRegion - expand(damagedRegion - region); | | |||
| 692 | 815 | | |||
| 693 | const QRegion horizontal = validUpdate.isEmpty() ? QRegion() : (updateBackground & screen); | 816 | const QRegion validUpdateRegion = it->damagedRegion - expand(it->damagedRegion - region); | ||
| 694 | const QRegion vertical = blurredRegion & region; | | |||
| 695 | 817 | | |||
| 696 | const int horizontalOffset = 0; | 818 | QRegion windowRegion = blurredRegion & region; | ||
| 697 | const int horizontalCount = horizontal.rectCount() * 6; | 819 | QRegion renderRegion = it->damagedRegion & region & windowRegion; | ||
| 698 | 820 | QRegion blurRegion = expand(renderRegion); | |||
| 699 | const int verticalOffset = horizontalCount; | | |||
| 700 | const int verticalCount = vertical.rectCount() * 6; | | |||
| 701 | 821 | | |||
| 702 | GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer(); | 822 | GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer(); | ||
| 703 | uploadGeometry(vbo, horizontal, vertical); | 823 | uploadGeometry(vbo, blurRegion, renderRegion, windowRegion); | ||
| 704 | | ||||
| 705 | vbo->bindArrays(); | 824 | vbo->bindArrays(); | ||
| 706 | 825 | | |||
| 707 | if (!validUpdate.isEmpty()) { | 826 | int blurRectCount = blurRegion.rectCount() * 6; | ||
| 708 | const QRect updateRect = (expand(updateBackground) & expanded).boundingRect(); | 827 | | ||
These three lines of code will expand to an unfortunate sequence of GL calls: // Iteration N glGetIntegerv(GL_VIEWPORT, ...); glBindFramebuffer(GL_FRAMEBUFFER, ...); glViewport(...); glDrawArrays(...); glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewport(...); // Iteration N+1 glGetIntegerv(GL_VIEWPORT, ..); glBindFramebuffer(GL_FRAMEBUFFER, ...); glViewport(...); glDrawArrays(...); glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewport(...); Note the redundant calls to glViewport() and glBindFramebuffer(). The worst offender here is glGetIntegerv() however, because it forces serialization of the internal driver threads. Ideally the call sequence should look like this: // Iteration N glBindFramebuffer(GL_FRAMEBUFFER, ...); glViewport(...); glDrawArrays(...); // Iteration N+1 glBindFramebuffer(GL_FRAMEBUFFER, ...); glViewport(...); glDrawArrays(...); This can be fixed in a followup patch though. fredrik: These three lines of code will expand to an unfortunate sequence of GL calls:
```
// Iteration… | |||||
| 709 | // First we have to copy the background from the frontbuffer | 828 | if (!validUpdateRegion.isEmpty()) { | ||
| 710 | // into a scratch texture (in this case "tex"). | 829 | QMatrix4x4 modelViewProjectionMatrix; | ||
| 711 | tex.bind(); | 830 | QRect blurRect = blurRegion.boundingRect() & screenRect; | ||
| 712 | 831 | | |||
| 713 | glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, updateRect.x(), effects->virtualScreenSize().height() - updateRect.y() - updateRect.height(), | 832 | // Copy part of the screen into this texture | ||
| 714 | updateRect.width(), updateRect.height()); | 833 | renderTextures.last().bind(); | ||
| 715 | 834 | glCopyTexSubImage2D( | |||
| 716 | // Draw the texture on the offscreen framebuffer object, while blurring it horizontally | 835 | GL_TEXTURE_2D, | ||
| 717 | target->attachTexture(targetTexture); | 836 | 0, | ||
| 718 | GLRenderTarget::pushRenderTarget(target); | 837 | blurRect.x(), | ||
| 838 | effects->virtualScreenSize().height() - blurRect.y() - blurRect.height(), | ||||
| 839 | blurRect.x(), | ||||
| 840 | effects->virtualScreenSize().height() - blurRect.y() - blurRect.height(), | ||||
| 841 | blurRect.width(), | ||||
| 842 | blurRect.height() | ||||
| 843 | ); | ||||
| 844 | | ||||
| 845 | shader->bind(BlurShader::copySampleType); | ||||
| 846 | | ||||
| 847 | shader->setModelViewProjectionMatrix(screenProjection); | ||||
| 848 | shader->setTextureSize(screenRect.size()); | ||||
| 849 | shader->setBlurRect(blurredRegion.boundingRect().adjusted(BORDER_SIZE, BORDER_SIZE, -BORDER_SIZE, -BORDER_SIZE), screenRect.size()); | ||||
| 850 | | ||||
| 851 | GLRenderTarget::pushRenderTarget(renderTargets[0]); | ||||
| 852 | vbo->draw(GL_TRIANGLES, 0, blurRectCount); | ||||
| 853 | GLRenderTarget::popRenderTarget(); | ||||
| 854 | | ||||
| 855 | shader->unbind(); | ||||
| 719 | 856 | | |||
| 720 | shader->setDirection(Qt::Horizontal); | 857 | // Downsample | ||
| 721 | shader->setPixelDistance(1.0 / tex.width()); | 858 | shader->bind(BlurShader::downSampleType); | ||
| 859 | shader->setOffset(m_offset); | ||||
| 860 | | ||||
| 861 | for (int i = 1; i <= m_downSampleIterations; i++) { | ||||
| 862 | modelViewProjectionMatrix.setToIdentity(); | ||||
| 863 | modelViewProjectionMatrix.ortho(0, renderTextures[i].width(), renderTextures[i].height(), 0 , 0, 65535); | ||||
| 722 | 864 | | |||
| 723 | modelViewProjectionMatrix.ortho(0, r.width(), r.height(), 0 , 0, 65535); | | |||
| 724 | modelViewProjectionMatrix.translate(-r.x(), -r.y(), 0); | | |||
| 725 | shader->setModelViewProjectionMatrix(modelViewProjectionMatrix); | 865 | shader->setModelViewProjectionMatrix(modelViewProjectionMatrix); | ||
| 866 | shader->setTextureSize(renderTextures[i].size()); | ||||
| 867 | | ||||
| 868 | // Copy the image from this texture | ||||
| 869 | renderTextures[i - 1].bind(); | ||||
| 870 | | ||||
| 871 | // Render to the texture attachment of this FrameBufferObject | ||||
| 872 | GLRenderTarget::pushRenderTarget(renderTargets[i]); | ||||
| 873 | vbo->draw(GL_TRIANGLES, blurRectCount * i, blurRectCount); | ||||
| 874 | GLRenderTarget::popRenderTarget(); | ||||
| 875 | } | ||||
| 876 | | ||||
| 877 | shader->unbind(); | ||||
| 726 | 878 | | |||
| 727 | // Set up the texture matrix to transform from screen coordinates | 879 | // Upsample | ||
| 728 | // to texture coordinates. | 880 | shader->bind(BlurShader::upSampleType); | ||
| 729 | textureMatrix.scale(1.0 / tex.width(), -1.0 / tex.height(), 1); | 881 | shader->setOffset(m_offset); | ||
| 730 | textureMatrix.translate(-updateRect.x(), -updateRect.height() - updateRect.y(), 0); | 882 | | ||
| 731 | shader->setTextureMatrix(textureMatrix); | 883 | for (int i = m_downSampleIterations - 1; i > 0; i--) { | ||
| 884 | modelViewProjectionMatrix.setToIdentity(); | ||||
| 885 | modelViewProjectionMatrix.ortho(0, renderTextures[i].width(), renderTextures[i].height(), 0 , 0, 65535); | ||||
| 732 | 886 | | |||
| 733 | vbo->draw(GL_TRIANGLES, horizontalOffset, horizontalCount); | 887 | shader->setModelViewProjectionMatrix(modelViewProjectionMatrix); | ||
| 888 | shader->setTextureSize(renderTextures[i].size()); | ||||
| 889 | | ||||
| 890 | // Copy the image from this texture | ||||
| 891 | renderTextures[i + 1].bind(); | ||||
| 734 | 892 | | |||
| 893 | // Render to the texture attachment of this FrameBufferObject | ||||
| 894 | GLRenderTarget::pushRenderTarget(renderTargets[i]); | ||||
| 895 | vbo->draw(GL_TRIANGLES, blurRectCount * i, blurRectCount); | ||||
| 735 | GLRenderTarget::popRenderTarget(); | 896 | GLRenderTarget::popRenderTarget(); | ||
| 736 | tex.unbind(); | | |||
| 737 | // mark the updated region as valid | | |||
| 738 | it->damagedRegion -= validUpdate; | | |||
| 739 | } | 897 | } | ||
| 740 | 898 | | |||
| 741 | // Now draw the horizontally blurred area back to the backbuffer, while | 899 | //Final upsample to the texture that is used for rendering to the screen | ||
| 742 | // blurring it vertically and clipping it to the window shape. | 900 | modelViewProjectionMatrix.setToIdentity(); | ||
| 743 | targetTexture.bind(); | 901 | modelViewProjectionMatrix.ortho(0, it->blurredBackground.width(), it->blurredBackground.height(), 0 , 0, 65535); | ||
| 902 | | ||||
| 903 | shader->setModelViewProjectionMatrix(modelViewProjectionMatrix); | ||||
| 904 | shader->setTextureSize(it->blurredBackground.size()); | ||||
| 905 | | ||||
| 906 | // Copy the image from this texture | ||||
| 907 | renderTextures[1].bind(); | ||||
| 908 | | ||||
| 909 | renderTargets.last()->attachTexture(it->blurredBackground); | ||||
| 744 | 910 | | |||
| 745 | shader->setDirection(Qt::Vertical); | 911 | // Render to the texture attachment of this FrameBufferObject | ||
| 746 | shader->setPixelDistance(1.0 / targetTexture.height()); | 912 | GLRenderTarget::pushRenderTarget(renderTargets.last()); | ||
| 913 | vbo->draw(GL_TRIANGLES, (blurRegion.rectCount() * (m_downSampleIterations + 1)) * 6, renderRegion.rectCount() * 6); | ||||
| 914 | GLRenderTarget::popRenderTarget(); | ||||
| 915 | | ||||
| 916 | shader->unbind(); | ||||
| 917 | | ||||
| 918 | // mark the updated region as valid | ||||
| 919 | it->damagedRegion -= validUpdateRegion; | ||||
| 920 | } | ||||
| 747 | 921 | | |||
| 748 | // Modulate the blurred texture with the window opacity if the window isn't opaque | 922 | // Modulate the blurred texture with the window opacity if the window isn't opaque | ||
| 749 | if (opacity < 1.0) { | 923 | if (opacity < 1.0) { | ||
| 750 | glEnable(GL_BLEND); | 924 | glEnable(GL_BLEND); | ||
| 751 | glBlendColor(0, 0, 0, opacity); | 925 | glBlendColor(0, 0, 0, opacity); | ||
| 752 | glBlendFunc(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA); | 926 | glBlendFunc(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA); | ||
| 753 | } | 927 | } | ||
| 754 | 928 | | |||
| 755 | shader->setModelViewProjectionMatrix(screenProjection); | 929 | // Render to screen | ||
| 930 | shader->bind(BlurShader::copySampleType); | ||||
| 931 | it->blurredBackground.bind(); | ||||
| 756 | 932 | | |||
| 757 | // Set the up the texture matrix to transform from screen coordinates | 933 | shader->setModelViewProjectionMatrix(screenProjection); | ||
| 758 | // to texture coordinates. | 934 | shader->setTextureSize(screenRect.size()); | ||
| 759 | textureMatrix.setToIdentity(); | 935 | shader->setBlurRect(windowRegion.boundingRect(), screenRect.size()); | ||
| 760 | textureMatrix.scale(1.0 / targetTexture.width(), -1.0 / targetTexture.height(), 1); | | |||
| 761 | textureMatrix.translate(-r.x(), -targetTexture.height() - r.y(), 0); | | |||
| 762 | shader->setTextureMatrix(textureMatrix); | | |||
| 763 | 936 | | |||
| 764 | vbo->draw(GL_TRIANGLES, verticalOffset, verticalCount); | 937 | vbo->draw(GL_TRIANGLES, (blurRectCount * (m_downSampleIterations + 1)) + renderRegion.rectCount() * 6, windowRegion.rectCount() * 6); | ||
| 765 | vbo->unbindArrays(); | | |||
| 766 | 938 | | |||
| 767 | if (opacity < 1.0) { | 939 | if (opacity < 1.0) { | ||
| 768 | glDisable(GL_BLEND); | 940 | glDisable(GL_BLEND); | ||
| 769 | } | 941 | } | ||
| 770 | 942 | | |||
| 771 | targetTexture.unbind(); | 943 | vbo->unbindArrays(); | ||
| 772 | shader->unbind(); | 944 | shader->unbind(); | ||
| 773 | } | 945 | } | ||
| 774 | 946 | | |||
| 775 | int BlurEffect::blurRadius() const | | |||
| 776 | { | | |||
| 777 | if (!shader) { | | |||
| 778 | return 0; | | |||
| 779 | } | | |||
| 780 | return shader->radius(); | | |||
| 781 | } | | |||
| 782 | | ||||
| 783 | } // namespace KWin | 947 | } // namespace KWin | ||
| 784 | 948 | | |||

Is this still needed when qPow() is not used?