diff --git a/kraken/CMakeLists.txt b/kraken/CMakeLists.txt index 0a45e0f..b4a4540 100644 --- a/kraken/CMakeLists.txt +++ b/kraken/CMakeLists.txt @@ -31,15 +31,6 @@ add_sources(KRSurface.cpp) add_sources(KRSurfaceManager.cpp) add_sources(KRStreamerThread.cpp) add_sources(KRSwapchain.cpp) -IF(APPLE) - add_sources(KREngine.mm) - - IF(IOS) - add_sources(KRContext_ios.mm) - ELSE() - add_sources(KRContext_osx.mm) - ENDIF() -ENDIF (APPLE) add_sources(KRContextObject.cpp) add_sources(KRDirectionalLight.cpp) IF(APPLE) diff --git a/kraken/KRContext_ios.mm b/kraken/KRContext_ios.mm deleted file mode 100755 index cb03f7a..0000000 --- a/kraken/KRContext_ios.mm +++ /dev/null @@ -1,34 +0,0 @@ -// -// KRContext_ios.mm -// Kraken Engine -// -// Copyright 2023 Kearwood Gilbert. All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, are -// permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, this list of -// conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright notice, this list -// of conditions and the following disclaimer in the documentation and/or other materials -// provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED -// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// The views and conclusions contained in the software and documentation are those of the -// authors and should not be interpreted as representing official policies, either expressed -// or implied, of Kearwood Gilbert. -// - -#include "KREngine-common.h" - -#include "KRContext.h" diff --git a/kraken/KRContext_osx.mm b/kraken/KRContext_osx.mm deleted file mode 100755 index 9c48738..0000000 --- a/kraken/KRContext_osx.mm +++ /dev/null @@ -1,35 +0,0 @@ -// -// KRContext_osx.mm -// Kraken Engine -// -// Copyright 2023 Kearwood Gilbert. All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, are -// permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, this list of -// conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright notice, this list -// of conditions and the following disclaimer in the documentation and/or other materials -// provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED -// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// The views and conclusions contained in the software and documentation are those of the -// authors and should not be interpreted as representing official policies, either expressed -// or implied, of Kearwood Gilbert. -// - -#include "KREngine-common.h" -#include - -#include "KRContext.h" diff --git a/kraken/KRDeviceManager.cpp b/kraken/KRDeviceManager.cpp index 29373b1..c39a662 100644 --- a/kraken/KRDeviceManager.cpp +++ b/kraken/KRDeviceManager.cpp @@ -100,6 +100,9 @@ KRDeviceManager::initialize() #endif #ifdef WIN32 "VK_KHR_win32_surface", +#endif +#ifdef __APPLE__ + "VK_EXT_metal_surface", #endif }; diff --git a/kraken/KREngine-common.h b/kraken/KREngine-common.h index c81faa7..ff5a8b8 100755 --- a/kraken/KREngine-common.h +++ b/kraken/KREngine-common.h @@ -62,6 +62,8 @@ using namespace kraken; #include "../3rdparty/glslang/glslang/Public/ShaderLang.h" #include "../3rdparty/glslang/SPIRV/GlslangToSpv.h" #if defined(__APPLE__) +#define VK_USE_PLATFORM_METAL_EXT +#define stricmp strcasecmp #include #include diff --git a/kraken/KRSurface.cpp b/kraken/KRSurface.cpp index b0c8280..726eb47 100644 --- a/kraken/KRSurface.cpp +++ b/kraken/KRSurface.cpp @@ -35,8 +35,10 @@ using namespace hydra; -#ifdef WIN32 +#if defined(WIN32) KRSurface::KRSurface(KRContext& context, KrSurfaceHandle handle, HWND hWnd) +#elif defined(__APPLE__) +KRSurface::KRSurface(KRContext& context, KrSurfaceHandle handle, CAMetalLayer* layer) #else KRSurface::KRSurface(KRContext& context, KrSurfaceHandle handle) #endif @@ -44,6 +46,8 @@ KRSurface::KRSurface(KRContext& context, KrSurfaceHandle handle) , m_handle(handle) #ifdef WIN32 , m_hWnd(hWnd) +#elif defined(__APPLE__) + , m_layer(layer) #endif , m_deviceHandle(0) , m_surface(VK_NULL_HANDLE) @@ -65,6 +69,7 @@ KRSurface::~KRSurface() KrResult KRSurface::initialize() { +#if defined(WIN32) VkWin32SurfaceCreateInfoKHR createInfo{}; createInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR; createInfo.hinstance = GetModuleHandle(nullptr); @@ -72,6 +77,13 @@ KrResult KRSurface::initialize() if (vkCreateWin32SurfaceKHR(m_pContext->getDeviceManager()->getVulkanInstance(), &createInfo, nullptr, &m_surface) != VK_SUCCESS) { return KR_ERROR_VULKAN; } +#elif defined(__APPLE__) + VkMetalSurfaceCreateInfoEXT createInfo{}; + createInfo.sType = VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT; + createInfo.pLayer = m_layer; // CAMetalLayer +#else +#error Unsupported +#endif m_deviceHandle = m_pContext->getDeviceManager()->getBestDeviceForSurface(m_surface); if (m_deviceHandle == 0) { diff --git a/kraken/KRSurface.h b/kraken/KRSurface.h index 4fc153a..52c4dba 100644 --- a/kraken/KRSurface.h +++ b/kraken/KRSurface.h @@ -41,8 +41,10 @@ class KRSwapchain; class KRSurface : public KRContextObject { public: -#ifdef WIN32 +#if defined(WIN32) KRSurface(KRContext& context, KrSurfaceHandle handle, HWND hWnd); +#elif defined(__APPLE__) + KRSurface(KRContext& context, KrSurfaceHandle handle, CAMetalLayer* layer); #else KRSurface(KRContext& context, KrSurfaceHandle handle); #endif @@ -69,6 +71,8 @@ public: #ifdef WIN32 HWND m_hWnd; +#elif defined(__APPLE__) + CAMetalLayer* m_layer; #endif KrDeviceHandle m_deviceHandle; VkSurfaceKHR m_surface;