From 0e008a1beb0ddefb81b2d4642825cef8aabe6c21 Mon Sep 17 00:00:00 2001 From: redstrate <54911369+redstrate@users.noreply.github.com> Date: Fri, 14 Aug 2020 19:56:27 -0400 Subject: [PATCH] Use fetch content on macOS for SPIRV-Cross, and fix compilation using the new Windows changes --- CMakeLists.txt | 24 +++++++++++++----------- engine/gfx/metal/src/gfx_metal.mm | 4 ++-- engine/renderer/src/shadercompiler.cpp | 9 --------- platforms/mac/main.mm.in | 20 ++++++++++---------- tools/common/include/debugpass.hpp | 4 ++-- tools/common/src/commoneditor.cpp | 1 + tools/common/src/debugpass.cpp | 2 +- tools/shadercompiler/main.cpp | 8 -------- 8 files changed, 29 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bfaefd4..07bc526 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,16 +14,6 @@ include(${CMAKE_CURRENT_LIST_DIR}/cmake/Common.cmake) include(${CMAKE_CURRENT_LIST_DIR}/cmake/AddPlatformExecutable.cmake) include(FetchContent) -if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" AND NOT IOS) - message("macOS build detected!") - - set(ENABLE_METAL TRUE) - set(ENABLE_DARWIN TRUE) - set(ENABLE_MACOS TRUE) - - set(CMAKE_XCODE_GENERATE_SCHEME OFF) -endif() - if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") message("Linux build detected!") @@ -83,6 +73,18 @@ macro(manual_download) set(CMAKE_FOLDER "") endmacro() +if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" AND NOT IOS) + message("macOS build detected!") + + set(ENABLE_METAL TRUE) + set(ENABLE_DARWIN TRUE) + set(ENABLE_MACOS TRUE) + + set(CMAKE_XCODE_GENERATE_SCHEME OFF) + + manual_download() +endif() + if(${CMAKE_SYSTEM_NAME} STREQUAL "iOS") message("iOS build detected!") @@ -120,7 +122,7 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "WindowsStore") manual_download() endif() -if(NOT ENABLE_IOS AND NOT ENABLE_TVOS AND NOT ENABLE_WINDOWS) +if(NOT TARGET spirv-cross-cpp) find_package(spirv_cross_core REQUIRED) find_package(spirv_cross_glsl REQUIRED) find_package(spirv_cross_cpp REQUIRED) diff --git a/engine/gfx/metal/src/gfx_metal.mm b/engine/gfx/metal/src/gfx_metal.mm index e61eb58..cf18b6a 100755 --- a/engine/gfx/metal/src/gfx_metal.mm +++ b/engine/gfx/metal/src/gfx_metal.mm @@ -431,7 +431,7 @@ GFXPipeline* GFXMetal::create_graphics_pipeline(const GFXGraphicsPipelineCreateI { std::string vertex_src; if(info.shaders.vertex_path.empty()) { - vertex_src = info.shaders.vertex_src; + vertex_src = std::get(info.shaders.vertex_src); } else { const auto vertex_path = utility::format("{}.msl", info.shaders.vertex_path); @@ -453,7 +453,7 @@ GFXPipeline* GFXMetal::create_graphics_pipeline(const GFXGraphicsPipelineCreateI { std::string fragment_src; if(info.shaders.fragment_path.empty()) { - fragment_src = info.shaders.fragment_src; + fragment_src = std::get(info.shaders.fragment_src); } else { const auto fragment_path = utility::format("{}.msl", info.shaders.fragment_path); diff --git a/engine/renderer/src/shadercompiler.cpp b/engine/renderer/src/shadercompiler.cpp index 396ed6b..5b4434f 100755 --- a/engine/renderer/src/shadercompiler.cpp +++ b/engine/renderer/src/shadercompiler.cpp @@ -1,17 +1,8 @@ #include "shadercompiler.hpp" -#include - -#if defined(PLATFORM_IOS) || defined(PLATFORM_TVOS) || defined(PLATFORM_WINDOWS) #include #include #include -#else -#include -#include -#include -#include -#endif #include "file.hpp" #include "log.hpp" diff --git a/platforms/mac/main.mm.in b/platforms/mac/main.mm.in index 995ebed..4e342c3 100755 --- a/platforms/mac/main.mm.in +++ b/platforms/mac/main.mm.in @@ -294,13 +294,13 @@ CGRect toTopLeftSpace(NSRect frame) { return NSRectToCGRect(frame); } -Rectangle platform::get_monitor_resolution() { +prism::Rectangle platform::get_monitor_resolution() { auto frame = toTopLeftSpace([[NSScreen mainScreen] frame]); return {static_cast(frame.origin.x), static_cast(frame.origin.y), static_cast(frame.size.width), static_cast(frame.size.height)}; } -Rectangle platform::get_monitor_work_area() { +prism::Rectangle platform::get_monitor_work_area() { auto frame = toTopLeftSpace([[NSScreen mainScreen] visibleFrame]); return {static_cast(frame.origin.x), static_cast(frame.origin.y), static_cast(frame.size.width), static_cast(frame.size.height)}; @@ -310,11 +310,11 @@ NSPoint get_fixed_cursor_point(NSPoint point) { return {point.x, std::max(windows[0]->currentHeight - point.y, 0.0)}; } -Offset platform::get_cursor_position() { +prism::Offset platform::get_cursor_position() { return {static_cast(windows[0]->currentMousePos.x), static_cast(windows[0]->currentMousePos.y)}; } -Offset platform::get_screen_cursor_position() { +prism::Offset platform::get_screen_cursor_position() { return {static_cast([NSEvent mouseLocation].x), static_cast([[NSScreen mainScreen] frame].size.height - [NSEvent mouseLocation].y)}; } @@ -330,17 +330,17 @@ std::tuple platform::get_right_stick_position() { return {rightX, rightY}; } -Extent platform::get_window_size(const int index) { +prism::Extent platform::get_window_size(const int index) { auto window = get_window(index); return {static_cast(window->currentWidth), static_cast(window->currentHeight)}; } -Extent platform::get_window_drawable_size(const int index) { +prism::Extent platform::get_window_drawable_size(const int index) { auto window = get_window(index); return {static_cast(window->currentWidth * window->window.backingScaleFactor), static_cast(window->currentHeight * window->window.backingScaleFactor)}; } -Offset platform::get_window_position(const int index) { +prism::Offset platform::get_window_position(const int index) { auto window = get_window(index); auto frame = toTopLeftSpace([window->window contentRectForFrameRect:[window->window frame]]); @@ -363,7 +363,7 @@ bool platform::get_mouse_button_down(const int button) { return (button + 1) & [NSEvent pressedMouseButtons]; } -void platform::set_window_position(const int index, const Offset offset) { +void platform::set_window_position(const int index, const prism::Offset offset) { auto window = get_window(index); NSPoint p; @@ -373,7 +373,7 @@ void platform::set_window_position(const int index, const Offset offset) { [window->window setFrameTopLeftPoint:p]; } -void platform::set_window_size(const int index, const Extent extent) { +void platform::set_window_size(const int index, const prism::Extent extent) { auto window = get_window(index); NSSize size; @@ -391,7 +391,7 @@ void platform::set_window_title(const int index, const std::string_view title) { void platform::mute_output() {} void platform::unmute_output() {} -int platform::open_window(const std::string_view title, const Rectangle rect, const WindowFlags flags) { +int platform::open_window(const std::string_view title, const prism::Rectangle rect, const WindowFlags flags) { NativeWindow* native = new NativeWindow(); native->index = windows.size(); GameView* del = [[GameView alloc] init]; diff --git a/tools/common/include/debugpass.hpp b/tools/common/include/debugpass.hpp index 6416091..ac7e5c9 100755 --- a/tools/common/include/debugpass.hpp +++ b/tools/common/include/debugpass.hpp @@ -47,7 +47,7 @@ class DebugPass : public Pass { public: void initialize() override; - void resize(const Extent extent) override; + void resize(const prism::Extent extent) override; void render_scene(Scene& scene, GFXCommandBuffer* commandBuffer) override; @@ -70,7 +70,7 @@ public: private: void createOffscreenResources(); - Extent extent; + prism::Extent extent; std::vector selectable_objects; diff --git a/tools/common/src/commoneditor.cpp b/tools/common/src/commoneditor.cpp index 93a241d..9d7cb57 100755 --- a/tools/common/src/commoneditor.cpp +++ b/tools/common/src/commoneditor.cpp @@ -18,6 +18,7 @@ #include "gfx.hpp" #include "gfx_commandbuffer.hpp" #include "imgui_utility.hpp" +#include "screen.hpp" const std::map imToPl = { {ImGuiKey_Tab, InputButton::Tab}, diff --git a/tools/common/src/debugpass.cpp b/tools/common/src/debugpass.cpp index 0ec56d9..d1f89c0 100755 --- a/tools/common/src/debugpass.cpp +++ b/tools/common/src/debugpass.cpp @@ -162,7 +162,7 @@ void DebugPass::initialize() { } } -void DebugPass::resize(const Extent extent) { +void DebugPass::resize(const prism::Extent extent) { this->extent = extent; createOffscreenResources(); diff --git a/tools/shadercompiler/main.cpp b/tools/shadercompiler/main.cpp index 74fd8ff..f097f3a 100755 --- a/tools/shadercompiler/main.cpp +++ b/tools/shadercompiler/main.cpp @@ -1,18 +1,10 @@ #include #include -#ifdef PLATFORM_WINDOWS #include #include #include #include -#else -#include -#include -#include -#include -#endif - #include "DirStackIncluder.h" #include "log.hpp"