JeDy111
Posts: 24
Joined: Tue Sep 03, 2019 8:35 pm

Pi3D transparent background on Pi4

Sat Oct 19, 2019 8:27 pm

Hi,

The transparent background of a Pi3d display, such as in the Raspberry_Rain.py example, works fine on my Pi2 and on my Pi3. However, when I run the same Pi3D script on my Pi4, the background is black, whether or not I activate the "Open GL driver with fake KMS" in raspi-config and allocate 128 MB to the GPU as recommended for the Pi4 in the Pi3D documentation.

Image

Do you experience the same thing?
Do you have any idea why? and how to fix it and get a transparent background with Pi3D on a Pi4 ?

Thanks for your help

JeDy111
Posts: 24
Joined: Tue Sep 03, 2019 8:35 pm

Re: Pi3D transparent background on Pi4

Wed Oct 23, 2019 12:58 pm

Hi,

It seems the mesa-v3d-VC6 will soon get updates on alpha support:
Gitlab - mesa / src / gallium / drivers / v3d - 21 Oct - Revert "v3d: do not report alpha-test as supported"

In the meantime, do you know if there is a workaround?
Maybe using an other graphic library?

Just to be sure the issue is related to to the Fake KMS driver and not to my setup, has someone been able to reproduce the issue?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7416
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Pi3D transparent background on Pi4

Wed Oct 23, 2019 1:31 pm

The removal or reporting alpha-test as supported in https://gitlab.freedesktop.org/kusma/me ... 5415d94336 was only 2 weeks ago, so the revert is most likely a nop against the version of Mesa shipped with Raspbian.

Are you running with Full KMS or Fake KMS on the Pi2/3? If not then please do so. A baseline is to determine whether it is something in the 3D rendering within the vc4 (Pi2/3) or v3d (Pi4) drivers, or something that is incompatible with Mesa generally in pi3d.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

JeDy111
Posts: 24
Joined: Tue Sep 03, 2019 8:35 pm

Re: Pi3D transparent background on Pi4

Wed Oct 23, 2019 4:20 pm

Hi 6by9,

Thanks for your reply.

I think it is related to the v3d driver.

I have run these two tests on a pi2. The only difference is uncommenting the #dtoverlay=vc4-fkms-v3d line in /boot/config.txt

Code: Select all

[all]
#dtoverlay=vc4-fkms-v3d
gpu_mem=128
=> (0,0,0,0) RGBA background is transparent

Code: Select all

[all]
dtoverlay=vc4-fkms-v3d
gpu_mem=128
=> (0,0,0,0) RGBA background is black, no alpha

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7416
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Pi3D transparent background on Pi4

Wed Oct 23, 2019 4:24 pm

If you're commenting out "dtoverlay=vc4-fkms-v3d" on the Pi2 then you are comparing the legacy GLES driver against Mesa. Two entirely different stacks.

Leave "dtoverlay=vc4-fkms-v3d" present on both systems, and then you're comparing the Mesa vc4 driver vs the Mesa v3d driver. That is the test I want to know the result of.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

JeDy111
Posts: 24
Joined: Tue Sep 03, 2019 8:35 pm

Re: Pi3D transparent background on Pi4

Wed Oct 23, 2019 4:29 pm

For both pi2 and pi4, the background has no alpha when "dtoverlay=vc4-fkms-v3d" is present.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7416
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Pi3D transparent background on Pi4

Wed Oct 23, 2019 4:53 pm

Thank you for running the test.
So it appears to be a generic Mesa thing, or potentially the way that Pi3D is driving Mesa.

Can you post an image of what you get with Mesa? Is it that it removes the desktop frame buffer? In which case that is probably expected as the way that DRM/KMS drives the screen. If you want to render on top of the desktop then you have to use EGL composition.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

JeDy111
Posts: 24
Joined: Tue Sep 03, 2019 8:35 pm

Re: Pi3D transparent background on Pi4

Wed Oct 23, 2019 5:45 pm

With legacy GLES ( #dtoverlay=vc4-fkms-v3d )
https://pasteboard.co/IDkH8yB.jpg
=> no window borders and title
=> transparency

With MESA ( dtoverlay=vc4-fkms-v3d )
https://pasteboard.co/IDkGm5u.jpg
=> displayed in a window with borders and title
=> no transparency

Sorry for the poor picture quality - scrot does not take the Pi3D layer (at least with Legacy GLES)

Note : I have added width and height to the Pi3D display so we can see the difference.
With MESA driver, when Pi3D display is full screen, the raspberries are displayed on a black background.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7416
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Pi3D transparent background on Pi4

Wed Oct 23, 2019 6:20 pm

OK, that's the legacy driver allowing you to do the wrong thing. It renders directly to a layer that is then composed but the hvs over the top of the desktop without the knowledge of X.
Mesa is using egl to do the composition into a window, and I suspect that window is not allowed to be alpha blended with the background.

If you quit X and run it from the console then you should be able to do the alpha blending with the underlying framebuffer. (that does assume pi3d does the right thing with talking to drm for rendering).

If pi3d works with mesa and fkms, then I'd expect it to work on an x86 machine too. Is there any way you can try it there?
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

JeDy111
Posts: 24
Joined: Tue Sep 03, 2019 8:35 pm

Re: Pi3D transparent background on Pi4

Wed Oct 23, 2019 7:07 pm

I get the same behavior on x86 as on Pi2 and Pi4 with the MESA driver : windowed when not full screen, and black background.

I get EGL errors when I try to run Pi3D from the console on Pi2 and Pi4, MESA driver enabled.

The Pi3D FAQ mentions:
From RPi4 onwards you have to use the fake KMS driver and start the X11 server to run pi3d.

JeDy111
Posts: 24
Joined: Tue Sep 03, 2019 8:35 pm

Re: Pi3D transparent background on Pi4

Thu Oct 24, 2019 2:09 pm

Does it mean the issue comes from EGL itself or the way Pi3D uses EGL?

EGL is supposed to handle alpha, if I refer to minimal example of creating an RGBA-format window that allows rendering with OpenGL ES on https://www.khronos.org/registry/EGL/sdk

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7416
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Pi3D transparent background on Pi4

Thu Oct 24, 2019 3:25 pm

If x86 does the same as the Pi via Mesa, then that sounds like it is the way Pi3d is driving EGL.
My understanding of EGL is the same as yours in that it should be possible to render to a window with alpha, but X may block that.

The reference to fake KMS in the Pi3D FAQ is because that is the only way to access the 3D hardware on the Pi4. Earlier Pis had a legacy GLES driver that ran on the GPU via an IPC. The Pi4 does not have that, so it's Mesa or nothing.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

JeDy111
Posts: 24
Joined: Tue Sep 03, 2019 8:35 pm

Re: Pi3D transparent background on Pi4

Thu Oct 24, 2019 4:08 pm

Thanks a lot for your insight 6by9 :)

I guess the next step for solving the issue is to ask the Pi3D project team.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7416
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Pi3D transparent background on Pi4

Thu Oct 24, 2019 4:41 pm

JeDy111 wrote:
Thu Oct 24, 2019 4:08 pm
I guess the next step for solving the issue is to ask the Pi3D project team.
I would. I believe there are mechanisms to allow for alpha blended windows, but I don't know what they are.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

JeDy111
Posts: 24
Joined: Tue Sep 03, 2019 8:35 pm

Re: Pi3D transparent background on Pi4

Fri Oct 25, 2019 9:31 am

I have asked on their github
https://github.com/pi3d/pi3d_demos/issues/9

Regarding mechanisms to allow for alpha blended window, I have tried to compile the EGL SDK minimal exemple of creating an RGBA-format window but I am struggling with meson errors to build the EGL SDK and gcc compilation error on the "typedef ... NativeWindowType;" line.

User avatar
paddyg
Posts: 2390
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Pi3D transparent background on Pi4

Sat Oct 26, 2019 8:49 pm

Hi, Yes it's a pity about the transparent background that used to be available with the old bcm display surface.

For the RPi4 I get pi3d to check /proc/modules for vc4 https://github.com/tipam/pi3d/blob/1478 ... t__.py#L81 and if it's there it behaves as on other X11 systems w.r.t location and loading of EGL and GLESv2 so https://github.com/tipam/pi3d/blob/1478 ... __.py#L103 and https://github.com/tipam/pi3d/blob/1478 ... nGL.py#L42

When I initially started using X11 for pi3d I don't remember the transparency being an option but there does seem to be something now. Setting x window properties from python using ctypes is a bit of a nightmare but I did make a bit of progress when I had to sort all the sudden changes when the RPi4 was suddenly sprung on us! I'm not sure that the suggested fixes will work on the RPi https://stackoverflow.com/questions/399 ... ow-in-xlib

Paddy
6by9 wrote:
Wed Oct 23, 2019 6:20 pm
If pi3d works with mesa and fkms, then I'd expect it to work on an x86 machine too. Is there any way you can try it there?
yes, I basically do all the development on my ubuntu laptop and only test it on RPi and windows as a final stage. Transparent background hasn't worked on x86 x11 or pygame based computers since day one (2014). But I will see if I can get this _NET_WM_WINDOW_OPACITY option to work. I might actually start off trying to get it to work using https://github.com/paddywwoof/rust_pi3d/ which access the X11 window via SDL2 and that does seem to have https://wiki.libsdl.org/SDL_SetWindowOpacity. If I can get some joy with that then I might start to wrestle with the construction of XInternAtoms etc.
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

User avatar
paddyg
Posts: 2390
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Pi3D transparent background on Pi4

Sat Oct 26, 2019 9:42 pm

OK the rust_pi3d transparency works on my laptop and was easy enough to do. But it's setting the opacity of the whole window not just the background. I will have another think about this.
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

JeDy111
Posts: 24
Joined: Tue Sep 03, 2019 8:35 pm

Re: Pi3D transparent background on Pi4

Sun Oct 27, 2019 11:02 am

Thanks a lot Paddy for working this out :)

Let me know if I can help you.

User avatar
paddyg
Posts: 2390
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Pi3D transparent background on Pi4

Sun Oct 27, 2019 11:58 am

It's something that's been niggling for a while.

Just to check; for your purposes is it no use making the whole window partly transparent (as attached) as opposed to the background only?
scrshot.jpg
scrshot.jpg (104.9 KiB) Viewed 1481 times
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

JeDy111
Posts: 24
Joined: Tue Sep 03, 2019 8:35 pm

Re: Pi3D transparent background on Pi4

Sun Oct 27, 2019 1:44 pm

I confirm that I need transparency on the background only, not on shapes.

If needed, transparency on some shapes can still be obtained with the set_alpha() method.

For compositing purposes, an option to display or hide the window frame (title bar and borders) would be great.
It would allow for the same behavior as with the legacy driver, which is well suited to mix Pi3D rendering and others layers.

User avatar
paddyg
Posts: 2390
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Pi3D transparent background on Pi4

Thu Oct 31, 2019 4:10 pm

OK, I've played around with X11 a bit. The consensus (when I can find anyone interested in this) seems to be that it could be done by taking a snap of what was on the screen then using it as background for the window. However this is unsatisfactory if the stuff behind the pi3d window is changing (a video say).

The alternative approach would be to have a system using KMS like this https://www.raspberrypi.org/forums/view ... 7#p1499181 but the prospect of getting that to work from python is a bit daunting...
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7416
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Pi3D transparent background on Pi4

Thu Oct 31, 2019 4:39 pm

paddyg wrote:
Thu Oct 31, 2019 4:10 pm
OK, I've played around with X11 a bit. The consensus (when I can find anyone interested in this) seems to be that it could be done by taking a snap of what was on the screen then using it as background for the window. However this is unsatisfactory if the stuff behind the pi3d window is changing (a video say).
Not my area of expertise, but does https://stackoverflow.com/questions/406 ... -backgroun help? That seems to have at least partial alpha support within the window, although it is the reverse of what you wanted
paddyg wrote:The alternative approach would be to have a system using KMS like this https://www.raspberrypi.org/forums/view ... 7#p1499181 but the prospect of getting that to work from python is a bit daunting...
Note the title of that example
"Trying to get OpenGL ES screen on RPi4 without X"
DRM and KMS is not accessible if you have X running. DRM supports a single authenticated client at any one time, and X will have registered as that client.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

User avatar
paddyg
Posts: 2390
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Pi3D transparent background on Pi4

Thu Oct 31, 2019 8:29 pm

@6by9, Thanks for that link, it seems to do what the author says. I will have a go, initially, to get the C version working with a transparent background and a solid cube! Then the ordeal of getting it to do the same from python.

The option of using pi3d without X11 desktop is actually preferable for some dedicated apps where the frame rate gets a boost from lightening the CPU overhead.

Thanks again.
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

User avatar
paddyg
Posts: 2390
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Pi3D transparent background on Pi4

Thu Oct 31, 2019 10:08 pm

Works OK in C and on my laptop. Will try it on Raspberry Pi next. https://www.youtube.com/watch?v=9_GvvyY ... e=youtu.be

All the OpenGL code seems to be fixed pipeline stuff but hopefully it will convert. :)

PS Sadly, though it compiles and runs without error on the RPi4 I can't get the transparent background to work.
PPS Thought it might be because there wasn't an adequate OpenGL compositing manager. On ubuntu there seems to be compiz running which doesn't appear on raspbian. However, though it installed and semi scrambled the desktop when I ran it, the demo still didn't work. Ah, buster has xcompmgr, maybe I need to start that or something...

PPPS YES, that's exactly what's needed. Although just running xcompmgr in a terminal produces some weird disapearing windows and error messages it does make the demo work. So all I have to do is get it working from pi3d.
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

JeDy111
Posts: 24
Joined: Tue Sep 03, 2019 8:35 pm

Re: Pi3D transparent background on Pi4

Fri Nov 01, 2019 9:24 am

What about using DispmanX ?

Return to “Graphics programming”