Moved event handler callbacks (windows and linux) into os specific macros
This commit is contained in:
parent
e24a54b976
commit
165022ab7e
1 changed files with 36 additions and 19 deletions
|
|
@ -368,44 +368,61 @@ public:
|
|||
// OS specific macros for the example main entry points
|
||||
#if defined(_WIN32)
|
||||
// Windows entry point
|
||||
#define VULKAN_EXAMPLE_MAIN(example, enabledfeatures) \
|
||||
#define VULKAN_EXAMPLE_MAIN(enabledfeatures) \
|
||||
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 hPrevInstance, LPSTR pCmdLine, int nCmdShow) \
|
||||
{ \
|
||||
example = new VulkanExample(); \
|
||||
example->setupWindow(hInstance, WndProc); \
|
||||
example->initSwapchain(); \
|
||||
example->prepare(); \
|
||||
example->renderLoop(); \
|
||||
delete(example); \
|
||||
vulkanExample = new VulkanExample(); \
|
||||
vulkanExample->setupWindow(hInstance, WndProc); \
|
||||
vulkanExample->initSwapchain(); \
|
||||
vulkanExample->prepare(); \
|
||||
vulkanExample->renderLoop(); \
|
||||
delete(vulkanExample); \
|
||||
return 0; \
|
||||
}
|
||||
#elif defined(__ANDROID__)
|
||||
// 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(example, enabledfeatures) \
|
||||
#define VULKAN_EXAMPLE_MAIN(enabledfeatures) \
|
||||
VulkanExample *vulkanExample; \
|
||||
void android_main(android_app* state) \
|
||||
{ \
|
||||
app_dummy(); \
|
||||
example = new VulkanExample(); \
|
||||
vulkanExample = new VulkanExample(); \
|
||||
state->userData = vulkanExample; \
|
||||
state->onAppCmd = VulkanExample::handleAppCommand; \
|
||||
state->onInputEvent = VulkanExample::handleAppInput; \
|
||||
vulkanExample->androidApp = state; \
|
||||
example->renderLoop(); \
|
||||
delete(example); \
|
||||
vulkanExample->renderLoop(); \
|
||||
delete(vulkanExample); \
|
||||
}
|
||||
#elif defined(__linux__)
|
||||
// Linux entry point
|
||||
// todo: extract command line arguments
|
||||
#define VULKAN_EXAMPLE_MAIN(example, enabledfeatures) \
|
||||
#define VULKAN_EXAMPLE_MAIN( enabledfeatures) \
|
||||
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[]) \
|
||||
{ \
|
||||
example = new VulkanExample(); \
|
||||
example->setupWindow(); \
|
||||
example->initSwapchain(); \
|
||||
example->prepare(); \
|
||||
example->renderLoop(); \
|
||||
delete(example); \
|
||||
vulkanExample = new VulkanExample(); \
|
||||
vulkanExample->setupWindow(); \
|
||||
vulkanExample->initSwapchain(); \
|
||||
vulkanExample->prepare(); \
|
||||
vulkanExample->renderLoop(); \
|
||||
delete(vulkanExample); \
|
||||
return 0; \
|
||||
}
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue