From 9b507aa79a26b6b78eef50a3dab4105b54005171 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Mon, 21 Feb 2022 11:47:23 -0500 Subject: [PATCH] Fix up macOS build --- CMakeLists.txt | 4 ++++ engine/gfx/metal/src/gfx_metal.cpp | 12 +++++++++--- engine/gfx/vulkan/CMakeLists.txt | 2 -- engine/platform/CMakeLists.txt | 10 +++++++++- engine/platform/include/platform.hpp | 6 ++++-- platforms/sdl/CMakeLists.txt | 16 ++++++++-------- platforms/sdl/sdl_metal.mm | 7 +++---- 7 files changed, 37 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ff8238..bc407d3 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,6 +100,10 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Emscripten") set(REQUIRED_SHADER_LANGUAGE "wgsl") endif() +if(ENABLE_VULKAN) + find_package(Vulkan REQUIRED) +endif() + if(NEEDS_HOSTED_SHADER_COMPILER AND (NOT DEFINED SHADER_COMPILER_LOCATION)) message(FATAL_ERROR "You are building for a platform that needs a hosted shader compiler. Please specify the path in SHADER_COMPILER_LOCATION!") endif() diff --git a/engine/gfx/metal/src/gfx_metal.cpp b/engine/gfx/metal/src/gfx_metal.cpp index 95ab56c..aad92ed 100755 --- a/engine/gfx/metal/src/gfx_metal.cpp +++ b/engine/gfx/metal/src/gfx_metal.cpp @@ -172,7 +172,11 @@ void GFXMetal::initialize_view(void* native_handle, const platform::window_ptr i auto native = new NativeMTLView(); native->identifier = identifier; - native->format = (MTL::PixelFormat)platform::initialize_metal_layer(identifier, device); + auto surface_creation_info = new metal_surface_creation_info(); + surface_creation_info->device = device; + + auto mtl_surface = (metal_surface*)platform::create_surface(identifier, surface_creation_info); + native->format = mtl_surface->format; nativeViews.push_back(native); } @@ -715,8 +719,10 @@ void GFXMetal::submit(GFXCommandBuffer* command_buffer, const platform::window_p NativeMTLView* native = getNativeView(window); CA::MetalDrawable* drawable = nullptr; - if(native != nullptr) - drawable = ((CA::MetalDrawable*)platform::get_next_drawable(window)); + if(native != nullptr) { + auto next_drawable = (metal_next_image*)platform::get_next_image(window); + drawable = next_drawable->next_drawable; + } MTL::CommandBuffer* commandBuffer = command_queue->commandBuffer(); diff --git a/engine/gfx/vulkan/CMakeLists.txt b/engine/gfx/vulkan/CMakeLists.txt index 9975d63..981ae28 100755 --- a/engine/gfx/vulkan/CMakeLists.txt +++ b/engine/gfx/vulkan/CMakeLists.txt @@ -7,8 +7,6 @@ set(HEADERS src/gfx_vulkan_renderpass.hpp src/gfx_vulkan_commandbuffer.hpp) -find_package(Vulkan REQUIRED) - add_library(GFXVulkan STATIC src/gfx_vulkan.cpp ${HEADERS}) diff --git a/engine/platform/CMakeLists.txt b/engine/platform/CMakeLists.txt index 1c072d1..62587df 100755 --- a/engine/platform/CMakeLists.txt +++ b/engine/platform/CMakeLists.txt @@ -1,3 +1,11 @@ +if(ENABLE_VULKAN) + set(EXTRA_LIBRARIES Vulkan::Vulkan ${EXTRA_LIBRARIES}) +endif() + +if(ENABLE_METAL) + set(EXTRA_LIBRARIES metal-cpp ${EXTRA_LIBRARIES}) +endif() + add_library(Platform INTERFACE) target_include_directories(Platform INTERFACE include) -target_link_libraries(Platform INTERFACE Utility Log) +target_link_libraries(Platform INTERFACE Utility Log ${EXTRA_LIBRARIES}) \ No newline at end of file diff --git a/engine/platform/include/platform.hpp b/engine/platform/include/platform.hpp index 0f2e2c8..a531992 100755 --- a/engine/platform/include/platform.hpp +++ b/engine/platform/include/platform.hpp @@ -78,6 +78,7 @@ enum class PlatformTheme { // this only determines it at build-time, not at runtime. #ifdef ENABLE_VULKAN #include +#include struct vulkan_information { std::vector surface_extensions; @@ -99,10 +100,11 @@ struct directx_surface_creation_info { #endif #ifdef ENABLE_METAL -#import +#include +#include struct metal_surface_creation_info { - MTLDevice device; + MTL::Device* device; }; struct metal_surface { diff --git a/platforms/sdl/CMakeLists.txt b/platforms/sdl/CMakeLists.txt index 87fb92c..11a80bc 100644 --- a/platforms/sdl/CMakeLists.txt +++ b/platforms/sdl/CMakeLists.txt @@ -1,26 +1,27 @@ include(../../cmake/AddPlatformExecutable.cmake) -if(ENABLE_MACOS) +if(ENABLE_METAL) find_library(METAL Metal) - set(EXTRA_LIBRARIES GFXMetal ${METAL}) - set(EXTRA_SRC ${CMAKE_CURRENT_SOURCE_DIR}/sdl_metal.mm) + set(EXTRA_LIBRARIES GFXMetal ${METAL} ${EXTRA_LIBRARIES}) + set(EXTRA_SRC ${CMAKE_CURRENT_SOURCE_DIR}/sdl_metal.mm ${EXTRA_SRC}) endif() if(ENABLE_VULKAN) - set(EXTRA_SRC ${CMAKE_CURRENT_SOURCE_DIR}/sdl_vulkan.cpp) + set(EXTRA_LIBRARIES GFXVulkan ${EXTRA_LIBRARIES}) + set(EXTRA_SRC ${CMAKE_CURRENT_SOURCE_DIR}/sdl_vulkan.cpp ${EXTRA_SRC}) endif() if(TARGET SDL2::SDL2) - set(EXTRA_LIBRARIES SDL2::SDL2) + set(EXTRA_LIBRARIES SDL2::SDL2 ${EXTRA_LIBRARIES}) endif() if(TARGET SDL2::Main) - set(EXTRA_LIBRARIES SDL2::Main) + set(EXTRA_LIBRARIES SDL2::Main ${EXTRA_LIBRARIES}) endif() if(TARGET SDL2::SDL2main) - set(EXTRA_LIBRARIES SDL2::SDL2main) + set(EXTRA_LIBRARIES SDL2::SDL2main ${EXTRA_LIBRARIES}) endif() add_platform( @@ -34,7 +35,6 @@ add_platform( MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist.in" LINK_LIBRARIES Core - GFXVulkan ${EXTRA_LIBRARIES} ) diff --git a/platforms/sdl/sdl_metal.mm b/platforms/sdl/sdl_metal.mm index cb170a6..85dc2f5 100644 --- a/platforms/sdl/sdl_metal.mm +++ b/platforms/sdl/sdl_metal.mm @@ -15,17 +15,16 @@ CAMetalLayer* get_layer(platform::window_ptr index) { return (__bridge CAMetalLayer*)SDL_RenderGetMetalLayer(renderers[get_window(index)]); } -metal_surface* create_metal_surface(platform::window_ptr window, void* surface_creation_info) { - auto layer = get_layer(index); +void* create_metal_surface(platform::window_ptr window, void* surface_creation_info) { + auto layer = get_layer(window); - auto layer = (__bridge CAMetalLayer*)SDL_RenderGetMetalLayer(renderers[get_window(window)]); auto metal_surface_info = (metal_surface_creation_info*)surface_creation_info; layer.device = (__bridge id)metal_surface_info->device; layer.allowsNextDrawableTimeout = true; auto return_surface = new metal_surface(); - return_surface->format = layer.pixelFormat; + return_surface->format = static_cast(layer.pixelFormat); return return_surface; }