From 0011a30f5ce026cf868be1a80d31d6e5b765f531 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Tue, 7 Dec 2010 21:50:43 +0100 Subject: [PATCH] ShowPaint effect ported to GLES --- effects/CMakeLists.txt | 2 +- effects/showpaint/showpaint.cpp | 78 +++++++++++++++++++++++++++------ effects/showpaint/showpaint.h | 8 ++++ 3 files changed, 73 insertions(+), 15 deletions(-) diff --git a/effects/CMakeLists.txt b/effects/CMakeLists.txt index 3d374c2cf4..54178a2186 100644 --- a/effects/CMakeLists.txt +++ b/effects/CMakeLists.txt @@ -71,6 +71,7 @@ include( translucency/CMakeLists.txt ) include( minimizeanimation/CMakeLists.txt ) include( presentwindows/CMakeLists.txt ) include( scalein/CMakeLists.txt ) +include( showpaint/CMakeLists.txt ) include( slide/CMakeLists.txt ) include( slideback/CMakeLists.txt ) include( slidingpopups/CMakeLists.txt ) @@ -83,7 +84,6 @@ include( resize/CMakeLists.txt ) include( logout/CMakeLists.txt ) include( shadow/CMakeLists.txt ) include( showfps/CMakeLists.txt ) -include( showpaint/CMakeLists.txt ) include( zoom/CMakeLists.txt ) endif( NOT KWIN_HAVE_OPENGLES_COMPOSITING ) diff --git a/effects/showpaint/showpaint.cpp b/effects/showpaint/showpaint.cpp index 3a623c9b03..9f9f28e40a 100644 --- a/effects/showpaint/showpaint.cpp +++ b/effects/showpaint/showpaint.cpp @@ -3,6 +3,7 @@ This file is part of the KDE project. Copyright (C) 2007 Lubos Lunak +Copyright (C) 2010 Martin Gräßlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -23,7 +24,7 @@ along with this program. If not, see . #include #ifdef KWIN_HAVE_OPENGL_COMPOSITING -#include +#include #endif #ifdef KWIN_HAVE_XRENDER_COMPOSITING #include @@ -33,6 +34,8 @@ along with this program. If not, see . #include #include +#include +#include namespace KWin { @@ -44,8 +47,42 @@ static QColor colors[] = { Qt::red, Qt::green, Qt::blue, Qt::cyan, Qt::magenta, ShowPaintEffect::ShowPaintEffect() : color_index( 0 ) + , useShader( false ) +#ifdef KWIN_HAVE_OPENGL_COMPOSITING + , vbo( 0 ) + , colorShader( 0 ) +#endif { +#ifdef KWIN_HAVE_OPENGL_COMPOSITING + if (effects->compositingType() == OpenGLCompositing) { + vbo = new GLVertexBuffer(GLVertexBuffer::Stream); + vbo->setUseColor(true); + // TODO: use GLPlatform + if (GLShader::vertexShaderSupported() && GLShader::fragmentShaderSupported()) { + colorShader = new GLShader(":/resources/scene-color-vertex.glsl", ":/resources/scene-color-fragment.glsl"); + if (colorShader->isValid()) { + colorShader->bind(); + colorShader->setUniform("displaySize", QVector2D(displayWidth(), displayHeight())); + colorShader->setUniform("geometry", QVector4D(0, 0, 0, 0)); + colorShader->unbind(); + vbo->setUseShader(true); + useShader = true; + kDebug(1212) << "Show Paint Shader is valid"; + } else { + kDebug(1212) << "Show Paint Shader not valid"; + } + } } +#endif + } + +ShowPaintEffect::~ShowPaintEffect() +{ +#ifdef KWIN_HAVE_OPENGL_COMPOSITING + delete vbo; + delete colorShader; +#endif +} void ShowPaintEffect::paintScreen( int mask, QRegion region, ScreenPaintData& data ) { @@ -69,26 +106,39 @@ void ShowPaintEffect::paintWindow( EffectWindow* w, int mask, QRegion region, Wi effects->paintWindow( w, mask, region, data ); } -// TODO I think we need some kind of generic paintRect() void ShowPaintEffect::paintGL() { #ifdef KWIN_HAVE_OPENGL_COMPOSITING +#ifndef KWIN_HAVE_OPENGLES glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT ); +#endif + if (useShader) { + colorShader->bind(); + } glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); - float alpha = 0.2; - const QColor& color = colors[ color_index ]; - glColor4f( color.red() / 255., color.green() / 255., color.blue() / 255., alpha ); - glBegin( GL_QUADS ); - foreach( const QRect &r, painted.rects()) - { - glVertex2i( r.x(), r.y()); - glVertex2i( r.x() + r.width(), r.y()); - glVertex2i( r.x() + r.width(), r.y() + r.height()); - glVertex2i( r.x(), r.y() + r.height()); - } - glEnd(); + QColor color = colors[ color_index ]; + color.setAlphaF(0.2); + vbo->setColor(color); + QVector verts; + verts.reserve(painted.rects().count()*12); + foreach (const QRect &r, painted.rects()) { + verts << r.x() + r.width() << r.y(); + verts << r.x() << r.y(); + verts << r.x() << r.y() + r.height(); + verts << r.x() << r.y() + r.height(); + verts << r.x() + r.width() << r.y() + r.height(); + verts << r.x() + r.width() << r.y(); + } + vbo->setData(verts.count()/2, 2, verts.data(), NULL); + vbo->render(GL_TRIANGLES); + if (useShader) { + colorShader->unbind(); + } + glDisable( GL_BLEND ); +#ifndef KWIN_HAVE_OPENGLES glPopAttrib(); +#endif #endif } diff --git a/effects/showpaint/showpaint.h b/effects/showpaint/showpaint.h index d8b7803198..36d7b7b018 100644 --- a/effects/showpaint/showpaint.h +++ b/effects/showpaint/showpaint.h @@ -25,12 +25,15 @@ along with this program. If not, see . namespace KWin { +class GLShader; +class GLVertexBuffer; class ShowPaintEffect : public Effect { public: ShowPaintEffect(); + ~ShowPaintEffect(); virtual void paintScreen( int mask, QRegion region, ScreenPaintData& data ); virtual void paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data ); private: @@ -38,6 +41,11 @@ class ShowPaintEffect void paintXrender(); QRegion painted; // what's painted in one pass int color_index; + bool useShader; +#ifdef KWIN_HAVE_OPENGL_COMPOSITING + GLVertexBuffer *vbo; + GLShader *colorShader; +#endif }; } // namespace