Do not use ShaderManager::isValid to check for OpenGL2 compositing

The main usage of ShaderManager::isValid was to have OpenGL2 specific
code pathes. Now we have an actual OpenGL2Compositing type and we know
that the ShaderManager is valid if we have this compositing type and we
know that it is not valid on OpenGL1Compositing. This gives us a much
better check and allows us to use the isValid method just for where we
want to check whether the shaders compiled successfully.

In addition some effects require OpenGL2, so we do not need to check
again that the ShaderManager is valid. Such usages are removed.
icc-effect-5.14.5
Martin Gräßlin 2012-09-21 09:09:52 +02:00
parent 6d2dfe06e7
commit f9a2ecbf33
18 changed files with 46 additions and 45 deletions

View File

@ -443,7 +443,7 @@ void BlurEffect::doBlur(const QRegion& shape, const QRect& screen, const float o
// Set up the texture matrix to transform from screen coordinates
// to texture coordinates.
#ifndef KWIN_HAVE_OPENGLES
if (!ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL1Compositing) {
glMatrixMode(GL_TEXTURE);
pushMatrix();
}
@ -485,7 +485,7 @@ void BlurEffect::doBlur(const QRegion& shape, const QRect& screen, const float o
drawRegion(shape);
#ifndef KWIN_HAVE_OPENGLES
if (!ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL1Compositing) {
popMatrix();
glMatrixMode(GL_MODELVIEW);
}
@ -532,7 +532,7 @@ void BlurEffect::doCachedBlur(EffectWindow *w, const QRegion& region, const floa
QMatrix4x4 textureMatrix;
QMatrix4x4 modelViewProjectionMatrix;
#ifndef KWIN_HAVE_OPENGLES
if (!ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL1Compositing) {
glMatrixMode(GL_MODELVIEW);
pushMatrix();
glLoadIdentity();
@ -604,7 +604,7 @@ void BlurEffect::doCachedBlur(EffectWindow *w, const QRegion& region, const floa
textureMatrix.scale(1.0 / tex.width(), -1.0 / tex.height(), 1);
textureMatrix.translate(-updateRect.x(), -updateRect.height() - updateRect.y(), 0);
#ifndef KWIN_HAVE_OPENGLES
if (!ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL1Compositing) {
glMatrixMode(GL_TEXTURE);
loadMatrix(textureMatrix);
glMatrixMode(GL_PROJECTION);
@ -645,7 +645,7 @@ void BlurEffect::doCachedBlur(EffectWindow *w, const QRegion& region, const floa
textureMatrix.scale(1.0 / targetTexture.width(), -1.0 / targetTexture.height(), 1);
textureMatrix.translate(-r.x(), -targetTexture.height() - r.y(), 0);
#ifndef KWIN_HAVE_OPENGLES
if (!ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL1Compositing) {
glMatrixMode(GL_TEXTURE);
loadMatrix(textureMatrix);
glMatrixMode(GL_PROJECTION);
@ -656,7 +656,7 @@ void BlurEffect::doCachedBlur(EffectWindow *w, const QRegion& region, const floa
drawRegion(blurredRegion & region);
#ifndef KWIN_HAVE_OPENGLES
if (!ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL1Compositing) {
popMatrix();
glMatrixMode(GL_TEXTURE);
popMatrix();

View File

@ -129,7 +129,7 @@ bool GLSLBlurShader::supported()
{
if (!GLPlatform::instance()->supports(GLSL))
return false;
if (!ShaderManager::instance()->isValid())
if (effects->compositingType() == OpenGL1Compositing)
return false;
(void) glGetError(); // Clear the error state

View File

@ -261,7 +261,7 @@ void CoverSwitchEffect::paintScreen(int mask, QRegion region, ScreenPaintData& d
if (reflection) {
// no reflections during start and stop animation
// except when using a shader
if ((!start && !stop) || ShaderManager::instance()->isValid())
if ((!start && !stop) || effects->compositingType() == OpenGL2Compositing)
paintScene(frontWindow, leftWindows, rightWindows, true);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -736,7 +736,7 @@ void CoverSwitchEffect::paintWindowCover(EffectWindow* w, bool reflectedWindow,
}
if (reflectedWindow) {
if (ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL2Compositing) {
GLShader *shader = ShaderManager::instance()->pushShader(ShaderManager::GenericShader);
QMatrix4x4 origMatrix = shader->getUniformMatrix4x4("screenTransformation");
QMatrix4x4 reflectionMatrix;

View File

@ -213,7 +213,7 @@ void CubeEffect::loadConfig(QString config)
}
// set the cap color on the shader
if (ShaderManager::instance()->isValid() && m_capShader->isValid()) {
if (effects->compositingType() == OpenGL2Compositing && m_capShader->isValid()) {
ShaderManager::instance()->pushShader(m_capShader);
m_capShader->setUniform("u_capColor", capColor);
ShaderManager::instance()->popShader();
@ -404,13 +404,13 @@ void CubeEffect::paintScreen(int mask, QRegion region, ScreenPaintData& data)
// wallpaper
if (wallpaper) {
if (ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL2Compositing) {
ShaderManager::instance()->pushShader(ShaderManager::SimpleShader);
}
wallpaper->bind();
wallpaper->render(region, rect);
wallpaper->unbind();
if (ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL2Compositing) {
ShaderManager::instance()->popShader();
}
}
@ -599,7 +599,7 @@ void CubeEffect::paintScreen(int mask, QRegion region, ScreenPaintData& data)
}
// restore the ScreenTransformation after all desktops are painted
// if not done GenericShader keeps the rotation data and transforms windows incorrectly in other rendering calls
if (ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL2Compositing) {
GLShader *shader = ShaderManager::instance()->pushShader(KWin::ShaderManager::GenericShader);
shader->setUniform(GLShader::ScreenTransformation, QMatrix4x4());
ShaderManager::instance()->popShader();
@ -786,7 +786,7 @@ void CubeEffect::paintCap(bool frontFirst, float zOffset)
}
bool capShader = false;
if (ShaderManager::instance()->isValid() && m_capShader->isValid()) {
if (effects->compositingType() == OpenGL2Compositing && m_capShader->isValid()) {
capShader = true;
ShaderManager::instance()->pushShader(m_capShader);
float opacity = cubeOpacity;
@ -1560,7 +1560,7 @@ void CubeEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPa
}
}
bool capShader = false;
if (ShaderManager::instance()->isValid() && m_capShader->isValid()) {
if (effects->compositingType() == OpenGL2Compositing && m_capShader->isValid()) {
capShader = true;
ShaderManager::instance()->pushShader(m_capShader);
m_capShader->setUniform("u_mirror", 0);

View File

@ -66,9 +66,6 @@ bool ExplosionEffect::supported()
bool ExplosionEffect::loadData()
{
mInited = true;
if (!ShaderManager::instance()->isValid()) {
return false;
}
QString shadername("explosion");
const QString fragmentshader = KGlobal::dirs()->findResource("data", "kwin/explosion.frag");
QString starttexture = KGlobal::dirs()->findResource("data", "kwin/explosion-start.png");

View File

@ -70,9 +70,6 @@ bool InvertEffect::supported()
bool InvertEffect::loadData()
{
m_inited = true;
if (!ShaderManager::instance()->isValid()) {
return false;
}
const QString fragmentshader = KGlobal::dirs()->findResource("data", "kwin/invert.frag");

View File

@ -288,7 +288,7 @@ bool LogoutEffect::isLogoutDialog(EffectWindow* w)
void LogoutEffect::renderVignetting()
{
if (!ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL1Compositing) {
renderVignettingLegacy();
return;
}
@ -369,7 +369,7 @@ void LogoutEffect::renderVignettingLegacy()
void LogoutEffect::renderBlurTexture()
{
if (!ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL1Compositing) {
renderBlurTextureLegacy();
return;
}

View File

@ -168,11 +168,11 @@ void MagnifierEffect::paintScreen(int mask, QRegion region, ScreenPaintData& dat
verts << area.right() + FRAME_WIDTH << area.bottom() + FRAME_WIDTH;
verts << area.right() + FRAME_WIDTH << area.bottom() + 1;
vbo->setData(verts.size() / 2, 2, verts.constData(), NULL);
if (ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL2Compositing) {
ShaderManager::instance()->pushShader(ShaderManager::ColorShader);
}
vbo->render(GL_TRIANGLES);
if (ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL2Compositing) {
ShaderManager::instance()->popShader();
}
}

View File

@ -116,7 +116,7 @@ void MouseMarkEffect::paintScreen(int mask, QRegion region, ScreenPaintData& dat
vbo->reset();
vbo->setUseColor(true);
vbo->setColor(color);
if (ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL2Compositing) {
ShaderManager::instance()->pushShader(ShaderManager::ColorShader);
}
QVector<float> verts;
@ -138,7 +138,7 @@ void MouseMarkEffect::paintScreen(int mask, QRegion region, ScreenPaintData& dat
vbo->setData(verts.size() / 2, 2, verts.data(), NULL);
vbo->render(GL_LINE_STRIP);
}
if (ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL2Compositing) {
ShaderManager::instance()->popShader();
}
glLineWidth(1.0);

View File

@ -86,7 +86,7 @@ void ResizeEffect::paintWindow(EffectWindow* w, int mask, QRegion region, Window
GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer();
vbo->reset();
vbo->setUseColor(true);
if (ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL2Compositing) {
ShaderManager::instance()->pushShader(ShaderManager::ColorShader);
}
glEnable(GL_BLEND);
@ -105,7 +105,7 @@ void ResizeEffect::paintWindow(EffectWindow* w, int mask, QRegion region, Window
}
vbo->setData(verts.count() / 2, 2, verts.data(), NULL);
vbo->render(GL_TRIANGLES);
if (ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL2Compositing) {
ShaderManager::instance()->popShader();
}
glDisable(GL_BLEND);

View File

@ -176,7 +176,7 @@ void ShowFpsEffect::paintGL(int fps)
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
if (ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL2Compositing) {
ShaderManager::instance()->pushShader(ShaderManager::ColorShader);
}
GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer();
@ -228,7 +228,7 @@ void ShowFpsEffect::paintGL(int fps)
// Paint amount of rendered pixels graph
paintDrawSizeGraph(x, y);
if (ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL2Compositing) {
ShaderManager::instance()->popShader();
}
@ -449,12 +449,12 @@ void ShowFpsEffect::paintFPSText(int fps)
delete fpsText;
fpsText = new GLTexture(im);
fpsText->bind();
if (ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL2Compositing) {
GLShader *shader = ShaderManager::instance()->pushShader(ShaderManager::SimpleShader);
shader->setUniform("offset", QVector2D(0, 0));
}
fpsText->render(QRegion(fpsTextRect), fpsTextRect);
if (ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL2Compositing) {
ShaderManager::instance()->popShader();
}
fpsText->unbind();

View File

@ -76,7 +76,7 @@ void ShowPaintEffect::paintGL()
GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer();
vbo->reset();
vbo->setUseColor(true);
if (ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL2Compositing) {
ShaderManager::instance()->pushShader(ShaderManager::ColorShader);
}
glEnable(GL_BLEND);
@ -96,7 +96,7 @@ void ShowPaintEffect::paintGL()
}
vbo->setData(verts.count() / 2, 2, verts.data(), NULL);
vbo->render(GL_TRIANGLES);
if (ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL2Compositing) {
ShaderManager::instance()->popShader();
}
glDisable(GL_BLEND);

View File

@ -81,7 +81,7 @@ void SnapHelperEffect::postPaintScreen()
GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer();
vbo->reset();
vbo->setUseColor(true);
if (ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL2Compositing) {
ShaderManager::instance()->pushShader(ShaderManager::ColorShader);
}
glEnable(GL_BLEND);
@ -122,7 +122,7 @@ void SnapHelperEffect::postPaintScreen()
}
vbo->setData(verts.count() / 2, 2, verts.data(), NULL);
vbo->render(GL_LINES);
if (ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL2Compositing) {
ShaderManager::instance()->popShader();
}

View File

@ -129,7 +129,7 @@ void StartupFeedbackEffect::reconfigure(Effect::ReconfigureFlags flags)
m_type = BouncingFeedback;
else if (busyBlinking) {
m_type = BlinkingFeedback;
if (ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL2Compositing) {
delete m_blinkingShader;
m_blinkingShader = 0;
const QString shader = KGlobal::dirs()->findResource("data", "kwin/blinking-startup-fragment.glsl");
@ -216,7 +216,7 @@ void StartupFeedbackEffect::paintScreen(int mask, QRegion region, ScreenPaintDat
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color);
#endif
}
} else if (ShaderManager::instance()->isValid()) {
} else if (effects->compositingType() == OpenGL2Compositing) {
useShader = true;
ShaderManager::instance()->pushShader(ShaderManager::SimpleShader);
}

View File

@ -127,7 +127,7 @@ void TrackMouseEffect::paintScreen(int mask, QRegion region, ScreenPaintData& da
if ( effects->isOpenGLCompositing() && m_texture[0] && m_texture[1]) {
GLShader *shader(0);
QMatrix4x4 modelview;
if (ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL2Compositing) {
ShaderManager::instance()->pushShader(ShaderManager::GenericShader);
shader = ShaderManager::instance()->getBoundShader();
modelview = shader->getUniformMatrix4x4("modelview");
@ -154,7 +154,7 @@ void TrackMouseEffect::paintScreen(int mask, QRegion region, ScreenPaintData& da
popMatrix();
}
glDisable(GL_BLEND);
if (ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL2Compositing) {
shader->setUniform(GLShader::ModelViewMatrix, modelview);
ShaderManager::instance()->popShader();
}

View File

@ -203,7 +203,7 @@ void LanczosFilter::performPaint(EffectWindowImpl* w, int mask, QRegion region,
if (hardwareClipping) {
glEnable(GL_SCISSOR_TEST);
}
if (ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL2Compositing) {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -340,7 +340,7 @@ void LanczosFilter::performPaint(EffectWindowImpl* w, int mask, QRegion region,
if (hardwareClipping) {
glEnable(GL_SCISSOR_TEST);
}
if (ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL2Compositing) {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -616,7 +616,7 @@ bool LanczosShader::init()
{
GLPlatform *gl = GLPlatform::instance();
if (gl->supports(GLSL) &&
ShaderManager::instance()->isValid() &&
effects->compositingType() == OpenGL2Compositing &&
GLRenderTarget::supported() &&
!(gl->isRadeon() && gl->chipClass() < R600)) {
m_shader = ShaderManager::instance()->loadFragmentShader(ShaderManager::SimpleShader, ":/resources/lanczos-fragment.glsl");

View File

@ -283,6 +283,13 @@ public:
**/
bool isShaderBound() const;
/**
* Allows to query whether Shaders are supported by the compositor, that is
* whether the Shaders compiled successfully.
*
* With OpenGL 1 compositing this method will always return @c false.
*
* Do not use this method to check whether the compositor uses OpenGL 1 or 2,
* use @link EffectsHandler::compositingType instead.
* @return @c true if the built-in shaders are valid, @c false otherwise
**/
bool isValid() const;

View File

@ -2189,7 +2189,7 @@ QString Workspace::supportInformation() const
support.append(" no\n");
}
if (ShaderManager::instance()->isValid()) {
if (effects->compositingType() == OpenGL2Compositing) {
support.append("OpenGL 2 Shaders are used\n");
} else {
support.append("OpenGL 2 Shaders are not used. Legacy OpenGL 1.x code path is used.\n");