From 990001c5d7525c97e35e7c99dbded20011904821 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 31 Dec 2010 14:12:33 +0100 Subject: [PATCH] Drop GLVertexBuffer::useShader. The vertex buffer implementation uses the shader manager to decide whether core painting should be used or not. Shader manager is only used by shaders using vertex attributes instead of gl_Vertex etc. --- effects/coverswitch/coverswitch.cpp | 1 - effects/cube/cube.cpp | 4 ---- effects/mousemark/mousemark.cpp | 1 - effects/resize/resize.cpp | 1 - effects/showpaint/showpaint.cpp | 1 - effects/snaphelper/snaphelper.cpp | 1 - effects/trackmouse/trackmouse.cpp | 2 +- lib/kwinglutils.cpp | 30 +++++++---------------------- lib/kwinglutils.h | 27 -------------------------- scene_opengl.cpp | 12 +++++------- scene_opengl_egl.cpp | 1 - 11 files changed, 13 insertions(+), 68 deletions(-) diff --git a/effects/coverswitch/coverswitch.cpp b/effects/coverswitch/coverswitch.cpp index 6784cd192b..9348f2c22b 100644 --- a/effects/coverswitch/coverswitch.cpp +++ b/effects/coverswitch/coverswitch.cpp @@ -335,7 +335,6 @@ void CoverSwitchEffect::paintScreen( int mask, QRegion region, ScreenPaintData& verts << vertices[6] << vertices[7] << vertices[8]; GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer(); vbo->reset(); - vbo->setUseShader(true); vbo->setData(6, 3, verts.data(), texcoords.data()); vbo->render(GL_TRIANGLES); diff --git a/effects/cube/cube.cpp b/effects/cube/cube.cpp index ea9dff36db..7da83bad9e 100644 --- a/effects/cube/cube.cpp +++ b/effects/cube/cube.cpp @@ -550,7 +550,6 @@ void CubeEffect::paintScreen( int mask, QRegion region, ScreenPaintData& data ) verts << vertices[6] << vertices[7] << vertices[8]; GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer(); vbo->reset(); - vbo->setUseShader(true); vbo->setData(6, 3, verts.data(), texcoords.data()); vbo->render(GL_TRIANGLES); @@ -1123,9 +1122,6 @@ void CubeEffect::paintCubeCap() delete m_cubeCapBuffer; m_cubeCapBuffer = new GLVertexBuffer(GLVertexBuffer::Static); m_cubeCapBuffer->setData(verts.count()/3, 3, verts.constData(), texture ? texCoords.constData() : NULL); - if (ShaderManager::instance()->isValid() && m_capShader->isValid()) { - m_cubeCapBuffer->setUseShader(true); - } } void CubeEffect::paintCylinderCap() diff --git a/effects/mousemark/mousemark.cpp b/effects/mousemark/mousemark.cpp index a07d217d69..9808be48e7 100644 --- a/effects/mousemark/mousemark.cpp +++ b/effects/mousemark/mousemark.cpp @@ -87,7 +87,6 @@ void MouseMarkEffect::paintScreen( int mask, QRegion region, ScreenPaintData& da vbo->setColor(color); if (ShaderManager::instance()->isValid()) { ShaderManager::instance()->pushShader(ShaderManager::ColorShader); - vbo->setUseShader(true); } QVector verts; foreach (const Mark& mark, marks) { diff --git a/effects/resize/resize.cpp b/effects/resize/resize.cpp index c195d0a945..51e8d22510 100644 --- a/effects/resize/resize.cpp +++ b/effects/resize/resize.cpp @@ -94,7 +94,6 @@ void ResizeEffect::paintWindow( EffectWindow* w, int mask, QRegion region, Windo vbo->setUseColor(true); if (ShaderManager::instance()->isValid()) { ShaderManager::instance()->pushShader(ShaderManager::ColorShader); - vbo->setUseShader(true); } glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); diff --git a/effects/showpaint/showpaint.cpp b/effects/showpaint/showpaint.cpp index 24ce704dcf..a8256ba8c7 100644 --- a/effects/showpaint/showpaint.cpp +++ b/effects/showpaint/showpaint.cpp @@ -85,7 +85,6 @@ void ShowPaintEffect::paintGL() vbo->setUseColor(true); if (ShaderManager::instance()->isValid()) { ShaderManager::instance()->pushShader(ShaderManager::ColorShader); - vbo->setUseShader(true); } glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); diff --git a/effects/snaphelper/snaphelper.cpp b/effects/snaphelper/snaphelper.cpp index 044bf96f53..f4d9adb2da 100644 --- a/effects/snaphelper/snaphelper.cpp +++ b/effects/snaphelper/snaphelper.cpp @@ -88,7 +88,6 @@ void SnapHelperEffect::postPaintScreen() vbo->setUseColor(true); if (ShaderManager::instance()->isValid()) { ShaderManager::instance()->pushShader(ShaderManager::ColorShader); - vbo->setUseShader(true); } glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); diff --git a/effects/trackmouse/trackmouse.cpp b/effects/trackmouse/trackmouse.cpp index 851d72decc..aa364d2a22 100644 --- a/effects/trackmouse/trackmouse.cpp +++ b/effects/trackmouse/trackmouse.cpp @@ -130,7 +130,7 @@ void TrackMouseEffect::paintScreen( int mask, QRegion region, ScreenPaintData& d ++i ) { QRect r = starRect( i ); - texture->render( region, r, useShader ); + texture->render( region, r ); } texture->unbind(); glDisable(GL_BLEND); diff --git a/lib/kwinglutils.cpp b/lib/kwinglutils.cpp index 69c368070e..2b51c7c40d 100644 --- a/lib/kwinglutils.cpp +++ b/lib/kwinglutils.cpp @@ -513,11 +513,6 @@ void GLTexture::unbind() } void GLTexture::render( QRegion region, const QRect& rect ) - { - render( region, rect, false ); - } - -void GLTexture::render( QRegion region, const QRect& rect, bool useShader ) { if( rect.size() != m_cachedSize ) { @@ -544,16 +539,18 @@ void GLTexture::render( QRegion region, const QRect& rect, bool useShader ) }; m_vbo->setData( 4, 2, verts, texcoords ); } - if (useShader) { - ShaderManager::instance()->getBoundShader()->setUniform("offset", QVector2D(rect.x(), rect.y())); + if (ShaderManager::instance()->isShaderBound()) { + GLShader *shader = ShaderManager::instance()->getBoundShader(); + shader->setUniform("offset", QVector2D(rect.x(), rect.y())); + shader->setUniform("textureWidth", 1.0f); + shader->setUniform("textureHeight", 1.0f); } else { #ifndef KWIN_HAVE_OPENGLES glTranslatef( rect.x(), rect.y(), 0.0f ); #endif } - m_vbo->setUseShader( useShader ); m_vbo->render( region, GL_TRIANGLE_STRIP ); - if (!useShader) { + if (!ShaderManager::instance()->isShaderBound()) { #ifndef KWIN_HAVE_OPENGLES glTranslatef( -rect.x(), -rect.y(), 0.0f ); #endif @@ -1524,7 +1521,6 @@ class GLVertexBufferPrivate : hint( usageHint ) , numberVertices( 0 ) , dimension( 2 ) - , useShader( false ) , useColor( false ) , useTexCoords( true ) , color( 0, 0, 0, 255 ) @@ -1545,7 +1541,6 @@ class GLVertexBufferPrivate GLuint buffers[2]; int numberVertices; int dimension; - bool useShader; static bool supported; static GLVertexBuffer *streamingBuffer; QVector legacyVertices; @@ -1707,7 +1702,7 @@ void GLVertexBuffer::render( const QRegion& region, GLenum primitiveMode ) d->legacyPainting( region, primitiveMode ); return; } - if( d->useShader ) + if( ShaderManager::instance()->isShaderBound() ) { d->corePainting( region, primitiveMode ); return; @@ -1741,16 +1736,6 @@ void GLVertexBuffer::render( const QRegion& region, GLenum primitiveMode ) #endif } -void GLVertexBuffer::setUseShader( bool use ) - { - d->useShader = use; - } - -bool GLVertexBuffer::isUseShader() const - { - return d->useShader; - } - bool GLVertexBuffer::isSupported() { return GLVertexBufferPrivate::supported; @@ -1778,7 +1763,6 @@ void GLVertexBuffer::reset() d->color = QColor(0, 0, 0, 255); d->numberVertices = 0; d->dimension = 2; - d->useShader = false; d->useTexCoords = true; } diff --git a/lib/kwinglutils.h b/lib/kwinglutils.h index ec85e4571c..342a18e6d5 100644 --- a/lib/kwinglutils.h +++ b/lib/kwinglutils.h @@ -149,17 +149,6 @@ class KWIN_EXPORT GLTexture virtual void bind(); virtual void unbind(); void render( QRegion region, const QRect& rect ); - /** - * Same as above, but allows to specify if the geometry of the texture - * should be passed for a core profile shader. The shader needs to be - * bound before. The default is to perform legacy rendering. - * @param useShader If @c true core profile compatible rendering is used. - * If a bound shader is not core profile compatible @c false should be used. - * @see render - * @see GLVertexBuffer::setUseShader - * @since 4.7 - */ - void render( QRegion region, const QRect& rect, bool useShader ); /** * Set up texture transformation matrix to automatically map unnormalized * texture coordinates (i.e. 0 to width, 0 to height, (0,0) is top-left) @@ -520,22 +509,6 @@ class KWIN_EXPORT GLVertexBuffer * Same as above restricting painting to @a region. */ void render( const QRegion& region, GLenum primitiveMode ); - /** - * Use methods from core profile to perform rendering. A core compatible shader has - * to be bound while rendering. - * If the shader emulates fixed functionality rendering (e.g. uses gl_Vertex) using core - * rendering should be disabled. - * The default rendering path does not use core profile rendering. - * @param use enable/disable use of core profile rendering. - * @since 4.7 - **/ - void setUseShader( bool use ); - /** - * @returns @c true if core profile methods are used for rendering, @c false otherwise. - * @see setUseShader - * @since 4.7 - **/ - bool isUseShader() const; /** * Sets the color the geometry will be rendered with. * For legacy rendering glColor is used before rendering the geometry. diff --git a/scene_opengl.cpp b/scene_opengl.cpp index 9eb176be46..de6735e8d6 100644 --- a/scene_opengl.cpp +++ b/scene_opengl.cpp @@ -530,7 +530,6 @@ void SceneOpenGL::Window::performPaint( int mask, QRegion region, WindowPaintDat GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer(); vbo->reset(); - vbo->setUseShader(sceneShader); // decorations Client *client = dynamic_cast(toplevel); @@ -1288,7 +1287,6 @@ void SceneOpenGL::EffectFrame::render( QRegion region, double opacity, double fr glTranslatef( pt.x(), pt.y(), 0.0f ); #endif } - m_unstyledVBO->setUseShader( sceneShader ); m_unstyledVBO->render( region, GL_TRIANGLES ); #ifndef KWIN_HAVE_OPENGLES if (!sceneShader) { @@ -1311,7 +1309,7 @@ void SceneOpenGL::EffectFrame::render( QRegion region, double opacity, double fr m_texture->bind(); qreal left, top, right, bottom; m_effectFrame->frame().getMargins( left, top, right, bottom ); // m_geometry is the inner geometry - m_texture->render( region, m_effectFrame->geometry().adjusted( -left, -top, right, bottom ), sceneShader ); + m_texture->render( region, m_effectFrame->geometry().adjusted( -left, -top, right, bottom ) ); m_texture->unbind(); if( !m_effectFrame->selection().isNull() ) @@ -1324,7 +1322,7 @@ void SceneOpenGL::EffectFrame::render( QRegion region, double opacity, double fr } glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA ); m_selectionTexture->bind(); - m_selectionTexture->render( region, m_effectFrame->selection(), sceneShader ); + m_selectionTexture->render( region, m_effectFrame->selection() ); m_selectionTexture->unbind(); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); } @@ -1373,7 +1371,7 @@ void SceneOpenGL::EffectFrame::render( QRegion region, double opacity, double fr m_iconTexture->setYInverted(true); } m_iconTexture->bind(); - m_iconTexture->render( region, QRect( topLeft, m_effectFrame->iconSize() ), sceneShader ); + m_iconTexture->render( region, QRect( topLeft, m_effectFrame->iconSize() ) ); m_iconTexture->unbind(); } @@ -1390,7 +1388,7 @@ void SceneOpenGL::EffectFrame::render( QRegion region, double opacity, double fr #endif m_oldTextTexture->bind(); - m_oldTextTexture->render( region, m_effectFrame->geometry(), sceneShader ); + m_oldTextTexture->render( region, m_effectFrame->geometry() ); m_oldTextTexture->unbind(); if( shader ) shader->setUniform( "opacity", (float)opacity * (float)m_effectFrame->crossFadeProgress() ); @@ -1411,7 +1409,7 @@ void SceneOpenGL::EffectFrame::render( QRegion region, double opacity, double fr if( !m_textTexture ) // Lazy creation updateTextTexture(); m_textTexture->bind(); - m_textTexture->render( region, m_effectFrame->geometry(), sceneShader ); + m_textTexture->render( region, m_effectFrame->geometry() ); m_textTexture->unbind(); } diff --git a/scene_opengl_egl.cpp b/scene_opengl_egl.cpp index 4d3a668d45..f24a09baab 100644 --- a/scene_opengl_egl.cpp +++ b/scene_opengl_egl.cpp @@ -278,7 +278,6 @@ void SceneOpenGL::paintBackground(QRegion region) GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer(); vbo->reset(); vbo->setUseColor(true); - vbo->setUseShader(true); vbo->setData(verts.count() / 2, 2, verts.data(), NULL); GLShader *shader = ShaderManager::instance()->pushShader(ShaderManager::ColorShader); shader->setUniform("offset", QVector2D(0, 0));