From 22d7c6c5f1005c2e2223bceb572dfd666082b437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Thu, 6 Jan 2011 11:58:03 +0100 Subject: [PATCH] ShowFPS effect ported to GLES --- effects/CMakeLists.txt | 2 +- effects/configs_builtins.cpp | 4 +- effects/showfps/showfps.cpp | 128 ++++++++++++++++++++++++----------- 3 files changed, 92 insertions(+), 42 deletions(-) diff --git a/effects/CMakeLists.txt b/effects/CMakeLists.txt index a0e3ba88f9..a6a1961e9c 100644 --- a/effects/CMakeLists.txt +++ b/effects/CMakeLists.txt @@ -72,6 +72,7 @@ include( minimizeanimation/CMakeLists.txt ) include( presentwindows/CMakeLists.txt ) include( resize/CMakeLists.txt ) include( scalein/CMakeLists.txt ) +include( showfps/CMakeLists.txt ) include( showpaint/CMakeLists.txt ) include( slide/CMakeLists.txt ) include( slideback/CMakeLists.txt ) @@ -84,7 +85,6 @@ include( zoom/CMakeLists.txt ) if( NOT KWIN_HAVE_OPENGLES_COMPOSITING ) include( logout/CMakeLists.txt ) include( shadow/CMakeLists.txt ) -include( showfps/CMakeLists.txt ) endif( NOT KWIN_HAVE_OPENGLES_COMPOSITING ) # OpenGL-specific effects diff --git a/effects/configs_builtins.cpp b/effects/configs_builtins.cpp index b896ed7fe1..01463a7e99 100644 --- a/effects/configs_builtins.cpp +++ b/effects/configs_builtins.cpp @@ -30,12 +30,12 @@ along with this program. If not, see . #include "translucency/translucency_config.h" #include "presentwindows/presentwindows_config.h" #include "resize/resize_config.h" +#include "showfps/showfps_config.h" #include "thumbnailaside/thumbnailaside_config.h" #include "zoom/zoom_config.h" #ifndef KWIN_HAVE_OPENGLES #include "shadow/shadow_config.h" -#include "showfps/showfps_config.h" #endif #ifdef KWIN_HAVE_OPENGL_COMPOSITING @@ -72,12 +72,12 @@ KWIN_EFFECT_CONFIG_MULTIPLE( builtins, KWIN_EFFECT_CONFIG_SINGLE( magiclamp, MagicLampEffectConfig ) KWIN_EFFECT_CONFIG_SINGLE( presentwindows, PresentWindowsEffectConfig ) KWIN_EFFECT_CONFIG_SINGLE( resize, ResizeEffectConfig ) + KWIN_EFFECT_CONFIG_SINGLE( showfps, ShowFpsEffectConfig ) KWIN_EFFECT_CONFIG_SINGLE( translucency, TranslucencyEffectConfig ) KWIN_EFFECT_CONFIG_SINGLE( thumbnailaside, ThumbnailAsideEffectConfig ) KWIN_EFFECT_CONFIG_SINGLE( zoom, ZoomEffectConfig ) #ifndef KWIN_HAVE_OPENGLES KWIN_EFFECT_CONFIG_SINGLE( shadow, ShadowEffectConfig ) - KWIN_EFFECT_CONFIG_SINGLE( showfps, ShowFpsEffectConfig ) #endif #ifdef KWIN_HAVE_OPENGL_COMPOSITING diff --git a/effects/showfps/showfps.cpp b/effects/showfps/showfps.cpp index ba8194ff57..b00ed161d6 100644 --- a/effects/showfps/showfps.cpp +++ b/effects/showfps/showfps.cpp @@ -38,6 +38,7 @@ along with this program. If not, see . #include #include +#include namespace KWin { @@ -184,38 +185,58 @@ void ShowFpsEffect::paintGL( int fps ) { int x = this->x; int y = this->y; +#ifndef KWIN_HAVE_OPENGLES glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT ); +#endif glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); // TODO painting first the background white and then the contents // means that the contents also blend with the background, I guess - glColor4f( 1, 1, 1, alpha ); // white - glBegin( GL_QUADS ); - glVertex2i( x, y ); - glVertex2i( x + 2*NUM_PAINTS + FPS_WIDTH, y ); - glVertex2i( x + 2*NUM_PAINTS + FPS_WIDTH, y + MAX_TIME ); - glVertex2i( x, y + MAX_TIME ); - glEnd(); + if (ShaderManager::instance()->isValid()) { + ShaderManager::instance()->pushShader(ShaderManager::ColorShader); + } + GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer(); + vbo->reset(); + QColor color(255, 255, 255); + color.setAlphaF(alpha); + vbo->setColor(color); + QVector verts; + verts.reserve(12); + verts << x + 2*NUM_PAINTS + FPS_WIDTH << y; + verts << x << y; + verts << x << y + MAX_TIME; + verts << x << y + MAX_TIME; + verts << x + 2*NUM_PAINTS + FPS_WIDTH << y + MAX_TIME; + verts << x + 2*NUM_PAINTS + FPS_WIDTH << y; + vbo->setData(6, 2, verts.constData(), NULL); + vbo->render(GL_TRIANGLES); y += MAX_TIME; // paint up from the bottom - glBegin( GL_QUADS ); - glColor4f( 0, 0, 1, alpha ); // blue - glVertex2i( x, y ); - glVertex2i( x + FPS_WIDTH, y ); - glVertex2i( x + FPS_WIDTH, y - fps ); - glVertex2i( x, y - fps ); - glEnd(); + color.setRed(0); + color.setGreen(0); + vbo->setColor(color); + verts.clear(); + verts << x + FPS_WIDTH << y - fps; + verts << x << y - fps; + verts << x << y; + verts << x << y; + verts << x + FPS_WIDTH << y; + verts << x + FPS_WIDTH << y - fps; + vbo->setData(6, 2, verts.constData(), NULL); + vbo->render(GL_TRIANGLES); - glColor4f( 0, 0, 0, alpha ); // black - glBegin( GL_LINES ); + color.setBlue(0); + vbo->setColor(color); + QVector vertices; for( int i = 10; i < MAX_TIME; i += 10 ) { - glVertex2i( x, y - i ); - glVertex2i( x + FPS_WIDTH, y - i ); + vertices << x << y - i; + vertices << x + FPS_WIDTH << y - i; } - glEnd(); + vbo->setData(vertices.size()/2, 2, vertices.constData(), NULL); + vbo->render(GL_LINES); x += FPS_WIDTH; // Paint FPS graph @@ -224,12 +245,18 @@ void ShowFpsEffect::paintGL( int fps ) // Paint amount of rendered pixels graph paintDrawSizeGraph( x, y ); + if (ShaderManager::instance()->isValid()) { + ShaderManager::instance()->popShader(); + } // Paint FPS numerical value paintFPSText(fps); // Paint paint sizes + glDisable(GL_BLEND); +#ifndef KWIN_HAVE_OPENGLES glPopAttrib(); +#endif } #endif @@ -328,34 +355,50 @@ void ShowFpsEffect::paintGraph( int x, int y, QList values, QList line #ifdef KWIN_HAVE_OPENGL_COMPOSITING if( effects->compositingType() == OpenGLCompositing) { - glColor4f( 0, 0, 0, alpha ); // black - glBegin( GL_LINES ); + QColor color(0, 0, 0); + color.setAlphaF(alpha); + GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer(); + vbo->reset(); + vbo->setColor(color); + QVector verts; // First draw the lines foreach( int h, lines) { - glVertex2i( x, y - h ); - glVertex2i( x + values.count(), y - h ); + verts << x << y - h; + verts << x + values.count() << y - h; } + vbo->setData(verts.size()/2, 2, verts.constData(), NULL); + vbo->render(GL_LINES); // Then the graph values - glColor4f( 0.5, 0.5, 0.5, alpha ); - for( int i = 0; i < values.count(); i++ ) - { + int lastValue = 0; + verts.clear(); + for (int i = 0; i < values.count(); i++) { int value = values[ i ]; - if( colorize ) - { - if( value <= 10 ) - glColor4f( 0, 1, 0, alpha ); // green - else if( value <= 20 ) - glColor4f( 1, 1, 0, alpha ); // yellow - else if( value <= 50 ) - glColor4f( 1, 0, 0, alpha ); // red - else - glColor4f( 0, 0, 0, alpha ); // black + if (colorize && value != lastValue) { + if (!verts.isEmpty()) { + vbo->setData(verts.size()/2, 2, verts.constData(), NULL); + vbo->render(GL_LINES); } - glVertex2i( x + values.count() - i, y ); - glVertex2i( x + values.count() - i, y - value ); + verts.clear(); + if (value <= 10) { + color = QColor(0, 255, 0); + } else if (value <= 20) { + color= QColor(255, 255, 0); + } else if( value <= 50 ) { + color = QColor(255, 0, 0); + } else { + color = QColor(0, 0, 0); + } + vbo->setColor(color); } - glEnd(); + verts << x + values.count() - i << y; + verts << x + values.count() - i << y - value; + lastValue = value; + } + if (!verts.isEmpty()) { + vbo->setData(verts.size()/2, 2, verts.constData(), NULL); + vbo->render(GL_LINES); + } } #endif #ifdef KWIN_HAVE_XRENDER_COMPOSITING @@ -443,7 +486,14 @@ void ShowFpsEffect::paintFPSText(int fps) delete fpsText; fpsText = new GLTexture(im); fpsText->bind(); + if (ShaderManager::instance()->isValid()) { + GLShader *shader = ShaderManager::instance()->pushShader(ShaderManager::SimpleShader); + shader->setUniform("offset", QVector2D(0, 0)); + } fpsText->render(QRegion(fpsTextRect), fpsTextRect); + if (ShaderManager::instance()->isValid()) { + ShaderManager::instance()->popShader(); + } fpsText->unbind(); effects->addRepaint(fpsTextRect); #endif