ShowPaint effect ported to GLES
This commit is contained in:
parent
a182744648
commit
0011a30f5c
3 changed files with 73 additions and 15 deletions
|
@ -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 )
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
This file is part of the KDE project.
|
||||
|
||||
Copyright (C) 2007 Lubos Lunak <l.lunak@kde.org>
|
||||
Copyright (C) 2010 Martin Gräßlin <kde@martin-graesslin.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
|||
#include <kwinconfig.h>
|
||||
|
||||
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
|
||||
#include <GL/gl.h>
|
||||
#include <kwinglutils.h>
|
||||
#endif
|
||||
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
||||
#include <X11/Xlib.h>
|
||||
|
@ -33,6 +34,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include <math.h>
|
||||
|
||||
#include <qcolor.h>
|
||||
#include <QVector2D>
|
||||
#include <QVector4D>
|
||||
|
||||
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());
|
||||
QColor color = colors[ color_index ];
|
||||
color.setAlphaF(0.2);
|
||||
vbo->setColor(color);
|
||||
QVector<float> 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();
|
||||
}
|
||||
glEnd();
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -25,12 +25,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue