From 2983727871d99bd5596f9dd4db66a70ad79be884 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Tue, 10 May 2022 10:22:57 +0300 Subject: [PATCH] effects: Make DeformEffect disable clipping if specified region is infinite The Scene no longer clips window quads if the specified paint region is infinite. The infinite region is defined as (INT_MIN/2, INT_MIN/2, INT_MAX, INT_MAX). If you try to scale the infinite region, you will easily hit integer overflow. This change makes the DeformEffect disable geometry clipping if the given paint region is infinite region in order to avoid hitting integer overflow. --- src/libkwineffects/kwindeformeffect.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/libkwineffects/kwindeformeffect.cpp b/src/libkwineffects/kwindeformeffect.cpp index ec1a1a1586..8f41a12efc 100644 --- a/src/libkwineffects/kwindeformeffect.cpp +++ b/src/libkwineffects/kwindeformeffect.cpp @@ -154,9 +154,6 @@ void DeformEffectPrivate::paint(EffectWindow *window, GLTexture *texture, const quads.makeInterleavedArrays(primitiveType, map, texture->matrix(NormalizedCoordinates)); vbo->unmap(); vbo->bindArrays(); - glEnable(GL_SCISSOR_TEST); - glEnable(GL_BLEND); - glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); const qreal rgb = data.brightness() * data.opacity(); const qreal a = data.opacity(); @@ -169,12 +166,24 @@ void DeformEffectPrivate::paint(EffectWindow *window, GLTexture *texture, const shader->setUniform(GLShader::TextureWidth, texture->width()); shader->setUniform(GLShader::TextureHeight, texture->height()); + const bool clipping = region != infiniteRegion(); + const QRegion clipRegion = clipping ? effects->mapToRenderTarget(region) : infiniteRegion(); + + if (clipping) { + glEnable(GL_SCISSOR_TEST); + } + + glEnable(GL_BLEND); + glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + texture->bind(); - vbo->draw(effects->mapToRenderTarget(region), primitiveType, 0, verticesPerQuad * quads.count(), true); + vbo->draw(clipRegion, primitiveType, 0, verticesPerQuad * quads.count(), clipping); texture->unbind(); glDisable(GL_BLEND); - glDisable(GL_SCISSOR_TEST); + if (clipping) { + glDisable(GL_SCISSOR_TEST); + } vbo->unbindArrays(); }