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

WIP Wayland backend for linux #996

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
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
7 changes: 4 additions & 3 deletions .github/workflows/build-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ jobs:
- name: Install dependencies
run: |
sudo apt update
sudo apt install libsdl2-dev ccache
sudo apt install libsdl2-dev ccache wayland-protocols libwayland-dev ninja-build

- name: Initial compile
run: |
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
CCACHE_NODIRECT=1 make -j$(nproc)
cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
echo no CCACHE_NODIRECT=1 make -j$(nproc)
cmake --build .

- name: Generate shader dump
run: |
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ include(CMakeDependentOption)

if(UNIX)
option(WICKED_LINUX_TEMPLATE "Build WickedEngine Linux template" ON)
option(WAYLAND_BACKEND "Build WickedEngine Wayland backend" ON)
elseif(WIN32)
option(WICKED_WINDOWS_TEMPLATE "Build WickedEngine Windows template" ON)
endif()
Expand Down
3 changes: 2 additions & 1 deletion Samples/Example_ImGui/Example_ImGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ void Example_ImGui::Initialize()
#ifdef _WIN32
ImGui_ImplWin32_Init(window);
#elif defined(SDL2)
ImGui_ImplSDL2_InitForVulkan(window);
IM_ASSERT(window.type == wi::platform::LinuxWindow::eSDLWindow);
ImGui_ImplSDL2_InitForVulkan(window.sdl_window);
#endif

IM_ASSERT(io.BackendRendererUserData == NULL && "Already initialized a renderer backend!");
Expand Down
21 changes: 11 additions & 10 deletions Samples/Example_ImGui_Docking/Example_ImGui_Docking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
#endif


#include "../WickedEngine/wiProfiler.h"
#include "../WickedEngine/wiBacklog.h"
#include "../WickedEngine/wiPrimitive.h"
#include "../WickedEngine/wiRenderPath3D.h"
#include "wiProfiler.h"
#include "wiBacklog.h"
#include "wiPrimitive.h"
#include "wiRenderPath3D.h"
#include "../Editor/ModelImporter.h"

#include <fstream>
Expand Down Expand Up @@ -174,7 +174,8 @@ void Example_ImGui::Initialize()
hWnd = window;
ImGui_ImplWin32_Init(window);
#elif defined(SDL2)
ImGui_ImplSDL2_InitForVulkan(window);
IM_ASSERT(window.type == wi::platform::LinuxWindow::eSDLWindow);
ImGui_ImplSDL2_InitForVulkan(window.sdl_window);
#endif

IM_ASSERT(io.BackendRendererUserData == NULL && "Already initialized a renderer backend!");
Expand Down Expand Up @@ -457,7 +458,7 @@ void Example_ImGuiRenderer::Update(float dt)
ImGui_Impl_CreateDeviceObjects();
}


#ifdef _WIN32
ImGui_ImplWin32_NewFrame();
#elif defined(SDL2)
Expand Down Expand Up @@ -681,7 +682,7 @@ void Example_ImGuiRenderer::Update(float dt)
bool bUseChild = false;
if (use_fixed_height > 0) bUseChild = true;
if(bUseChild) ImGui::BeginChild("##objectsc", ImVec2(0.0f, use_fixed_height), false, ImGuiWindowFlags_None); //ImGuiWindowFlags_AlwaysVerticalScrollbar

for (int i = 0; i < size; i++)
{
Entity e = scene.objects.GetEntity(i);
Expand Down Expand Up @@ -1029,7 +1030,7 @@ void Example_ImGuiRenderer::Update(float dt)
ImGui::EndTabBar();
}
}

