Resize effect ported to GLES
This commit is contained in:
parent
0011a30f5c
commit
5c22ffb5f2
3 changed files with 68 additions and 15 deletions
|
@ -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 )
|
||||
|
|
|
@ -21,7 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include "resize.h"
|
||||
|
||||
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
|
||||
#include <GL/gl.h>
|
||||
#include <kwinglutils.h>
|
||||
#endif
|
||||
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
||||
#include <X11/Xlib.h>
|
||||
|
@ -29,6 +29,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#endif
|
||||
|
||||
#include <KColorScheme>
|
||||
#include <QVector2D>
|
||||
#include <QVector4D>
|
||||
|
||||
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<float> 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
|
||||
|
|
|
@ -25,6 +25,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
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
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue