-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move entry point macros to separate header
- Loading branch information
1 parent
4a0c8b8
commit 4e7144a
Showing
2 changed files
with
186 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
/* | ||
* Vulkan entry points | ||
* | ||
* Platform specific macros for the example main entry points | ||
* | ||
* Copyright (C) 2024 by Sascha Willems - www.saschawillems.de | ||
* | ||
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) | ||
*/ | ||
|
||
#if defined(_WIN32) | ||
/* | ||
* Windows | ||
*/ | ||
#define VULKAN_EXAMPLE_MAIN() \ | ||
VulkanExample *vulkanExample; \ | ||
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) \ | ||
{ \ | ||
if (vulkanExample != NULL) \ | ||
{ \ | ||
vulkanExample->handleMessages(hWnd, uMsg, wParam, lParam); \ | ||
} \ | ||
return (DefWindowProc(hWnd, uMsg, wParam, lParam)); \ | ||
} \ | ||
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) \ | ||
{ \ | ||
for (int32_t i = 0; i < __argc; i++) { VulkanExample::args.push_back(__argv[i]); }; \ | ||
vulkanExample = new VulkanExample(); \ | ||
vulkanExample->initVulkan(); \ | ||
vulkanExample->setupWindow(hInstance, WndProc); \ | ||
vulkanExample->prepare(); \ | ||
vulkanExample->renderLoop(); \ | ||
delete(vulkanExample); \ | ||
return 0; \ | ||
} | ||
|
||
#elif defined(VK_USE_PLATFORM_ANDROID_KHR) | ||
/* | ||
* Android | ||
*/ | ||
#define VULKAN_EXAMPLE_MAIN() \ | ||
VulkanExample *vulkanExample; \ | ||
void android_main(android_app* state) \ | ||
{ \ | ||
vulkanExample = new VulkanExample(); \ | ||
state->userData = vulkanExample; \ | ||
state->onAppCmd = VulkanExample::handleAppCommand; \ | ||
state->onInputEvent = VulkanExample::handleAppInput; \ | ||
androidApp = state; \ | ||
vks::android::getDeviceConfig(); \ | ||
vulkanExample->renderLoop(); \ | ||
delete(vulkanExample); \ | ||
} | ||
|
||
#elif defined(_DIRECT2DISPLAY) | ||
/* | ||
* Direct-to-display | ||
*/ | ||
#define VULKAN_EXAMPLE_MAIN() \ | ||
VulkanExample *vulkanExample; \ | ||
static void handleEvent() \ | ||
{ \ | ||
} \ | ||
int main(const int argc, const char *argv[]) \ | ||
{ \ | ||
for (size_t i = 0; i < argc; i++) { VulkanExample::args.push_back(argv[i]); }; \ | ||
vulkanExample = new VulkanExample(); \ | ||
vulkanExample->initVulkan(); \ | ||
vulkanExample->prepare(); \ | ||
vulkanExample->renderLoop(); \ | ||
delete(vulkanExample); \ | ||
return 0; \ | ||
} | ||
|
||
#elif defined(VK_USE_PLATFORM_DIRECTFB_EXT) | ||
/* | ||
* Direct FB | ||
*/ | ||
#define VULKAN_EXAMPLE_MAIN() \ | ||
VulkanExample *vulkanExample; \ | ||
static void handleEvent(const DFBWindowEvent *event) \ | ||
{ \ | ||
if (vulkanExample != NULL) \ | ||
{ \ | ||
vulkanExample->handleEvent(event); \ | ||
} \ | ||
} \ | ||
int main(const int argc, const char *argv[]) \ | ||
{ \ | ||
for (size_t i = 0; i < argc; i++) { VulkanExample::args.push_back(argv[i]); }; \ | ||
vulkanExample = new VulkanExample(); \ | ||
vulkanExample->initVulkan(); \ | ||
vulkanExample->setupWindow(); \ | ||
vulkanExample->prepare(); \ | ||
vulkanExample->renderLoop(); \ | ||
delete(vulkanExample); \ | ||
return 0; \ | ||
} | ||
|
||
#elif (defined(VK_USE_PLATFORM_WAYLAND_KHR) || defined(VK_USE_PLATFORM_HEADLESS_EXT)) | ||
/* | ||
* Wayland / headless | ||
*/ | ||
#define VULKAN_EXAMPLE_MAIN() \ | ||
VulkanExample *vulkanExample; \ | ||
int main(const int argc, const char *argv[]) \ | ||
{ \ | ||
for (size_t i = 0; i < argc; i++) { VulkanExample::args.push_back(argv[i]); }; \ | ||
vulkanExample = new VulkanExample(); \ | ||
vulkanExample->initVulkan(); \ | ||
vulkanExample->setupWindow(); \ | ||
vulkanExample->prepare(); \ | ||
vulkanExample->renderLoop(); \ | ||
delete(vulkanExample); \ | ||
return 0; \ | ||
} | ||
|
||
#elif defined(VK_USE_PLATFORM_XCB_KHR) | ||
/* | ||
* X11 Xcb | ||
*/ | ||
#define VULKAN_EXAMPLE_MAIN() \ | ||
VulkanExample *vulkanExample; \ | ||
static void handleEvent(const xcb_generic_event_t *event) \ | ||
{ \ | ||
if (vulkanExample != NULL) \ | ||
{ \ | ||
vulkanExample->handleEvent(event); \ | ||
} \ | ||
} \ | ||
int main(const int argc, const char *argv[]) \ | ||
{ \ | ||
for (size_t i = 0; i < argc; i++) { VulkanExample::args.push_back(argv[i]); }; \ | ||
vulkanExample = new VulkanExample(); \ | ||
vulkanExample->initVulkan(); \ | ||
vulkanExample->setupWindow(); \ | ||
vulkanExample->prepare(); \ | ||
vulkanExample->renderLoop(); \ | ||
delete(vulkanExample); \ | ||
return 0; \ | ||
} | ||
|
||
#elif (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK)) | ||
/* | ||
* iOS and macOS (using MoltenVK) | ||
*/ | ||
#if defined(VK_EXAMPLE_XCODE_GENERATED) | ||
#define VULKAN_EXAMPLE_MAIN() \ | ||
VulkanExample *vulkanExample; \ | ||
int main(const int argc, const char *argv[]) \ | ||
{ \ | ||
@autoreleasepool \ | ||
{ \ | ||
for (size_t i = 0; i < argc; i++) { VulkanExample::args.push_back(argv[i]); }; \ | ||
vulkanExample = new VulkanExample(); \ | ||
vulkanExample->initVulkan(); \ | ||
vulkanExample->setupWindow(nullptr); \ | ||
vulkanExample->prepare(); \ | ||
vulkanExample->renderLoop(); \ | ||
delete(vulkanExample); \ | ||
} \ | ||
return 0; \ | ||
} | ||
#else | ||
#define VULKAN_EXAMPLE_MAIN() | ||
#endif | ||
|
||
#elif defined(VK_USE_PLATFORM_SCREEN_QNX) | ||
/* | ||
* QNX Screen | ||
*/ | ||
#define VULKAN_EXAMPLE_MAIN() \ | ||
VulkanExample *vulkanExample; \ | ||
int main(const int argc, const char *argv[]) \ | ||
{ \ | ||
for (int i = 0; i < argc; i++) { VulkanExample::args.push_back(argv[i]); }; \ | ||
vulkanExample = new VulkanExample(); \ | ||
vulkanExample->initVulkan(); \ | ||
vulkanExample->setupWindow(); \ | ||
vulkanExample->prepare(); \ | ||
vulkanExample->renderLoop(); \ | ||
delete(vulkanExample); \ | ||
return 0; \ | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters