Some shaders are incompatible with each other when enabled.
kevinlekiller opened this issue · 2 comments
As mentioned in the README, the shaders are all run in 1 pass, which causes this issue.
I've been looking into and trying (unsuccesfully) to get the shaders to run individually (in pairs of frag + vert) which should solve this issue.
Resources:
GLRenderTarget : https://github.com/KDE/kwin/blob/Plasma/5.24/src/libkwineffects/kwinglutils.h#L382
GLVertexBuffer: https://github.com/KDE/kwin/blob/Plasma/5.24/src/libkwineffects/kwinglutils.h#L573
GLTexture: https://github.com/KDE/kwin/blob/Plasma/5.24/src/libkwineffects/kwingltexture.h#L41
https://www.khronos.org/opengl/wiki/Framebuffer_Object
Effects that use FBO's / VBO's:
https://github.com/KDE/kwin/blob/Plasma/5.24/src/effects/magnifier/magnifier.cpp
https://github.com/KDE/kwin/blob/Plasma/5.24/src/effects/lookingglass/lookingglass.cpp
https://github.com/KDE/kwin/blob/Plasma/5.24/src/effects/blur/blur.cpp
An update on this issue:
I've been trying for the past months to resolve this problem, I understand where I'm failing, but not sure how to succeed.
I've tried various things, but here's where I'm at:
Set a pointer to the current framebuffer for later use (GLFramebuffer::currentFramebuffer())
Creating a texture using GLTexture, creating (/ attaching the texture to) a FBO using GLFramebuffer.
Copying the current frame buffer to the FBO (blitFromFramebuffer).
Binding the FBO (to make it the current render target) (GLFramebuffer::pushFramebuffer).
Binding the shader. (calls glUseProgam(shader))
Setting the shader uniforms.
Binding the texture.
Rendering the window (effects->paintWindow()) ; This is then rendered to the FBO since it was bound.
Unbinding the texture.
Unbind the shader (stops using the shader program).
At this point, if I blit the previous framebuffer to the FBO (copy the FBO to the framebuffer effects->paintWindow() uses), that works fine. Then I unbind the FBO to return the previous framebuffer as the current one.
Where things don't work is if I try doing another shader pass, the buffer effects->paintWindow() reads from is not the same as the one it writes to, so the first shader pass is ignored.
I tried manually setting the read/write buffers (https://www.khronos.org/opengl/wiki/Default_Framebuffer#Color_buffers) and blitting but didn't succeed.
If I could figure out how to update the read buffer effects->paintWindow() between each shader pass then I could succeed.
Reading the source code of effects->paintWindow(), and backtracking, this is the final function that is called, but I can't see figured out which buffer it uses or if it can be updated: https://github.com/KDE/kwin/blob/Plasma/5.26/src/scenes/qpainter/scene_qpainter.cpp#L89
Another thing I tried is runnng effects->paintWindow() first, then using texture->render(), but this only ended up in a single color being rendered to a quarter of the screen.
Anyways, will keep trying things, hopefully will resolve this eventually.