Effects ported to GLES use ShaderManager

This commit is contained in:
Martin Gräßlin 2010-12-11 10:28:37 +01:00
parent 3c6e7309f2
commit e2e4fe54ba
8 changed files with 24 additions and 109 deletions

View file

@ -29,8 +29,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#endif
#include <KColorScheme>
#include <QVector2D>
#include <QVector4D>
namespace KWin
{
@ -40,10 +38,8 @@ 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 );
@ -51,20 +47,8 @@ ResizeEffect::ResizeEffect()
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";
}
if (ShaderManager::instance()->isValid()) {
m_vbo->setUseShader(true);
}
}
#endif
@ -74,7 +58,6 @@ ResizeEffect::~ResizeEffect()
{
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
delete m_vbo;
delete m_colorShader;
#endif
}
@ -121,8 +104,8 @@ void ResizeEffect::paintWindow( EffectWindow* w, int mask, QRegion region, Windo
#ifndef KWIN_HAVE_OPENGLES
glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT );
#endif
if (m_useShader) {
m_colorShader->bind();
if (ShaderManager::instance()->isValid()) {
ShaderManager::instance()->pushShader(ShaderManager::ColorShader);
}
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
@ -140,8 +123,8 @@ void ResizeEffect::paintWindow( EffectWindow* w, int mask, QRegion region, Windo
}
m_vbo->setData(verts.count()/2, 2, verts.data(), NULL);
m_vbo->render(GL_TRIANGLES);
if (m_useShader) {
m_colorShader->unbind();
if (ShaderManager::instance()->isValid()) {
ShaderManager::instance()->popShader();
}
glDisable(GL_BLEND);
#ifndef KWIN_HAVE_OPENGLES

View file

@ -25,7 +25,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin
{
class GLShader;
class GLVertexBuffer;
class ResizeEffect
@ -48,10 +47,8 @@ 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
};

View file

@ -34,8 +34,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <math.h>
#include <qcolor.h>
#include <QVector2D>
#include <QVector4D>
namespace KWin
{
@ -47,30 +45,16 @@ 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";
}
if (ShaderManager::instance()->isValid()) {
vbo->setUseShader(true);
}
}
#endif
@ -80,7 +64,6 @@ ShowPaintEffect::~ShowPaintEffect()
{
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
delete vbo;
delete colorShader;
#endif
}
@ -112,8 +95,8 @@ void ShowPaintEffect::paintGL()
#ifndef KWIN_HAVE_OPENGLES
glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT );
#endif
if (useShader) {
colorShader->bind();
if (ShaderManager::instance()->isValid()) {
ShaderManager::instance()->pushShader(ShaderManager::ColorShader);
}
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
@ -132,8 +115,8 @@ void ShowPaintEffect::paintGL()
}
vbo->setData(verts.count()/2, 2, verts.data(), NULL);
vbo->render(GL_TRIANGLES);
if (useShader) {
colorShader->unbind();
if (ShaderManager::instance()->isValid()) {
ShaderManager::instance()->popShader();
}
glDisable( GL_BLEND );
#ifndef KWIN_HAVE_OPENGLES

View file

@ -25,7 +25,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin
{
class GLShader;
class GLVertexBuffer;
class ShowPaintEffect
@ -41,10 +40,8 @@ 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
};

View file

@ -22,8 +22,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "kwinglutils.h"
//#include "kwinxrenderutils.h"
#include <QVector2D>
#include <QVector4D>
namespace KWin
{
@ -34,10 +32,8 @@ KWIN_EFFECT_SUPPORTED( snaphelper, SnapHelperEffect::supported() )
SnapHelperEffect::SnapHelperEffect()
: m_active( false )
, m_window( NULL )
, m_useShader( false )
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
, m_vbo( 0 )
, m_colorShader( 0 )
#endif
{
m_timeline.setCurveShape( TimeLine::LinearCurve );
@ -46,20 +42,8 @@ SnapHelperEffect::SnapHelperEffect()
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";
}
if (ShaderManager::instance()->isValid()) {
m_vbo->setUseShader(true);
}
}
#endif
@ -79,7 +63,6 @@ SnapHelperEffect::~SnapHelperEffect()
// XFreeGC( display(), m_gc );
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
delete m_vbo;
delete m_colorShader;
#endif
}
@ -115,8 +98,8 @@ void SnapHelperEffect::postPaintScreen()
#ifndef KWIN_HAVE_OPENGLES
glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT );
#endif
if (m_useShader) {
m_colorShader->bind();
if (ShaderManager::instance()->isValid()) {
ShaderManager::instance()->pushShader(ShaderManager::ColorShader);
}
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
@ -156,8 +139,8 @@ void SnapHelperEffect::postPaintScreen()
}
m_vbo->setData(verts.count()/2, 2, verts.data(), NULL);
m_vbo->render(GL_LINES);
if (m_useShader) {
m_colorShader->unbind();
if (ShaderManager::instance()->isValid()) {
ShaderManager::instance()->popShader();
}
glDisable( GL_BLEND );

View file

@ -49,10 +49,8 @@ class SnapHelperEffect
EffectWindow* m_window;
TimeLine m_timeline;
//GC m_gc;
bool m_useShader;
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
GLVertexBuffer *m_vbo;
GLShader *m_colorShader;
#endif
};

