Updated main entry points (in line with the example base) (Refs #268, #270)

This commit is contained in:
saschawillems 2017-01-23 13:54:23 +01:00
parent f09993bc15
commit f86ff6dd27
2 changed files with 63 additions and 36 deletions

View file

@ -370,7 +370,6 @@ void android_main(android_app* state) \
} }
#elif defined(_DIRECT2DISPLAY) #elif defined(_DIRECT2DISPLAY)
// Linux entry point with direct to display wsi // Linux entry point with direct to display wsi
// todo: extract command line arguments
#define VULKAN_EXAMPLE_MAIN() \ #define VULKAN_EXAMPLE_MAIN() \
VulkanExample *vulkanExample; \ VulkanExample *vulkanExample; \
static void handleEvent() \ static void handleEvent() \
@ -378,6 +377,7 @@ static void handleEvent() \
} \ } \
int main(const int argc, const char *argv[]) \ 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 = new VulkanExample(); \
vulkanExample->initVulkan(); \ vulkanExample->initVulkan(); \
vulkanExample->initSwapchain(); \ vulkanExample->initSwapchain(); \
@ -388,7 +388,6 @@ int main(const int argc, const char *argv[]) \
} }
#elif defined(__linux__) #elif defined(__linux__)
// Linux entry point // Linux entry point
// todo: extract command line arguments
#define VULKAN_EXAMPLE_MAIN() \ #define VULKAN_EXAMPLE_MAIN() \
VulkanExample *vulkanExample; \ VulkanExample *vulkanExample; \
static void handleEvent(const xcb_generic_event_t *event) \ static void handleEvent(const xcb_generic_event_t *event) \

View file

@ -1090,64 +1090,92 @@ public:
} }
}; };
VulkanExample *vulkanExample; // OS specific macros for the example main entry points
// Most of the code base is shared for the different supported operating systems, but stuff like message handling diffes
#if defined(_WIN32) #if defined(_WIN32)
// Windows entry point
#define VULKAN_EXAMPLE_MAIN()
VulkanExample *vulkanExample;
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
if (vulkanExample != nullptr) if (vulkanExample != NULL)
{ {
vulkanExample->handleMessages(hWnd, uMsg, wParam, lParam); vulkanExample->handleMessages(hWnd, uMsg, wParam, lParam);
} }
return (DefWindowProc(hWnd, uMsg, wParam, lParam)); return (DefWindowProc(hWnd, uMsg, wParam, lParam));
} }
#elif defined(__linux__) && !defined(__ANDROID__) && !defined(_DIRECT2DISPLAY)
static void handleEvent(const xcb_generic_event_t *event)
{
if (vulkanExample != nullptr)
{
vulkanExample->handleEvent(event);
}
}
#endif
// Main entry point
#if defined(_WIN32)
// Windows entry point
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine, int nCmdShow) int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine, int nCmdShow)
{
for (size_t i = 0; i < __argc; i++) { VulkanExample::args.push_back(__argv[i]); };
vulkanExample = new VulkanExample();
vulkanExample->initVulkan();
vulkanExample->setupWindow(hInstance, WndProc);
vulkanExample->initSwapchain();
vulkanExample->prepare();
vulkanExample->renderLoop();
delete(vulkanExample);
return 0;
}
#elif defined(__ANDROID__) #elif defined(__ANDROID__)
// Android entry point // Android entry point
// A note on app_dummy(): This is required as the compiler may otherwise remove the main entry point of the application
#define VULKAN_EXAMPLE_MAIN()
VulkanExample *vulkanExample;
void android_main(android_app* state) void android_main(android_app* state)
#elif defined(__linux__)
// Linux entry point
int main(const int argc, const char *argv[])
#endif
{ {
#if defined(__ANDROID__)
// Removing this may cause the compiler to omit the main entry point
// which would make the application crash at start
app_dummy(); app_dummy();
#endif
vulkanExample = new VulkanExample(); vulkanExample = new VulkanExample();
#if defined(_WIN32)
vulkanExample->setupWindow(hInstance, WndProc);
#elif defined(__ANDROID__)
// Attach vulkan example to global android application state
state->userData = vulkanExample; state->userData = vulkanExample;
state->onAppCmd = VulkanExample::handleAppCommand; state->onAppCmd = VulkanExample::handleAppCommand;
state->onInputEvent = VulkanExample::handleAppInput; state->onInputEvent = VulkanExample::handleAppInput;
androidApp = state; androidApp = state;
#elif defined(__linux__) && !defined(_DIRECT2DISPLAY) vulkanExample->renderLoop();
vulkanExample->setupWindow(); delete(vulkanExample);
#endif }
#if !defined(__ANDROID__) #elif defined(_DIRECT2DISPLAY)
// Linux entry point with direct to display wsi
// Direct to Displays (D2D) is used on embedded platforms
#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->initVulkan();
vulkanExample->initSwapchain(); vulkanExample->initSwapchain();
vulkanExample->prepare(); vulkanExample->prepare();
#endif
vulkanExample->renderLoop(); vulkanExample->renderLoop();
delete(vulkanExample); delete(vulkanExample);
#if !defined(__ANDROID__)
return 0; return 0;
#endif
} }
#elif defined(__linux__)
// Linux entry point
#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->initSwapchain();
vulkanExample->prepare();
vulkanExample->renderLoop();
delete(vulkanExample);
return 0;
}
#endif