From 5c22ffb5f2275173141ce63a1f6959d580c886cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Wed, 8 Dec 2010 18:39:36 +0100 Subject: [PATCH] Resize effect ported to GLES --- effects/CMakeLists.txt | 2 +- effects/resize/resize.cpp | 74 +++++++++++++++++++++++++++++++-------- effects/resize/resize.h | 7 ++++ 3 files changed, 68 insertions(+), 15 deletions(-) diff --git a/effects/CMakeLists.txt b/effects/CMakeLists.txt index 54178a2186..36db4ea2b1 100644 --- a/effects/CMakeLists.txt +++ b/effects/CMakeLists.txt @@ -70,6 +70,7 @@ include( magiclamp/CMakeLists.txt ) include( translucency/CMakeLists.txt ) include( minimizeanimation/CMakeLists.txt ) include( presentwindows/CMakeLists.txt ) +include( resize/CMakeLists.txt ) include( scalein/CMakeLists.txt ) include( showpaint/CMakeLists.txt ) include( slide/CMakeLists.txt ) @@ -80,7 +81,6 @@ include( thumbnailaside/CMakeLists.txt ) include( windowgeometry/CMakeLists.txt ) if( NOT KWIN_HAVE_OPENGLES_COMPOSITING ) -include( resize/CMakeLists.txt ) include( logout/CMakeLists.txt ) include( shadow/CMakeLists.txt ) include( showfps/CMakeLists.txt ) diff --git a/effects/resize/resize.cpp b/effects/resize/resize.cpp index 11d53825f9..637f95533b 100644 --- a/effects/resize/resize.cpp +++ b/effects/resize/resize.cpp @@ -21,7 +21,7 @@ along with this program. If not, see . #include "resize.h" #ifdef KWIN_HAVE_OPENGL_COMPOSITING -#include +#include #endif #ifdef KWIN_HAVE_XRENDER_COMPOSITING #include @@ -29,6 +29,8 @@ along with this program. If not, see . #endif #include +#include +#include namespace KWin { @@ -38,12 +40,42 @@ KWIN_EFFECT( resize, ResizeEffect ) ResizeEffect::ResizeEffect() : m_active( false ) , m_resizeWindow( 0 ) + , m_useShader( false ) +#ifdef KWIN_HAVE_OPENGL_COMPOSITING + , m_vbo( 0 ) + , m_colorShader( 0 ) +#endif { reconfigure( ReconfigureAll ); +#ifdef KWIN_HAVE_OPENGL_COMPOSITING + if (effects->compositingType() == OpenGLCompositing) { + m_vbo = new GLVertexBuffer(GLVertexBuffer::Stream); + m_vbo->setUseColor(true); + // TODO: use GLPlatform + if (GLShader::vertexShaderSupported() && GLShader::fragmentShaderSupported()) { + m_colorShader = new GLShader(":/resources/scene-color-vertex.glsl", ":/resources/scene-color-fragment.glsl"); + if (m_colorShader->isValid()) { + m_colorShader->bind(); + m_colorShader->setUniform("displaySize", QVector2D(displayWidth(), displayHeight())); + m_colorShader->setUniform("geometry", QVector4D(0, 0, 0, 0)); + m_colorShader->unbind(); + m_vbo->setUseShader(true); + m_useShader = true; + kDebug(1212) << "Show Paint Shader is valid"; + } else { + kDebug(1212) << "Show Paint Shader not valid"; + } + } + } +#endif } ResizeEffect::~ResizeEffect() { +#ifdef KWIN_HAVE_OPENGL_COMPOSITING + delete m_vbo; + delete m_colorShader; +#endif } void ResizeEffect::prePaintScreen( ScreenPrePaintData& data, int time ) @@ -85,23 +117,37 @@ void ResizeEffect::paintWindow( EffectWindow* w, int mask, QRegion region, Windo QColor color = KColorScheme( QPalette::Normal, KColorScheme::Selection ).background().color(); #ifdef KWIN_HAVE_OPENGL_COMPOSITING - if( effects->compositingType() == OpenGLCompositing) - { + if (effects->compositingType() == OpenGLCompositing) { +#ifndef KWIN_HAVE_OPENGLES glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT ); +#endif + if (m_useShader) { + m_colorShader->bind(); + } glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); - glColor4f( color.red() / 255.0f, color.green() / 255.0f, color.blue() / 255.0f, alpha ); - glBegin( GL_QUADS ); - foreach( const QRect &r, paintRegion.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(); - glPopAttrib(); + color.setAlphaF(alpha); + m_vbo->setColor(color); + QVector verts; + verts.reserve(paintRegion.rects().count()*12); + foreach( const QRect &r, paintRegion.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(); } + m_vbo->setData(verts.count()/2, 2, verts.data(), NULL); + m_vbo->render(GL_TRIANGLES); + if (m_useShader) { + m_colorShader->unbind(); + } + glDisable(GL_BLEND); +#ifndef KWIN_HAVE_OPENGLES + glPopAttrib(); +#endif + } #endif #ifdef KWIN_HAVE_XRENDER_COMPOSITING diff --git a/effects/resize/resize.h b/effects/resize/resize.h index 9575fbcd20..f3c54512e8 100644 --- a/effects/resize/resize.h +++ b/effects/resize/resize.h @@ -25,6 +25,8 @@ along with this program. If not, see . namespace KWin { +class GLShader; +class GLVertexBuffer; class ResizeEffect : public Effect @@ -46,6 +48,11 @@ class ResizeEffect int m_features; EffectWindow* m_resizeWindow; QRect m_currentGeometry, m_originalGeometry; + bool m_useShader; +#ifdef KWIN_HAVE_OPENGL_COMPOSITING + GLVertexBuffer *m_vbo; + GLShader *m_colorShader; +#endif }; }