Commit d0d15c4c authored by Martin Flöser's avatar Martin Flöser

Remove ShaderEffect from KWinEffects Library.

The class is not used by any effect any more and the
design of the ShaderEffect makes it hardly usable.
For most effects just rendering the windows with the Shader
attached to it makes more sense than rendering the complete
screen into a FBO and apply the shader on the off-screen texture.
parent 4e49ee51
......@@ -35,7 +35,6 @@ set(kwin_EFFECTSLIB_SRCS
kwinglutils.cpp
kwinglutils_funcs.cpp
kwinglplatform.cpp
kwinshadereffect.cpp
kwinxrenderutils.cpp
)
......@@ -83,7 +82,6 @@ install( FILES
kwineffects.h
kwinglutils.h
kwinglutils_funcs.h
kwinshadereffect.h
kwinxrenderutils.h
${CMAKE_CURRENT_BINARY_DIR}/kwinconfig.h
DESTINATION ${INCLUDE_INSTALL_DIR} COMPONENT Devel)
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2006-2007 Rivo Laks <rivolaks@hot.ee>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "kwinshadereffect.h"
#include "kwinglutils.h"
#include <kstandarddirs.h>
#include <kdebug.h>
#include <assert.h>
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
namespace KWin
{
ShaderEffect::ShaderEffect(const QString& shadername) : Effect()
{
mTexture = 0;
mRenderTarget = 0;
mShader = 0;
mTime = 0.0f;
mValid = loadData(shadername);
mEnabled = false;
}
ShaderEffect::~ShaderEffect()
{
delete mTexture;
delete mRenderTarget;
delete mShader;
}
bool ShaderEffect::loadData(const QString& shadername)
{
#ifndef KWIN_HAVE_OPENGL_COMPOSITING
return false;
#else
#ifdef KWIN_HAVE_OPENGLES
return false;
#else
// If NPOT textures are not supported, use nearest power-of-two sized
// texture. It wastes memory, but it's possible to support systems without
// NPOT textures that way
int texw = displayWidth();
int texh = displayHeight();
if( !GLTexture::NPOTTextureSupported() )
{
kWarning( 1212 ) << "NPOT textures not supported, wasting some memory" ;
texw = nearestPowerOfTwo(texw);
texh = nearestPowerOfTwo(texh);
}
// Create texture and render target
mTexture = new GLTexture(texw, texh);
mTexture->setFilter(GL_LINEAR_MIPMAP_LINEAR);
mTexture->setWrapMode(GL_CLAMP);
mRenderTarget = new GLRenderTarget(mTexture);
if( !mRenderTarget->valid() )
return false;
QString fragmentshader = KGlobal::dirs()->findResource("data", "kwin/" + shadername + ".frag");
QString vertexshader = KGlobal::dirs()->findResource("data", "kwin/" + shadername + ".vert");
if(fragmentshader.isEmpty() || vertexshader.isEmpty())
{
kError(1212) << "Couldn't locate shader files" << endl;
return false;
}
mShader = new GLShader(vertexshader, fragmentshader);
if(!mShader->isValid())
{
kError(1212) << "The shader failed to load!" << endl;
return false;
}
mShader->bind();
mShader->setUniform("sceneTex", 0);
mShader->setUniform("textureWidth", (float)texw);
mShader->setUniform("textureHeight", (float)texh);
mShader->unbind();
return true;
#endif
#endif
}
bool ShaderEffect::supported()
{
#ifndef KWIN_HAVE_OPENGL_COMPOSITING
return false;
#else
#ifdef KWIN_HAVE_OPENGLES
return false;
#else
return GLRenderTarget::supported() &&
GLShader::fragmentShaderSupported() &&
(effects->compositingType() == OpenGLCompositing);
#endif
#endif
}
bool ShaderEffect::isEnabled() const
{
return mEnabled;
}
void ShaderEffect::setEnabled(bool enabled)
{
mEnabled = enabled;
// Everything needs to be repainted
effects->addRepaintFull();
}
GLShader* ShaderEffect::shader() const
{
return mShader;
}
void ShaderEffect::prePaintScreen( ScreenPrePaintData& data, int time )
{
mTime += time / 1000.0f;
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
#ifndef KWIN_HAVE_OPENGLES
if( mValid && mEnabled )
{
data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
// Start rendering to texture
effects->pushRenderTarget(mRenderTarget);
}
#endif
#endif
effects->prePaintScreen(data, time);
}
void ShaderEffect::postPaintScreen()
{
// Call the next effect.
effects->postPaintScreen();
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
#ifndef KWIN_HAVE_OPENGLES
if( mValid && mEnabled )
{
// Disable render texture
GLRenderTarget* target = effects->popRenderTarget();
assert( target == mRenderTarget );
Q_UNUSED( target );
mTexture->bind();
// Use the shader
mShader->bind();
mShader->setUniform("time", (float)mTime);
mShader->setUniform("cursorX", (float)cursorPos().x());
mShader->setUniform("cursorY", (float)cursorPos().y());
// Render fullscreen quad with screen contents
glBegin(GL_QUADS);
glVertex2f(0.0, displayHeight());
glVertex2f(displayWidth(), displayHeight());
glVertex2f(displayWidth(), 0.0);
glVertex2f(0.0, 0.0);
glEnd();
mShader->unbind();
mTexture->unbind();
}
#endif
#endif
}
} // namespace
#endif
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2006-2007 Rivo Laks <rivolaks@hot.ee>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#ifndef KWIN_SHADEREFFECT_H
#define KWIN_SHADEREFFECT_H
#include <kwineffects.h>
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
/** @addtogroup kwineffects */
/** @{ */
namespace KWin
{
class GLTexture;
class GLRenderTarget;
class GLShader;
/**
* Unsupported in OpenGL ES
* @deprecated Use a normal Shader
*/
class KWIN_EXPORT ShaderEffect : public Effect
{
public:
ShaderEffect(const QString& shadername);
virtual ~ShaderEffect();
virtual void prePaintScreen( ScreenPrePaintData& data, int time );
virtual void postPaintScreen();
static bool supported();
protected:
bool isEnabled() const;
void setEnabled(bool enabled);
GLShader* shader() const;
bool loadData(const QString& shadername);
private:
GLTexture* mTexture;
GLRenderTarget* mRenderTarget;
GLShader* mShader;
bool mValid;
double mTime;
bool mEnabled;
};
} // namespace
/** @} */
#endif
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment