Opened 2 years ago

Closed 2 years ago

#9028 closed defect (fixed)

Python311: Wayland required but PyOpenGL EGL backend gives bad background

Reported by: Zach Pearson Owned by: Zach Pearson
Priority: blocker Milestone: 1.7
Component: Platform Version:
Keywords: Cc: Tom Goddard, Greg Couch
Blocked By: Blocking:
Notify when closed: Platform: all
Project: ChimeraX

Description

I built a Python 3.11 version of ChimeraX on Ubuntu 22.04, and on first start it complained that it couldn't get an OpenGL context. The interface worked, but not the graphics window.

Our __main__.py has long had code to force the use of XWayland on Wayland compositors; removing that code made the OpenGL error go away but the interface stopped drawing itself (except the graphics window, which worked).

I then added a line to set PYOPENGL_PLATFORM to egl if the WAYLAND_DISPLAY environment variable exists, and finally the interface and graphics window worked at the same time. However, the background becomes transparent if it is not set to white, and you get a 'winning at Solitaire on Windows XP' type effect if you drag the window or a model around.

set bgColor 0,0,0,100 seems to make the background white but also transparent. Set the background to white, then type set bgColor blue and the background doesn't change but occasionally the window behind ChimeraX will shine through with a blue tint.

Change History (7)

comment:1 by Eric Pettersen, 2 years ago

Component: UnassignedPlatform

comment:2 by Zach Pearson, 2 years ago

The background color setter in graphics/src/volume.py always sets the alpha of the incoming/requested color to 0, and it looks like Tom's intuition about that value being respected on Wayland but not X11 is correct. After hardcoding the alpha to 1 and reinstalling the graphics bundle, background colors other than white work.

comment:3 by Tom Goddard, 2 years ago

I guess you mean you set alpha = 1 in graphics/src/view.py (not volume.py)?

The view.py code has a comment that indicates that the alpha = 0 value is needed for saving images with transparent background:

    def set_background_color(self, rgba):
        import numpy
        color = numpy.array(rgba, dtype=numpy.float32)
        color[3] = 0	# For transparent background images.
        ...

It would be useful to figure out why ChimeraX 1.6 with Python 3.9 works on Wayland using XWayland while your Python 3.11 version does not work.

comment:4 by Zach Pearson, 2 years ago

Yes, that's the right file.

I don't think that it needs to be hardcoded to 1, that wouldn't be a good fix. Do users tend to always take screenshots that have transparent backgrounds? I suppose yes because that's the hardcoded value? We could set the background to transparent just before saving a screenshot then restore it later, and update current code to just respect the alpha of requested colors -- and whatever is necessary to blank the screen right between frames when the background is transparent.

1.6/3.9 ChimeraX works on Minsky because it uses X11 natively. I logged in and didn't see an option to switch between Gnome on X11 or Gnome on Wayland in the display manager window. Looking at the environment in a terminal there was no WAYLAND_DISPLAY variable.

comment:5 by Greg Couch, 2 years ago

In Chimera, we let users to optionally save an image of the graphics window with transparency so they could composite the image in other software. I'm pretty sure that it didn't change how the image was displayed in the GUI.

comment:6 by Zach Pearson, 2 years ago

As it turns out, PyOpenGL 3.1.5 will default to its X11 backend on Wayland unless told to use EGL. In 3.1.6, it will default to EGL unless told to use X11. Since EGL is not fully compatible with OpenGL, I think it's better to force Qt and PyOpenGL to use Xwayland for now. Where we currently set QT_QPA_PLATFORM to xcb we can add PYOPENGL_PLATFORM = x11.

comment:7 by Zach Pearson, 2 years ago

Resolution: fixed
Status: assignedclosed

For the Python 3.11 update, we make PyOpenGL use its x11 backend to match PyQt's xcb backend.

Note: See TracTickets for help on using tickets.