View file

@ -22,8 +22,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "trackmouse.h"
#include <QTime>
#include <QVector2D>
#include <QVector4D>
#include <kwinconfig.h>
#include <kwinglutils.h>
@ -51,8 +49,6 @@ TrackMouseEffect::TrackMouseEffect()
: active( false )
, angle( 0 )
, texture( NULL )
, useShader( false )
, shader( NULL )
{
mousePolling = false;
actionCollection = new KActionCollection( this );
@ -60,26 +56,6 @@ TrackMouseEffect::TrackMouseEffect()
action->setText( i18n( "Track mouse" ) );
action->setGlobalShortcut( KShortcut() );
// TODO: use GLPlatform
if (GLShader::vertexShaderSupported() && GLShader::fragmentShaderSupported()) {
shader = new GLShader(":/resources/scene-vertex.glsl", ":/resources/scene-fragment.glsl");
if (shader->isValid()) {
shader->bind();
shader->setUniform("sample", 0);
shader->setUniform("displaySize", QVector2D(displayWidth(), displayHeight()));
shader->setUniform("debug", 0);
shader->setUniform("textureWidth", 1.0f);
shader->setUniform("textureHeight", 1.0f);
shader->setUniform("opacity", 1.0f);
shader->setUniform("brightness", 1.0f);
shader->setUniform("saturation", 1.0f);
shader->unbind();
useShader = true;
kDebug(1212) << "Track mouse shader is valid";
} else {
kDebug(1212) << "Track mouse shader is not valid";
}
}
connect( action, SIGNAL( triggered( bool ) ), this, SLOT( toggle() ) );
reconfigure( ReconfigureAll );
}
@ -89,7 +65,6 @@ TrackMouseEffect::~TrackMouseEffect()
if( mousePolling )
effects->stopMousePolling();
delete texture;
delete shader;
}
void TrackMouseEffect::reconfigure( ReconfigureFlags )
@ -142,8 +117,10 @@ void TrackMouseEffect::paintScreen( int mask, QRegion region, ScreenPaintData& d
#ifndef KWIN_HAVE_OPENGLES
glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT );
#endif
if (useShader) {
shader->bind();
bool useShader = false;
if (ShaderManager::instance()->isValid()) {
useShader = true;
ShaderManager::instance()->pushShader(ShaderManager::SimpleShader);
}
texture->bind();
glEnable( GL_BLEND );
@ -157,8 +134,8 @@ void TrackMouseEffect::paintScreen( int mask, QRegion region, ScreenPaintData& d
}
texture->unbind();
glDisable(GL_BLEND);
if (useShader) {
shader->unbind();
if (ShaderManager::instance()->isValid()) {
ShaderManager::instance()->popShader();
}
#ifndef KWIN_HAVE_OPENGLES
glPopAttrib();

View file

@ -28,7 +28,6 @@ class KAction;
namespace KWin
{
class GLShader;
class GLTexture;
class TrackMouseEffect
@ -57,8 +56,6 @@ class TrackMouseEffect
KActionCollection* actionCollection;
KAction* action;
Qt::KeyboardModifiers modifier;
bool useShader;
GLShader* shader;
};
} // namespace