Snaphelper ported to GLES

This commit is contained in:
Martin Gräßlin 2010-12-08 19:25:15 +01:00
parent db4c81993a
commit 91f7a70e4f
3 changed files with 84 additions and 28 deletions

View file

@ -91,6 +91,7 @@ endif( NOT KWIN_HAVE_OPENGLES_COMPOSITING )
if( KWIN_HAVE_OPENGL_COMPOSITING ) if( KWIN_HAVE_OPENGL_COMPOSITING )
include( glide/CMakeLists.txt ) include( glide/CMakeLists.txt )
include( sheet/CMakeLists.txt ) include( sheet/CMakeLists.txt )
include( snaphelper/CMakeLists.txt )
include( wobblywindows/CMakeLists.txt ) include( wobblywindows/CMakeLists.txt )
endif( KWIN_HAVE_OPENGL_COMPOSITING ) endif( KWIN_HAVE_OPENGL_COMPOSITING )
if( KWIN_HAVE_OPENGL_COMPOSITING AND NOT KWIN_HAVE_OPENGLES_COMPOSITING ) if( KWIN_HAVE_OPENGL_COMPOSITING AND NOT KWIN_HAVE_OPENGLES_COMPOSITING )
@ -105,7 +106,6 @@ if( KWIN_HAVE_OPENGL_COMPOSITING AND NOT KWIN_HAVE_OPENGLES_COMPOSITING )
include( mousemark/CMakeLists.txt ) include( mousemark/CMakeLists.txt )
include( screenshot/CMakeLists.txt ) include( screenshot/CMakeLists.txt )
include( sharpen/CMakeLists.txt ) include( sharpen/CMakeLists.txt )
include( snaphelper/CMakeLists.txt )
include( snow/CMakeLists.txt ) include( snow/CMakeLists.txt )
include( startupfeedback/CMakeLists.txt ) include( startupfeedback/CMakeLists.txt )
include( trackmouse/CMakeLists.txt ) include( trackmouse/CMakeLists.txt )

View file

