Enable VK_EXT_metal_surface for MacOS
Remove unused ObjC files Fix MacOS build
This commit is contained in:
@@ -31,15 +31,6 @@ add_sources(KRSurface.cpp)
|
|||||||
add_sources(KRSurfaceManager.cpp)
|
add_sources(KRSurfaceManager.cpp)
|
||||||
add_sources(KRStreamerThread.cpp)
|
add_sources(KRStreamerThread.cpp)
|
||||||
add_sources(KRSwapchain.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(KRContextObject.cpp)
|
||||||
add_sources(KRDirectionalLight.cpp)
|
add_sources(KRDirectionalLight.cpp)
|
||||||
IF(APPLE)
|
IF(APPLE)
|
||||||
|
|||||||
@@ -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"
|
|
||||||
@@ -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 <AppKit/AppKit.h>
|
|
||||||
|
|
||||||
#include "KRContext.h"
|
|
||||||
@@ -100,6 +100,9 @@ KRDeviceManager::initialize()
|
|||||||
#endif
|
#endif
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
"VK_KHR_win32_surface",
|
"VK_KHR_win32_surface",
|
||||||
|
#endif
|
||||||
|
#ifdef __APPLE__
|
||||||
|
"VK_EXT_metal_surface",
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -62,6 +62,8 @@ using namespace kraken;
|
|||||||
#include "../3rdparty/glslang/glslang/Public/ShaderLang.h"
|
#include "../3rdparty/glslang/glslang/Public/ShaderLang.h"
|
||||||
#include "../3rdparty/glslang/SPIRV/GlslangToSpv.h"
|
#include "../3rdparty/glslang/SPIRV/GlslangToSpv.h"
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
|
#define VK_USE_PLATFORM_METAL_EXT
|
||||||
|
#define stricmp strcasecmp
|
||||||
|
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|||||||
@@ -35,8 +35,10 @@
|
|||||||
|
|
||||||
using namespace hydra;
|
using namespace hydra;
|
||||||
|
|
||||||
#ifdef WIN32
|
#if defined(WIN32)
|
||||||
KRSurface::KRSurface(KRContext& context, KrSurfaceHandle handle, HWND hWnd)
|
KRSurface::KRSurface(KRContext& context, KrSurfaceHandle handle, HWND hWnd)
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
KRSurface::KRSurface(KRContext& context, KrSurfaceHandle handle, CAMetalLayer* layer)
|
||||||
#else
|
#else
|
||||||
KRSurface::KRSurface(KRContext& context, KrSurfaceHandle handle)
|
KRSurface::KRSurface(KRContext& context, KrSurfaceHandle handle)
|
||||||
#endif
|
#endif
|
||||||
@@ -44,6 +46,8 @@ KRSurface::KRSurface(KRContext& context, KrSurfaceHandle handle)
|
|||||||
, m_handle(handle)
|
, m_handle(handle)
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
, m_hWnd(hWnd)
|
, m_hWnd(hWnd)
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
, m_layer(layer)
|
||||||
#endif
|
#endif
|
||||||
, m_deviceHandle(0)
|
, m_deviceHandle(0)
|
||||||
, m_surface(VK_NULL_HANDLE)
|
, m_surface(VK_NULL_HANDLE)
|
||||||
@@ -65,6 +69,7 @@ KRSurface::~KRSurface()
|
|||||||
|
|
||||||
KrResult KRSurface::initialize()
|
KrResult KRSurface::initialize()
|
||||||
{
|
{
|
||||||
|
#if defined(WIN32)
|
||||||
VkWin32SurfaceCreateInfoKHR createInfo{};
|
VkWin32SurfaceCreateInfoKHR createInfo{};
|
||||||
createInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
|
createInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
|
||||||
createInfo.hinstance = GetModuleHandle(nullptr);
|
createInfo.hinstance = GetModuleHandle(nullptr);
|
||||||
@@ -72,6 +77,13 @@ KrResult KRSurface::initialize()
|
|||||||
if (vkCreateWin32SurfaceKHR(m_pContext->getDeviceManager()->getVulkanInstance(), &createInfo, nullptr, &m_surface) != VK_SUCCESS) {
|
if (vkCreateWin32SurfaceKHR(m_pContext->getDeviceManager()->getVulkanInstance(), &createInfo, nullptr, &m_surface) != VK_SUCCESS) {
|
||||||
return KR_ERROR_VULKAN;
|
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);
|
m_deviceHandle = m_pContext->getDeviceManager()->getBestDeviceForSurface(m_surface);
|
||||||
if (m_deviceHandle == 0) {
|
if (m_deviceHandle == 0) {
|
||||||
|
|||||||
@@ -41,8 +41,10 @@ class KRSwapchain;
|
|||||||
class KRSurface : public KRContextObject
|
class KRSurface : public KRContextObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
#ifdef WIN32
|
#if defined(WIN32)
|
||||||
KRSurface(KRContext& context, KrSurfaceHandle handle, HWND hWnd);
|
KRSurface(KRContext& context, KrSurfaceHandle handle, HWND hWnd);
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
KRSurface(KRContext& context, KrSurfaceHandle handle, CAMetalLayer* layer);
|
||||||
#else
|
#else
|
||||||
KRSurface(KRContext& context, KrSurfaceHandle handle);
|
KRSurface(KRContext& context, KrSurfaceHandle handle);
|
||||||
#endif
|
#endif
|
||||||
@@ -69,6 +71,8 @@ public:
|
|||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
HWND m_hWnd;
|
HWND m_hWnd;
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
CAMetalLayer* m_layer;
|
||||||
#endif
|
#endif
|
||||||
KrDeviceHandle m_deviceHandle;
|
KrDeviceHandle m_deviceHandle;
|
||||||
VkSurfaceKHR m_surface;
|
VkSurfaceKHR m_surface;
|
||||||
|
|||||||
Reference in New Issue
Block a user