Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial Wayland support #442

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ if (NOT PPX_ANDROID)
set(GLFW_BUILD_TESTS FALSE CACHE BOOL "" FORCE)
set(GLFW_BUILD_DOCS FALSE CACHE BOOL "" FORCE)
set(GLFW_VULKAN_STATIC FALSE CACHE BOOL "" FORCE)
if (PPX_LINUX_WAYLAND)
set(GLFW_USE_WAYLAND TRUE CACHE BOOL "" FORCE)
endif()
add_subdirectory(${PPX_THIRD_PARTY_DIR}/glfw)
endif()

Expand Down
8 changes: 8 additions & 0 deletions docs/building_and_running.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ Install the following prerequisite packages before building:
sudo apt install libxrandr-dev libxinerama-dev libx11-dev libxcursor-dev libxi-dev libx11-xcb-dev clang mesa-vulkan-drivers cmake ninja-build
```

If building for Wayland, also install:

```
sudo apt install libwayland-dev wayland-protocols libxkbcommon-dev extra-cmake-modules
```

## Linux
```
git clone --recursive https://github.com/google/bigwheels
Expand All @@ -49,6 +55,8 @@ ninja -C build

Built binaries are written to `build/bin/`.

If building for Wayland, run CMake with `-DPPX_LINUX_WAYLAND=1`.

## Windows

- Make sure the "Graphics Tools" feature is enabled (Settings > System > "Optional features" > "Add a feature" > "Graphics Tools". This is required to have DX12 debug layers.
Expand Down
2 changes: 1 addition & 1 deletion src/ppx/grfx/vk/vk_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ Result Instance::ConfigureLayersAndExtensions(const grfx::InstanceCreateInfo* pC
#elif defined(PPX_LINUX_XLIB)
#error "Xlib not implemented"
#elif defined(PPX_LINUX_WAYLAND)
#error "Wayland not implemented"
mExtensions.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
#elif defined(PPX_MSW)
mExtensions.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
#endif
Expand Down
10 changes: 9 additions & 1 deletion src/ppx/grfx/vk/vk_swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,15 @@ Result Surface::CreateApiObjects(const grfx::SurfaceCreateInfo* pCreateInfo)
#elif defined(PPX_LINUX_XLIB)
#error "Xlib not implemented"
#elif defined(PPX_LINUX_WAYLAND)
#error "Wayland not implemented"
VkWaylandSurfaceCreateInfoKHR vkci = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
vkci.display = pCreateInfo->display;
vkci.surface = pCreateInfo->surface;

vkres = vkCreateWaylandSurfaceKHR(
ToApi(GetInstance())->GetVkInstance(),
&vkci,
nullptr,
&mSurface);
#elif defined(PPX_MSW)
VkWin32SurfaceCreateInfoKHR vkci = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
vkci.hinstance = pCreateInfo->hinstance;
Expand Down
9 changes: 6 additions & 3 deletions src/ppx/window_glfw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@
#elif defined(PPX_LINUX_XLIB)
#error "Xlib not implemented"
#elif defined(PPX_LINUX_WAYLAND)
#error "Wayland not implemented"
#include <wayland-client.h>
#endif

#include <GLFW/glfw3.h>
// clang-format off
#if defined(PPX_LINUX)
#if defined(PPX_LINUX_XCB)
# define GLFW_EXPOSE_NATIVE_X11
#elif defined(PPX_MSW)
# define GLFW_EXPOSE_NATIVE_WIN32
#elif defined(PPX_LINUX_WAYLAND)
# define GLFW_EXPOSE_NATIVE_WAYLAND
#endif
#include <GLFW/glfw3native.h>
// clang-format on
Expand Down Expand Up @@ -484,7 +486,8 @@ void WindowImplGLFW::FillSurfaceInfo(grfx::SurfaceCreateInfo* pCreateInfo) const
#elif defined(PPX_LINUX_XLIB)
#error "Xlib not implemented"
#elif defined(PPX_LINUX_WAYLAND)
#error "Wayland not implemented"
pCreateInfo->display = glfwGetWaylandDisplay();
pCreateInfo->surface = glfwGetWaylandWindow(mNative);
#elif defined(PPX_MSW)
pCreateInfo->hinstance = ::GetModuleHandle(nullptr);
pCreateInfo->hwnd = glfwGetWin32Window(mNative);
Expand Down
Loading