OGRECave / ogre

scene-oriented, flexible 3D engine (C++, Python, C#, Java)
https://ogrecave.github.io/ogre/
MIT License
3.93k stars 970 forks source link

Add Wayland support #3142

Closed joakimono closed 3 months ago

joakimono commented 3 months ago

This PR fixes issue #2432

Implement support for Wayland with EGL in GLSupport. The functionality is enabled at compile type by cmake option OGRE_GLSUPPORT_USE_WAYLAND, provided that EGL headers are found. Note that when Wayland is enabled, X11 is unavailable. Some new packages will need to be installed to compile it (tested on Debian 12): libwayland-dev libwayland-egl wayland-protocols pkg-config For Qt (in addition to default Core and Gui): At least also qtwayland5 and qttools5-private-dev. Tested with Qt 5.15.8.

Once compiled and installed, the feature can be tested with the sample browser. It is important to explicitly select wayland when starting the application as follows: SDL_VIDEODRIVER=wayland ./SampleBrowser

Likewise when using ApplicationContextQt: ./MyOgreQt -platform wayland or QT_QPA_PLATFORM=wayland ./MyOgreQt. Note: Ogre Qt and Wayland does not work yet.

This new feature has been tested on Debian 12 on WSL2. There are several things that should be tested and fixed before merging.

joakimono commented 3 months ago

Regarding loosing mouse motion events: It is lost if the user clicks on the window title line (or moves the window) and then clicks somewhere inside the window.

joakimono commented 3 months ago

With Wayland, if fullscreen is selected, but video mode is not selected to be the native resolution of the monitor, there will be alpha channel artifacts: e.g. windows below overlay elements will be partly visible. All open GL renderers are affected.

paroj commented 3 months ago

I think this is in a pretty good shape for merging now. The comment spam is mostly a checklist for myself as it might take me a few weeks until I can fix this up. Of course you can do the remaining fixes yourself too :)

other things to watch out:

joakimono commented 3 months ago

TestContext fails with a segmentation fault at RenderSystem::_createRenderWindow "OGRE VTest Context". It should be resolved before merging.

joakimono commented 3 months ago

ApplicationContextQt is still not functional. An error similar to: https://bugreports.qt.io/browse/QTBUG-123866 But it may be some missing configuration in our end. I want to try a newer version of Qt also.

paroj commented 3 months ago

ApplicationContextQt is still not functional. An error similar to: https://bugreports.qt.io/browse/QTBUG-123866 But it may be some missing configuration in our end. I want to try a newer version of Qt also.

it would be totally fine by me if Wayland support would be only available with Qt >= 6.5

joakimono commented 3 months ago

ApplicationContextQt is still not functional. An error similar to: https://bugreports.qt.io/browse/QTBUG-123866 But it may be some missing configuration in our end. I want to try a newer version of Qt also.

it would be totally fine by me if Wayland support would be only available with Qt >= 6.5

Ok. I will investigate further to see if a newer Qt version is beneficial

paroj commented 3 months ago

TestContext fails with a segmentation fault at RenderSystem::_createRenderWindow "OGRE VTest Context". It should be resolved before merging.

I guess the problem is that it does not pass any miscParams: https://github.com/OGRECave/ogre/blob/70d7c82530add72e1fe88e976a6c854352b1fce5/Tests/VisualTests/Context/src/TestContext.cpp#L126

which is a nice test case actually. We should assert instead of segfaulting in this case as on Vulkan: https://github.com/OGRECave/ogre/blob/70d7c82530add72e1fe88e976a6c854352b1fce5/RenderSystems/Vulkan/src/OgreVulkanWindow.cpp#L444

but yeah.. for merging we should either revert the CI to X11 or fix that

I think maintaining CI with X11 could be advantageous since X11 will likely stay prevalent for a few more years. For now, we could modify the "custombuild" target to just compile-test Wayland.

joakimono commented 3 months ago

Ok. I will investigate further to see if a newer Qt version is beneficial

Some of the interface is nicer for Qt 6.5+, but there will still be a need for including a private header, even at Qt 6.7. Specifically the wl_surface is not publically exposed in the new native interface. ref: https://planet.kde.org/david-redondo-2022-12-09-wayland-native-interface-in-qt-6-5/

Since an implementation need to use QtGui::Private and deal with version-specific includes anyways, I do not see the point of restricting Ogre with Wayland to 6.5+ (unless there are other features unknown to me). Qt 6 also requires c++17.

paroj commented 3 months ago

tested this locally on Ubuntu 22.04 and added some final fixes. I would merge this next, if it is done from your side.

Out of curiosity as I did not test: does Wayland on Qt work in the current state?

joakimono commented 3 months ago

Out of curiosity as I did not test: does Wayland on Qt work in the current state?

No it does not. I suspect there is something missing regarding handling of the wl_surface but I do not know what. Maybe somehow initalise xdg_surface or indicate that it is a parent window. But these are guesses. I don't have time to look more into this for the time being.

paroj commented 3 months ago

No it does not.

I just tested it on Ubuntu 22.04 & Qt 6.2.4 and I get an undecorated window with the wrong resolution. However input is already working. So likely not much is missing.