Bug 163054 - wrong rendering by using OpenGL
Summary: wrong rendering by using OpenGL
Status: RESOLVED FIXED
Alias: None
Product: kwin
Classification: Plasma
Component: compositing (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
: 163683 168926 170965 174988 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-06-02 11:53 UTC by Painkiller101
Modified: 2008-12-15 08:07 UTC (History)
5 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Rendering with OpenGL (192.16 KB, image/jpeg)
2008-06-04 12:33 UTC, Painkiller101
Details
Rendering with XRender (192.28 KB, image/jpeg)
2008-06-04 12:35 UTC, Painkiller101
Details
Change OpenGL blending formula (855 bytes, patch)
2008-06-19 18:17 UTC, lucas
Details
Use premultiplied blending (3.21 KB, patch)
2008-06-20 12:06 UTC, lucas
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Painkiller101 2008-06-02 11:53:35 UTC
Version:            (using Devel)
Installed from:    Compiled sources
OS:                Linux

I created the 'Glassified' plasma theme (http://kde-look.org/content/show.php/Glassified?content=81388) and discovered a bug by using OpenGL as the render engine for desktop effects.
While XRender renders my theme correctly OpenGL does not at all. Primarily the panel and dialogs are darker there. It seems to me that OpenGL turns white into black (but only the panel and dialog).
Comment 1 Painkiller101 2008-06-04 12:33:51 UTC
Created attachment 25111 [details]
Rendering with OpenGL

The panel rendered with OpenGL
Comment 2 Painkiller101 2008-06-04 12:35:17 UTC
Created attachment 25112 [details]
Rendering with XRender

The panel rendered with xrender (That's how it should look like)
Comment 3 Painkiller101 2008-06-04 12:35:48 UTC
I've tested this bug more and found that when the center of the panel-background.svg is completly transparent no plasmoid is shom in the panel.
They are neither clickable nor visible. Just away.

i don#t know really how much this is a fault of KDE or OpenGL, but it's definitly a problem of transparency for the panel and dialogs when using OpenGL as the render engine for kde4 and desktop effects.
Comment 4 Aaron J. Seigo 2008-06-10 11:47:48 UTC
*** Bug 163683 has been marked as a duplicate of this bug. ***
Comment 5 Aaron J. Seigo 2008-06-10 11:49:09 UTC
having used glassified with opengl compositing with success, i'm guessing this is a driver / kwin mismatch. i was using an intel 3100 chipset, and it worked lovely (love the theme, btw =); what chipset and driver are you using?

(then i'll triage this over to either kwin or mark it as an upstream x.org/driver issue since this is not a plasma issue)
Comment 6 lucas 2008-06-10 13:03:16 UTC
I can confirm this bug with nVidia drivers 169.12.

I use the theme all the time (Alternating with Akoma) and I didn't even know it was being rendered inferiorly. ^_^;
Comment 7 Painkiller101 2008-06-10 13:45:41 UTC
@aaron
Nice to hear that it works correctly with non-Nvidia chipsets (and that you like my theme).
I'm using the same Nvidia drivers like Lucas with a GeForce 7200gs.
Seems to be no problem of plasma though.   
Comment 8 lucas 2008-06-19 18:09:53 UTC
Problem is caused by different blending formulas. OpenGL uses:

Res = (1 - Opacity) * Bg + Opacity * Fg

XRender uses:

Res = (1 - Opacity) * Bg + Fg

As XRender produces the same results as what is shown in Inkscape I'll assume the OpenGL formula is incorrect.
Comment 9 lucas 2008-06-19 18:17:38 UTC
Created attachment 25456 [details]
Change OpenGL blending formula
Comment 10 lucas 2008-06-19 18:41:35 UTC
Comment on attachment 25456 [details]
Change OpenGL blending formula

Didn't test the patch, fails miserably.
Comment 11 lucas 2008-06-20 12:06:23 UTC
Created attachment 25471 [details]
Use premultiplied blending

I can't work out how to test the shader opacity function but this one works for
normal rendering.
Comment 12 Painkiller101 2008-06-24 10:56:10 UTC
Thank you Lucas for finding out and patching the problem!

Unfortunately i am not able to test it, because i use precompiled kde4-packages from opensuse and don't know really how to recompile it. 

What's next? Will it be commited? Many users would be thankful.

Lucas, is it possible for you to send me your compiled and patched file?
Comment 13 Lubos Lunak 2008-06-24 19:20:36 UTC
The first formula from comment #8 looks correct to me, not the second one, unless I'm missing something. Rivo?
Comment 14 Rivo Laks 2008-06-25 19:10:29 UTC
For OpenGL, the correct formula is definitely the first one in comment #8.
But the second formula might be correct as well :-)
XRender probably uses premultiplied pixmaps for blending, in which case the second formula is correct for XRender: it just assumes that Fg has already been multiplied by opacity. So in the end the two formulas are actually equal, just that in XRender's case, Opacity * Fg has been optimized.
Comment 15 lucas 2008-06-26 03:52:37 UTC
Yup, that's correct.

This bug however is for the blending of the translucent canvas of an "opaque" window that has such as the panel. The Plasma panel's window canvas has premultiplied contents so it is displayed incorrectly in OpenGL mode. There are two ways of correcting it:

1) Convert OpenGL to use premultiplied opacity canvases and premultiply all window opacities (My second patch does this).
2) Have the Plasma panel depremultiply the opacity of it's canvas before sending to KWin for display and then remultiply in the XRender renderer.

The second method is most likely the correct choice but it doesn't look to be the most efficient compared to the first.
Comment 16 lucas 2008-07-05 17:44:48 UTC
Recent changes to the Plasma panel resize configuration thingy has made this bug MUCH more apparent. Now when in OpenGL mode the entire panel configuration is rendered one way but when you hover over it with the mouse it changes, causing massive amounts of glitching.

This needs to be fixed before RC1.
Comment 17 lucas 2008-07-05 18:44:44 UTC
I am mistaken, the panel glitch is not caused by this bug. However it does only effect OpenGL mode.
Comment 18 lucas 2008-07-23 18:08:54 UTC
Ignore all my previous comments, OpenGL is fine.

What is not fine however is:
1) Plasma doesn't depremultiply the SVG rasters after they have been generated so the can be correctly rendered in windows, and
2) XRender needs to premultiply window contents before they are rendered to compensate.
Comment 19 lucas 2008-08-04 13:35:09 UTC
SVN commit 841974 by lmurray:

X ARGB windows are stored with alpha premultiplied. Adjusted OpenGL rendering to accomodate that and therefore fixed incorrect rendering of windows with transparencies such as the Plasma panel.
BUG: 163054


 M  +8 -10     scene_opengl.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=841974
Comment 20 lucas 2008-08-12 10:57:18 UTC
*** Bug 168926 has been marked as a duplicate of this bug. ***
Comment 21 Painkiller101 2008-08-13 17:27:17 UTC
Thank you for this final fix! 

Are there any plans for backporting it to kde 4.1?
Comment 22 lucas 2008-11-13 09:03:34 UTC
*** Bug 174988 has been marked as a duplicate of this bug. ***
Comment 23 lucas 2008-12-15 08:07:59 UTC
*** Bug 170965 has been marked as a duplicate of this bug. ***