Archived
1
Fork 0

Fix up macOS build

This commit is contained in:
Joshua Goins 2022-02-21 11:47:23 -05:00
parent 54c95b9ddd
commit 9b507aa79a
7 changed files with 37 additions and 20 deletions

View file

@ -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()

View file

@ -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();

View file

@ -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})

View file

@ -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})

View file

@ -78,6 +78,7 @@ enum class PlatformTheme {
// this only determines it at build-time, not at runtime.
#ifdef ENABLE_VULKAN
#include <vulkan/vulkan.h>
#include <vector>
struct vulkan_information {
std::vector<const char*> surface_extensions;
@ -99,10 +100,11 @@ struct directx_surface_creation_info {
#endif
#ifdef ENABLE_METAL
#import <Metal/Metal.hpp>
#include <Metal/Metal.hpp>
#include <QuartzCore/CAMetalDrawable.hpp>
struct metal_surface_creation_info {
MTLDevice device;
MTL::Device* device;
};
struct metal_surface {

View file

@ -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}
)

View file

@ -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<MTLDevice>)metal_surface_info->device;
layer.allowsNextDrawableTimeout = true;
auto return_surface = new metal_surface();
return_surface->format = layer.pixelFormat;
return_surface->format = static_cast<MTL::PixelFormat>(layer.pixelFormat);
return return_surface;
}