From 571ac00bc0ac720bd70f8190c0749d0149c2e33a Mon Sep 17 00:00:00 2001 From: Matteo De Carlo Date: Fri, 5 Nov 2021 09:30:24 +0100 Subject: [PATCH] Added compilation framework for IMGUI example on linux (#340) --- CMakeLists.txt | 17 +++++++++++------ Example_ImGui/CMakeLists.txt | 32 +++++++++++++++++++++----------- Example_ImGui/Example_ImGui.cpp | 6 +++--- Example_ImGui/main_SDL2.cpp | 8 ++++---- 4 files changed, 39 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d501fc24..8280784c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,12 +23,17 @@ endif() add_subdirectory(WickedEngine) -option(WICKED_TESTS "Build WickedEngine tests" ON) -if (WICKED_TESTS) - add_subdirectory(Tests) -endif() - option(WICKED_EDITOR "Build WickedEngine editor" ON) if (WICKED_EDITOR) - add_subdirectory(Editor) + add_subdirectory(Editor) +endif() + +option(WICKED_TESTS "Build WickedEngine tests" ON) +if (WICKED_TESTS) + add_subdirectory(Tests) +endif() + +option(WICKED_IMGUI_EXAMPLE "Build WickedEngine imgui example" ON) +if (WICKED_TESTS) + add_subdirectory(Example_ImGui) endif() diff --git a/Example_ImGui/CMakeLists.txt b/Example_ImGui/CMakeLists.txt index b838befd7..20b83ca20 100644 --- a/Example_ImGui/CMakeLists.txt +++ b/Example_ImGui/CMakeLists.txt @@ -4,9 +4,20 @@ endif () set (SOURCE_FILES stdafx.cpp - Tests.cpp - Tests.h + Example_ImGui.cpp + Example_ImGui.h stdafx.h + ImGui/imconfig.h + ImGui/imgui.cpp + ImGui/imgui.h + ImGui/imgui_demo.cpp + ImGui/imgui_draw.cpp + ImGui/imgui_internal.h + ImGui/imgui_tables.cpp + ImGui/imgui_widgets.cpp + ImGui/imstb_rectpack.h + ImGui/imstb_textedit.h + ImGui/imstb_truetype.h ) if (WIN32) @@ -16,9 +27,9 @@ if (WIN32) Tests.rc ) - add_executable(Tests WIN32 ${SOURCE_FILES}) + add_executable(Example_ImGui WIN32 ${SOURCE_FILES}) - target_link_libraries(Tests PUBLIC + target_link_libraries(Example_ImGui PUBLIC WickedEngine_Windows ) else() @@ -26,16 +37,16 @@ else() main_SDL2.cpp ) - add_executable(Tests ${SOURCE_FILES}) + add_executable(Example_ImGui ${SOURCE_FILES}) - target_link_libraries(Tests PUBLIC + target_link_libraries(Example_ImGui PUBLIC WickedEngine Threads::Threads ) # Copy shaders to build and source folders just to be safe: add_custom_command( - TARGET Tests POST_BUILD + TARGET Example_ImGui POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/WickedEngine/shaders/spirv ${CMAKE_CURRENT_SOURCE_DIR}/shaders/spirv COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/WickedEngine/shaders/spirv ${CMAKE_CURRENT_BINARY_DIR}/shaders/spirv ) @@ -43,14 +54,13 @@ else() endif () if (MSVC) - set_property(TARGET Tests PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + set_property(TARGET Example_ImGui PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") endif () # Copy content to build folder: add_custom_command( - TARGET Tests POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/images ${CMAKE_CURRENT_BINARY_DIR}/images - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/sound ${CMAKE_CURRENT_BINARY_DIR}/sound + TARGET Example_ImGui POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/WickedEngine/${LIB_DXCOMPILER} ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/Content ${CMAKE_CURRENT_BINARY_DIR}/../Content ) diff --git a/Example_ImGui/Example_ImGui.cpp b/Example_ImGui/Example_ImGui.cpp index 5ab47a136..ace206633 100644 --- a/Example_ImGui/Example_ImGui.cpp +++ b/Example_ImGui/Example_ImGui.cpp @@ -64,9 +64,9 @@ bool ImGui_Impl_CreateDeviceObjects() imguiInputLayout.elements = { - { "POSITION", 0, FORMAT_R32G32_FLOAT, 0, (UINT)IM_OFFSETOF(ImDrawVert, pos), INPUT_PER_VERTEX_DATA }, - { "TEXCOORD", 0, FORMAT_R32G32_FLOAT, 0, (UINT)IM_OFFSETOF(ImDrawVert, uv), INPUT_PER_VERTEX_DATA }, - { "COLOR", 0, FORMAT_R8G8B8A8_UNORM, 0, (UINT)IM_OFFSETOF(ImDrawVert, col), INPUT_PER_VERTEX_DATA }, + { "POSITION", 0, FORMAT_R32G32_FLOAT, 0, (uint32_t)IM_OFFSETOF(ImDrawVert, pos), INPUT_PER_VERTEX_DATA }, + { "TEXCOORD", 0, FORMAT_R32G32_FLOAT, 0, (uint32_t)IM_OFFSETOF(ImDrawVert, uv), INPUT_PER_VERTEX_DATA }, + { "COLOR", 0, FORMAT_R8G8B8A8_UNORM, 0, (uint32_t)IM_OFFSETOF(ImDrawVert, col), INPUT_PER_VERTEX_DATA }, }; // Create pipeline diff --git a/Example_ImGui/main_SDL2.cpp b/Example_ImGui/main_SDL2.cpp index b2c1b399d..1e4ed3a9d 100644 --- a/Example_ImGui/main_SDL2.cpp +++ b/Example_ImGui/main_SDL2.cpp @@ -5,7 +5,7 @@ #include #include "sdl2.h" -int sdl_loop(Tests &tests) +int sdl_loop(Example_ImGui &tests) { SDL_Event event; @@ -50,7 +50,7 @@ int sdl_loop(Tests &tests) int main(int argc, char *argv[]) { - Tests tests; + Example_ImGui exampleImGui; // TODO: Place code here. wiStartupArguments::Parse(argc, argv); @@ -69,9 +69,9 @@ int main(int argc, char *argv[]) throw sdl2::SDLError("Error creating window"); } - tests.SetWindow(window.get()); + exampleImGui.SetWindow(window.get()); - int ret = sdl_loop(tests); + int ret = sdl_loop(exampleImGui); SDL_Quit(); return ret;