@ -22,6 +22,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "kwinglutils.h" #include "kwinglutils.h"
//#include "kwinxrenderutils.h" //#include "kwinxrenderutils.h"
#include <QVector2D>
#include <QVector4D>
namespace KWin namespace KWin
{ {
@ -32,9 +34,35 @@ KWIN_EFFECT_SUPPORTED( snaphelper, SnapHelperEffect::supported() )
SnapHelperEffect::SnapHelperEffect() SnapHelperEffect::SnapHelperEffect()
: m_active( false ) : m_active( false )
, m_window( NULL ) , m_window( NULL )
, m_useShader( false )
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
, m_vbo( 0 )
, m_colorShader( 0 )
#endif
{ {
m_timeline.setCurveShape( TimeLine::LinearCurve ); m_timeline.setCurveShape( TimeLine::LinearCurve );
reconfigure( ReconfigureAll ); 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
/*if( effects->compositingType() == XRenderCompositing ) /*if( effects->compositingType() == XRenderCompositing )
{ {
@ -49,6 +77,10 @@ SnapHelperEffect::~SnapHelperEffect()
{ {
//if( effects->compositingType() == XRenderCompositing ) //if( effects->compositingType() == XRenderCompositing )
// XFreeGC( display(), m_gc ); // XFreeGC( display(), m_gc );
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
delete m_vbo;
delete m_colorShader;
#endif
} }
void SnapHelperEffect::reconfigure( ReconfigureFlags ) void SnapHelperEffect::reconfigure( ReconfigureFlags )
@ -80,42 +112,59 @@ void SnapHelperEffect::postPaintScreen()
{ // Display the guide { // Display the guide
if( effects->compositingType() == OpenGLCompositing ) if( effects->compositingType() == OpenGLCompositing )
{ {
#ifndef KWIN_HAVE_OPENGLES
glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT ); glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT );
#endif
if (m_useShader) {
m_colorShader->bind();
}
glEnable( GL_BLEND ); glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glColor4f( 0.5, 0.5, 0.5, m_timeline.value() * 0.5 ); QColor color;
glLineWidth( 4.0 ); color.setRedF(0.5);
glBegin( GL_LINES ); color.setGreenF(0.5);
for( int i = 0; i < effects->numScreens(); i++ ) color.setBlueF(0.5);
{ color.setAlphaF(m_timeline.value() * 0.5);
const QRect& rect = effects->clientArea( ScreenArea, i, 0 ); m_vbo->setColor(color);
int midX = rect.x() + rect.width() / 2; glLineWidth( 4.0 );
int midY = rect.y() + rect.height() / 2 ; QVector<float> verts;
int halfWidth = m_window->width() / 2; verts.reserve(effects->numScreens()*24);
int halfHeight = m_window->height() / 2; for (int i = 0; i < effects->numScreens(); i++) {
const QRect& rect = effects->clientArea( ScreenArea, i, 0 );
int midX = rect.x() + rect.width() / 2;
int midY = rect.y() + rect.height() / 2 ;
int halfWidth = m_window->width() / 2;
int halfHeight = m_window->height() / 2;
// Center lines // Center lines
glVertex2f( rect.x() + rect.width() / 2, rect.y() ); verts << rect.x() + rect.width() / 2 << rect.y();
glVertex2f( rect.x() + rect.width() / 2, rect.y() + rect.height() ); verts << rect.x() + rect.width() / 2 << rect.y() + rect.height();
glVertex2f( rect.x(), rect.y() + rect.height() / 2 ); verts << rect.x() << rect.y() + rect.height() / 2;
glVertex2f( rect.x() + rect.width(), rect.y() + rect.height() / 2 ); verts << rect.x() + rect.width() << rect.y() + rect.height() / 2;
// Window outline // Window outline
// The +/- 2 is to prevent line overlap // The +/- 2 is to prevent line overlap
glVertex2f( midX - halfWidth + 2, midY - halfHeight ); verts << midX - halfWidth + 2 << midY - halfHeight;
glVertex2f( midX + halfWidth + 2, midY - halfHeight ); verts << midX + halfWidth + 2 << midY - halfHeight;
glVertex2f( midX + halfWidth, midY - halfHeight + 2 ); verts << midX + halfWidth << midY - halfHeight + 2;
glVertex2f( midX + halfWidth, midY + halfHeight + 2 ); verts << midX + halfWidth << midY + halfHeight + 2;
glVertex2f( midX + halfWidth - 2, midY + halfHeight ); verts << midX + halfWidth - 2 << midY + halfHeight;
glVertex2f( midX - halfWidth - 2, midY + halfHeight ); verts << midX - halfWidth - 2 << midY + halfHeight;
glVertex2f( midX - halfWidth, midY + halfHeight - 2 ); verts << midX - halfWidth << midY + halfHeight - 2;
glVertex2f( midX - halfWidth, midY - halfHeight - 2 ); verts << midX - halfWidth << midY - halfHeight - 2;
} }
glEnd(); m_vbo->setData(verts.count()/2, 2, verts.data(), NULL);
m_vbo->render(GL_LINES);
if (m_useShader) {
m_colorShader->unbind();
}
glDisable( GL_BLEND ); glDisable( GL_BLEND );
glLineWidth( 1.0 );
#ifndef KWIN_HAVE_OPENGLES
glPopAttrib(); glPopAttrib();
#endif
} }
/*if( effects->compositingType() == XRenderCompositing ) /*if( effects->compositingType() == XRenderCompositing )
{ // TODO { // TODO

View file

@ -25,6 +25,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin namespace KWin
{ {
class GLShader;
class GLVertexBuffer;
class SnapHelperEffect class SnapHelperEffect
: public Effect : public Effect
@ -47,6 +49,11 @@ class SnapHelperEffect
EffectWindow* m_window; EffectWindow* m_window;
TimeLine m_timeline; TimeLine m_timeline;
//GC m_gc; //GC m_gc;
bool m_useShader;
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
GLVertexBuffer *m_vbo;
GLShader *m_colorShader;
#endif
}; };
} // namespace } // namespace