if (ImGui::CollapsingHeader(ICON_MD_SETTINGS " Settings", ImGuiTreeNodeFlags_None)) //ImGuiTreeNodeFlags_DefaultOpen
{
ImGui::SetCursorPos(ImGui::GetCursorPos() + ImVec2(0.0f, 3.0f));
Expand Down Expand Up @@ -1390,7 +1391,7 @@ void Example_ImGuiRenderer::Update(float dt)
if (ImGui::Selectable(lua_history[i].c_str(), is_selected)) {
#ifdef _WIN32
strcpy_s(lua, lua_history[i].c_str());
#elif __linux__
#elif __linux__
strcpy(lua, lua_history[i].c_str());
#endif
bSetKeyBoardFocus = true;
Expand Down Expand Up @@ -1489,7 +1490,7 @@ void Example_ImGuiRenderer::Update(float dt)
}

float movespeed = CAMERAMOVESPEED;

if (imgui_io.KeyShift)
{
movespeed *= 3.0; //Speed up camera.
Expand Down
47 changes: 46 additions & 1 deletion Samples/Tests/main_SDL2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#include "stdafx.h"
#include "sdl2.h"
#include "Wayland/wiWaylandBackend.h"
#include "Wayland/wiWaylandWindow.h"
#include <wiPlatform.h>

int sdl_loop(Tests &tests)
{
Expand Down Expand Up @@ -61,7 +64,7 @@ int sdl_loop(Tests &tests)
return 0;
}

int main(int argc, char *argv[])
int main_sdl2(int argc, char *argv[])
{
Tests tests;
// TODO: Place code here.
Expand Down Expand Up @@ -89,3 +92,45 @@ int main(int argc, char *argv[])
SDL_Quit();
return ret;
}


void wayland_loop(wi::wayland::Backend &wwbackend, Tests &tests)
{
bool quit = false;
wwbackend.window.on_close = [&quit](wi::wayland::Window*w) { quit = true; };

while(!quit)
{
tests.Run();
if (wwbackend.dispatch() < 0)
break;
if (wwbackend.window.AcceptDesiredDimensions())
tests.SetWindow(&wwbackend.window);
}
}


bool main_wayland(int argc, char *argv[])
{
wi::wayland::Backend wwbackend;
if (!wwbackend.Init())
return false;
if (!wwbackend.CreateWindow("Wicked Engine Tests"))
return false;

Tests tests;
tests.SetWindow(&wwbackend.window);
wayland_loop(wwbackend, tests);

wwbackend.window.Deinit();
wwbackend.DeInit();

return true;
}

int main(int argc, char *argv[])
{
// Attempt to initialize wayland backend
if (!main_wayland(argc, argv))
main_sdl2(argc, argv);
}
19 changes: 19 additions & 0 deletions WickedEngine/.kdev4/WickedEngine.kdev4
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[Buildset]
BuildItems=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x01\x00\x00\x00\x18\x00W\x00i\x00c\x00k\x00e\x00d\x00E\x00n\x00g\x00i\x00n\x00e)

[CMake]
Build Directory Count=1
Current Build Directory Index-Host System=0

[CMake][CMake Build Directory 0]
Build Directory Path=/home/matteo/projects/WickedEngine/WickedEngine/cmake-build-debug
Build Type=Debug
CMake Binary=/usr/bin/cmake
CMake Executable=/usr/bin/cmake
Environment Profile=
Extra Arguments=
Install Directory=/usr/local
Runtime=Host System

[Project]
VersionControlSupport=kdevgit
81 changes: 76 additions & 5 deletions WickedEngine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,54 @@ else ()
if((${SDL_VERSION_MAJOR} GREATER_EQUAL 2) AND (${SDL2_VERSION_MINOR} GREATER_EQUAL 0) AND (${SDL2_VERSION_PATCH} GREATER_EQUAL 14))
add_compile_definitions(SDL2_FEATURE_CONTROLLER_LED=1)
endif()

if (WAYLAND_BACKEND)

find_package(PkgConfig REQUIRED)
pkg_check_modules(WAYLAND_CLIENT REQUIRED wayland-client)
pkg_check_modules(WAYLAND_SCANNER REQUIRED wayland-scanner)
pkg_check_modules(WAYLAND_PROTOCOLS REQUIRED wayland-protocols)
# Get variables
pkg_get_variable(WAYLAND_SCANNER_BIN wayland-scanner wayland_scanner)
pkg_get_variable(WAYLAND_PROTOCOLS_DATADIR wayland-protocols pkgdatadir)
################################################################################################################
# Wayland protocol generated code
function(GENERATE_XDG_PROTOCOLS)
# GENERATE XDG PROTOCOLS SOURCES
set(XDG_PROTOCOLS_SOURCES)
set(XDG_PROTOCOLS_HEADERS)
foreach(XML ${ARGN})
get_filename_component(XML_NAME "${XML}" NAME_WE)
MESSAGE("Generating C source code for ${XML} -> ${XML_NAME}")
add_custom_command(COMMAND ${WAYLAND_SCANNER_BIN}
ARGS private-code "${XML}" "${CMAKE_CURRENT_BINARY_DIR}/${XML_NAME}.c"
DEPENDS "${XML}"
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${XML_NAME}.c"
COMMENT "Generating \"${XML_NAME}\" protocol private code."
)
list(APPEND XDG_PROTOCOLS_SOURCES "${CMAKE_CURRENT_BINARY_DIR}/${XML_NAME}.c")

add_custom_command(COMMAND ${WAYLAND_SCANNER_BIN}
ARGS client-header "${XML}" "${CMAKE_CURRENT_BINARY_DIR}/${XML_NAME}.h"
DEPENDS "${XML}"
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${XML_NAME}.h"
COMMENT "Generating \"${XML_NAME}\" protocol header."
)
list(APPEND XDG_PROTOCOLS_HEADERS "${CMAKE_CURRENT_BINARY_DIR}/${XML_NAME}.h")
set(XDG_PROTOCOLS_SOURCES ${XDG_PROTOCOLS_SOURCES} PARENT_SCOPE)
set(XDG_PROTOCOLS_HEADERS ${XDG_PROTOCOLS_HEADERS} PARENT_SCOPE)
endforeach()
endfunction()

GENERATE_XDG_PROTOCOLS(
"${WAYLAND_PROTOCOLS_DATADIR}/stable/xdg-shell/xdg-shell.xml"
"${WAYLAND_PROTOCOLS_DATADIR}/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml"
)
file(GLOB WAYLAND_SOURCES CONFIGURE_DEPENDS Wayland/*.cpp)
file(GLOB WAYLAND_HEADERS CONFIGURE_DEPENDS Wayland/*.h)
set(WAYLAND_SOURCES ${WAYLAND_SOURCES} ${XDG_PROTOCOLS_SOURCES})
set(WAYLAND_HEADERS ${WAYLAND_HEADERS} ${XDG_PROTOCOLS_HEADERS})
endif()
endif()

add_subdirectory(LUA)
Expand All @@ -64,14 +112,16 @@ list(REMOVE_ITEM SOURCE_FILES offlineshadercompiler.cpp)
add_library(${TARGET_NAME} ${WICKED_LIBRARY_TYPE}
${SOURCE_FILES}
${HEADER_FILES}
${WAYLAND_SOURCES}
${WAYLAND_HEADERS}
)

if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
endif()

add_library(WickedEngine ALIAS ${TARGET_NAME})
set_target_properties(${TARGET_NAME} PROPERTIES PUBLIC_HEADER "${HEADER_FILES}")
set_target_properties(${TARGET_NAME} PROPERTIES PUBLIC_HEADER "${HEADER_FILES} ${WAYLAND_HEADERS}")

target_include_directories(${TARGET_NAME} SYSTEM PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
Expand Down Expand Up @@ -106,12 +156,15 @@ else ()

if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(${TARGET_NAME} PRIVATE
# C and C++ warnings
-Wuninitialized
#-Wwrite-strings
#-Winit-self
#-Wreturn-type
#-Wreorder
#-Werror=delete-non-virtual-dtor
# C++ only warnings
#$<$<COMPILE_LANGUAGE:CXX>:-Wreorder>
#$<$<COMPILE_LANGUAGE:CXX>:-Werror=delete-non-virtual-dtor>
# Treat warnings as errors
#-Werror
#uncomment this to stop the compilation at the first error
# -Wfatal-errors
Expand All @@ -120,19 +173,37 @@ else ()
# add some warnings and set them as errors
# read more details here: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
target_compile_options(${TARGET_NAME} PRIVATE
# C and C++ warnings
-Wuninitialized
-Wmaybe-uninitialized
-Wwrite-strings
-Winit-self
-Wreturn-type
-Wreorder
-Werror=delete-non-virtual-dtor
# C++ only warnings
$<$<COMPILE_LANGUAGE:CXX>:-Wreorder>
$<$<COMPILE_LANGUAGE:CXX>:-Werror=delete-non-virtual-dtor>
# Treat warnings as errors
-Werror
#uncomment this to stop the compilation at the first error
# -Wfatal-errors
)
endif()


if (WAYLAND_BACKEND)
target_include_directories(${TARGET_NAME}
PUBLIC ${WAYLAND_CLIENT_INCLUDE_DIRS}
# PRIVATE ${WAYLAND_CURSOR_INCLUDE_DIRS}
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
# PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/WickedEngine>
)

target_link_libraries(${TARGET_NAME}
PUBLIC ${WAYLAND_CLIENT_LIBRARIES}
# PRIVATE ${WAYLAND_CURSOR_LIBRARIES}
)
endif()

target_link_libraries(${TARGET_NAME} PRIVATE dl)

set(LIBDXCOMPILER "libdxcompiler.so")
Expand Down
Loading
Loading