From 1d362d38fd3eb1186bc849b33b6e27d13bfae7ac Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Tue, 12 Nov 2019 22:46:29 +0200 Subject: [PATCH] [libkwineffects] Restore GL_DRAW_FRAMEBUFFER binding in GLTexture::clear Summary: If an effect renders a window into an offscreen texture, it's very important that the window ends up in the offscreen render target rather than the default framebuffer object. However, that might be not the case if the OpenGL decoration renderer needs to create a texture atlas since the renderer calls GLTexture::clear() method, which might clobber the current GL_DRAW_FRAMEBUFFER binding. Reviewers: #kwin, davidedmundson Reviewed By: #kwin, davidedmundson Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D25365 --- libkwineffects/kwingltexture.cpp | 8 ++++++-- libkwineffects/kwingltexture.h | 1 - 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libkwineffects/kwingltexture.cpp b/libkwineffects/kwingltexture.cpp index 0ecce612b6..177b10542a 100644 --- a/libkwineffects/kwingltexture.cpp +++ b/libkwineffects/kwingltexture.cpp @@ -514,11 +514,15 @@ void GLTexture::clear() if (GLTexturePrivate::s_fbo) { // Clear the texture - glBindFramebuffer(GL_FRAMEBUFFER, GLTexturePrivate::s_fbo); + GLuint previousFramebuffer = 0; + glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, reinterpret_cast(&previousFramebuffer)); + if (GLTexturePrivate::s_fbo != previousFramebuffer) + glBindFramebuffer(GL_FRAMEBUFFER, GLTexturePrivate::s_fbo); glClearColor(0, 0, 0, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, d->m_texture, 0); glClear(GL_COLOR_BUFFER_BIT); - glBindFramebuffer(GL_FRAMEBUFFER, 0); + if (GLTexturePrivate::s_fbo != previousFramebuffer) + glBindFramebuffer(GL_FRAMEBUFFER, previousFramebuffer); } else { if (const int size = width()*height()) { uint32_t *buffer = new uint32_t[size]; diff --git a/libkwineffects/kwingltexture.h b/libkwineffects/kwingltexture.h index 965348332c..0aebab08f2 100644 --- a/libkwineffects/kwingltexture.h +++ b/libkwineffects/kwingltexture.h @@ -108,7 +108,6 @@ public: /** @short * Make the texture fully transparent - * Warning: this clobbers the current framebuffer binding except on fglrx */ void clear(); bool isDirty() const;