[effects] Use shader traits API for lookingglass
In the long run this effect needs to be modified. Rendering the complete scene to an FBO is not the best approach.
This commit is contained in:
parent
18a15a59d5
commit
9aeb2f7907
4 changed files with 17 additions and 10 deletions
|
@ -4,15 +4,15 @@ uniform float u_zoom;
|
|||
uniform float u_radius;
|
||||
uniform vec2 u_textureSize;
|
||||
|
||||
varying vec2 varyingTexCoords;
|
||||
varying vec2 texcoord0;
|
||||
|
||||
#define PI 3.14159
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 d = u_cursor - varyingTexCoords;
|
||||
vec2 d = u_cursor - texcoord0;
|
||||
float dist = sqrt(d.x*d.x + d.y*d.y);
|
||||
vec2 texcoord = varyingTexCoords;
|
||||
vec2 texcoord = texcoord0;
|
||||
if (dist < u_radius) {
|
||||
float disp = sin(dist / u_radius * PI) * (u_zoom - 1.0) * 20.0;
|
||||
texcoord += d / dist * disp;
|
||||
|
|
|
@ -5,7 +5,7 @@ uniform float u_zoom;
|
|||
uniform float u_radius;
|
||||
uniform vec2 u_textureSize;
|
||||
|
||||
in vec2 varyingTexCoords;
|
||||
in vec2 texcoord0;
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
|
@ -13,9 +13,9 @@ out vec4 fragColor;
|
|||
|
||||
void main()
|
||||
{
|
||||
vec2 d = u_cursor - varyingTexCoords;
|
||||
vec2 d = u_cursor - texcoord0;
|
||||
float dist = sqrt(d.x*d.x + d.y*d.y);
|
||||
vec2 texcoord = varyingTexCoords;
|
||||
vec2 texcoord = texcoord0;
|
||||
if (dist < u_radius) {
|
||||
float disp = sin(dist / u_radius * PI) * (u_zoom - 1.0) * 20.0;
|
||||
texcoord += d / dist * disp;
|
||||
|
|
|
@ -32,6 +32,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include <KGlobalAccel>
|
||||
#include <KLocalizedString>
|
||||
#include <QVector2D>
|
||||
#include <QFile>
|
||||
|
||||
#include <kmessagebox.h>
|
||||
|
||||
|
@ -116,7 +117,12 @@ bool LookingGlassEffect::loadData()
|
|||
if (GLPlatform::instance()->glslVersion() >= coreVersionNumber)
|
||||
shadersDir = QStringLiteral("kwin/shaders/1.40/");
|
||||
const QString fragmentshader = QStandardPaths::locate(QStandardPaths::GenericDataLocation, shadersDir + QStringLiteral("lookingglass.frag"));
|
||||
m_shader = ShaderManager::instance()->loadFragmentShader(ShaderManager::SimpleShader, fragmentshader);
|
||||
QFile ff(fragmentshader);
|
||||
if (!ff.open(QIODevice::ReadOnly)) {
|
||||
qCCritical(KWINEFFECTS) << "Failed to read shader!";
|
||||
return false;
|
||||
}
|
||||
m_shader = ShaderManager::instance()->generateCustomShader(ShaderTrait::MapTexture, QByteArray(), ff.readAll());
|
||||
if (m_shader->isValid()) {
|
||||
ShaderBinder binder(m_shader);
|
||||
m_shader->setUniform("u_textureSize", QVector2D(screenSize.width(), screenSize.height()));
|
||||
|
@ -228,10 +234,10 @@ void LookingGlassEffect::slotMouseChanged(const QPoint& pos, const QPoint& old,
|
|||
}
|
||||
}
|
||||
|
||||
void LookingGlassEffect::postPaintScreen()
|
||||
void LookingGlassEffect::paintScreen(int mask, QRegion region, ScreenPaintData &data)
|
||||
{
|
||||
// Call the next effect.
|
||||
effects->postPaintScreen();
|
||||
effects->paintScreen(mask, region, data);
|
||||
if (m_valid && m_enabled) {
|
||||
// Disable render texture
|
||||
GLRenderTarget* target = GLRenderTarget::popRenderTarget();
|
||||
|
@ -245,6 +251,7 @@ void LookingGlassEffect::postPaintScreen()
|
|||
m_shader->setUniform("u_zoom", (float)zoom);
|
||||
m_shader->setUniform("u_radius", (float)radius);
|
||||
m_shader->setUniform("u_cursor", QVector2D(cursorPos().x(), cursorPos().y()));
|
||||
m_shader->setUniform(GLShader::ModelViewProjectionMatrix, data.projectionMatrix());
|
||||
m_vbo->render(GL_TRIANGLES);
|
||||
m_texture->unbind();
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ public:
|
|||
virtual void reconfigure(ReconfigureFlags);
|
||||
|
||||
virtual void prePaintScreen(ScreenPrePaintData& data, int time);
|
||||
virtual void postPaintScreen();
|
||||
void paintScreen(int mask, QRegion region, ScreenPaintData &data) override;
|
||||
virtual bool isActive() const;
|
||||
|
||||
static bool supported();
|
||||
|
|
Loading…
Reference in a new issue