Merge pull request #342 from brenwill/master
Add support for iOS and macOS via MoltenVK
This commit is contained in:
commit
b1da3e2cb1
47 changed files with 2098 additions and 11 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
|
||||
|
||||
if (err != VK_SUCCESS) {
|
||||
|
|
|
|||
|
|
@ -52,6 +52,56 @@
|
|||
#define KEY_N 0xE
|
||||
#define KEY_O 0xF
|
||||
#define KEY_T 0x10
|
||||
|
||||
#elif defined(VK_USE_PLATFORM_IOS_MVK)
|
||||
// Use numeric keys instead of function keys.
|
||||
// Use main keyboard plus/minus instead of keypad plus/minus
|
||||
// Use Delete key instead of Escape key.
|
||||
#define KEY_ESCAPE 0x33
|
||||
#define KEY_F1 '1'
|
||||
#define KEY_F2 '2'
|
||||
#define KEY_F3 '3'
|
||||
#define KEY_F4 '4'
|
||||
#define KEY_W 'w'
|
||||
#define KEY_A 'a'
|
||||
#define KEY_S 's'
|
||||
#define KEY_D 'd'
|
||||
#define KEY_P 'p'
|
||||
#define KEY_SPACE ' '
|
||||
#define KEY_KPADD '+'
|
||||
#define KEY_KPSUB '-'
|
||||
#define KEY_B 'b'
|
||||
#define KEY_F 'f'
|
||||
#define KEY_L 'l'
|
||||
#define KEY_N 'n'
|
||||
#define KEY_O 'o'
|
||||
#define KEY_T 't'
|
||||
|
||||
#elif defined(VK_USE_PLATFORM_MACOS_MVK)
|
||||
// For compatibility with iOS UX and absent keypad on MacBook:
|
||||
// - Use numeric keys instead of function keys
|
||||
// - Use main keyboard plus/minus instead of keypad plus/minus
|
||||
// - Use Delete key instead of Escape key
|
||||
#define KEY_ESCAPE 0x33
|
||||
#define KEY_F1 0x12
|
||||
#define KEY_F2 0x13
|
||||
#define KEY_F3 0x14
|
||||
#define KEY_F4 0x15
|
||||
#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 0x18
|
||||
#define KEY_KPSUB 0x1B
|
||||
#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>
|
||||
|
||||
|
|
|
|||
|
|
@ -73,6 +73,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__)
|
||||
|
|
@ -81,6 +83,7 @@ const std::string VulkanExampleBase::getAssetPath()
|
|||
return "./../data/";
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
bool VulkanExampleBase::checkCommandBuffers()
|
||||
{
|
||||
|
|
@ -215,6 +218,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;
|
||||
|
|
@ -1332,6 +1374,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,
|
||||
|
|
@ -2096,6 +2144,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)
|
||||
|
|
|
|||
|
|
@ -209,6 +209,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;
|
||||
|
|
@ -256,6 +258,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();
|
||||
|
|
@ -375,6 +379,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();
|
||||
|
||||
/** @brief (Virtual) Called when the text overlay is updating, can be used to add custom text to the overlay */
|
||||
|
|
@ -489,4 +496,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