Add support for iOS and macOS via MoltenVK.
This commit is contained in:
parent
ac0a4989bd
commit
626ab5803f
40 changed files with 1829 additions and 1 deletions
|
|
@ -107,6 +107,9 @@ public:
|
|||
#ifdef __ANDROID__
|
||||
ANativeWindow* window
|
||||
#else
|
||||
#if (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
|
||||
void* view
|
||||
#else
|
||||
#ifdef _DIRECT2DISPLAY
|
||||
uint32_t width, uint32_t height
|
||||
#else
|
||||
|
|
@ -117,6 +120,7 @@ public:
|
|||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
)
|
||||
{
|
||||
|
|
@ -136,6 +140,22 @@ public:
|
|||
surfaceCreateInfo.window = window;
|
||||
err = vkCreateAndroidSurfaceKHR(instance, &surfaceCreateInfo, NULL, &surface);
|
||||
#else
|
||||
#ifdef VK_USE_PLATFORM_IOS_MVK
|
||||
VkIOSSurfaceCreateInfoMVK surfaceCreateInfo = {};
|
||||
surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_IOS_SURFACE_CREATE_INFO_MVK;
|
||||
surfaceCreateInfo.pNext = NULL;
|
||||
surfaceCreateInfo.flags = 0;
|
||||
surfaceCreateInfo.pView = view;
|
||||
err = vkCreateIOSSurfaceMVK(instance, &surfaceCreateInfo, nullptr, &surface);
|
||||
#else
|
||||
#ifdef VK_USE_PLATFORM_MACOS_MVK
|
||||
VkMacOSSurfaceCreateInfoMVK surfaceCreateInfo = {};
|
||||
surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK;
|
||||
surfaceCreateInfo.pNext = NULL;
|
||||
surfaceCreateInfo.flags = 0;
|
||||
surfaceCreateInfo.pView = view;
|
||||
err = vkCreateMacOSSurfaceMVK(instance, &surfaceCreateInfo, NULL, &surface);
|
||||
#else
|
||||
#if defined(_DIRECT2DISPLAY)
|
||||
createDirect2DisplaySurface(width, height);
|
||||
#else
|
||||
|
|
@ -154,6 +174,8 @@ public:
|
|||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Get available queue family properties
|
||||
|
|
|
|||
|
|
@ -52,6 +52,28 @@
|
|||
#define KEY_N 0xE
|
||||
#define KEY_O 0xF
|
||||
#define KEY_T 0x10
|
||||
|
||||
#elif (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
|
||||
#define KEY_ESCAPE 0x35
|
||||
#define KEY_F1 0x7A
|
||||
#define KEY_F2 0x78
|
||||
#define KEY_F3 0x63
|
||||
#define KEY_F4 0x76
|
||||
#define KEY_W 0x0D
|
||||
#define KEY_A 0x00
|
||||
#define KEY_S 0x01
|
||||
#define KEY_D 0x02
|
||||
#define KEY_P 0x23
|
||||
#define KEY_SPACE 0x31
|
||||
#define KEY_KPADD 0x45
|
||||
#define KEY_KPSUB 0x4E
|
||||
#define KEY_B 0x0B
|
||||
#define KEY_F 0x03
|
||||
#define KEY_L 0x25
|
||||
#define KEY_N 0x2D
|
||||
#define KEY_O 0x1F
|
||||
#define KEY_T 0x11
|
||||
|
||||
#elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
|
||||
#include <linux/input.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -68,6 +68,8 @@ std::string VulkanExampleBase::getWindowTitle()
|
|||
return windowTitle;
|
||||
}
|
||||
|
||||
#if !(defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
|
||||
// iOS & macOS: VulkanExampleBase::getAssetPath() implemented externally to allow access to Objective-C components
|
||||
const std::string VulkanExampleBase::getAssetPath()
|
||||
{
|
||||
#if defined(__ANDROID__)
|
||||
|
|
@ -76,6 +78,7 @@ const std::string VulkanExampleBase::getAssetPath()
|
|||
return "./../data/";
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
bool VulkanExampleBase::checkCommandBuffers()
|
||||
{
|
||||
|
|
@ -210,6 +213,45 @@ VkPipelineShaderStageCreateInfo VulkanExampleBase::loadShader(std::string fileNa
|
|||
return shaderStage;
|
||||
}
|
||||
|
||||
void VulkanExampleBase::renderFrame()
|
||||
{
|
||||
#if (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
|
||||
auto tStart = std::chrono::high_resolution_clock::now();
|
||||
if (viewUpdated)
|
||||
{
|
||||
viewUpdated = false;
|
||||
viewChanged();
|
||||
}
|
||||
render();
|
||||
frameCounter++;
|
||||
auto tEnd = std::chrono::high_resolution_clock::now();
|
||||
auto tDiff = std::chrono::duration<double, std::milli>(tEnd - tStart).count();
|
||||
frameTimer = tDiff / 1000.0f;
|
||||
camera.update(frameTimer);
|
||||
if (camera.moving())
|
||||
{
|
||||
viewUpdated = true;
|
||||
}
|
||||
// Convert to clamped timer value
|
||||
if (!paused)
|
||||
{
|
||||
timer += timerSpeed * frameTimer;
|
||||
if (timer > 1.0)
|
||||
{
|
||||
timer -= 1.0f;
|
||||
}
|
||||
}
|
||||
fpsTimer += (float)tDiff;
|
||||
if (fpsTimer > 1000.0f)
|
||||
{
|
||||
lastFPS = frameCounter;
|
||||
updateTextOverlay();
|
||||
fpsTimer = 0.0f;
|
||||
frameCounter = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void VulkanExampleBase::renderLoop()
|
||||
{
|
||||
destWidth = width;
|
||||
|
|
@ -1321,6 +1363,12 @@ void VulkanExampleBase::handleAppCommand(android_app * app, int32_t cmd)
|
|||
break;
|
||||
}
|
||||
}
|
||||
#elif (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
|
||||
void* VulkanExampleBase::setupWindow(void* view)
|
||||
{
|
||||
this->view = view;
|
||||
return view;
|
||||
}
|
||||
#elif defined(_DIRECT2DISPLAY)
|
||||
#elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
|
||||
/*static*/void VulkanExampleBase::registryGlobalCb(void *data,
|
||||
|
|
@ -2094,6 +2142,8 @@ void VulkanExampleBase::initSwapchain()
|
|||
swapChain.initSurface(windowInstance, window);
|
||||
#elif defined(__ANDROID__)
|
||||
swapChain.initSurface(androidApp->window);
|
||||
#elif (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
|
||||
swapChain.initSurface(view);
|
||||
#elif defined(_DIRECT2DISPLAY)
|
||||
swapChain.initSurface(width, height);
|
||||
#elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
|
||||
|
|
|
|||
|
|
@ -207,6 +207,8 @@ public:
|
|||
int64_t lastTapTime = 0;
|
||||
/** @brief Product model and manufacturer of the Android device (via android.Product*) */
|
||||
std::string androidProduct;
|
||||
#elif (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
|
||||
void* view;
|
||||
#elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
|
||||
wl_display *display = nullptr;
|
||||
wl_registry *registry = nullptr;
|
||||
|
|
@ -252,6 +254,8 @@ public:
|
|||
#elif defined(__ANDROID__)
|
||||
static int32_t handleAppInput(struct android_app* app, AInputEvent* event);
|
||||
static void handleAppCommand(android_app* app, int32_t cmd);
|
||||
#elif (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
|
||||
void* setupWindow(void* view);
|
||||
#elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
|
||||
wl_shell_surface *setupWindow();
|
||||
void initWaylandConnection();
|
||||
|
|
@ -293,7 +297,6 @@ public:
|
|||
static void keyboardModifiersCb(void *data, struct wl_keyboard *keyboard,
|
||||
uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched,
|
||||
uint32_t mods_locked, uint32_t group);
|
||||
|
||||
#elif defined(__linux__)
|
||||
xcb_window_t setupWindow();
|
||||
void initxcbConnection();
|
||||
|
|
@ -369,6 +372,9 @@ public:
|
|||
// Start the main render loop
|
||||
void renderLoop();
|
||||
|
||||
// Render one frame of a render loop on platforms that sync rendering
|
||||
void renderFrame();
|
||||
|
||||
void updateTextOverlay();
|
||||
|
||||
// Called when the text overlay is updating
|
||||
|
|
@ -484,4 +490,6 @@ int main(const int argc, const char *argv[]) \
|
|||
delete(vulkanExample); \
|
||||
return 0; \
|
||||
}
|
||||
#elif (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
|
||||
#define VULKAN_EXAMPLE_MAIN()
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue