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
|
// OS specific macros for the example main entry points
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
// Windows entry point
|
// 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) \
|
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine, int nCmdShow) \
|
||||||
{ \
|
{ \
|
||||||
example = new VulkanExample(); \
|
vulkanExample = new VulkanExample(); \
|
||||||
example->setupWindow(hInstance, WndProc); \
|
vulkanExample->setupWindow(hInstance, WndProc); \
|
||||||
example->initSwapchain(); \
|
vulkanExample->initSwapchain(); \
|
||||||
example->prepare(); \
|
vulkanExample->prepare(); \
|
||||||
example->renderLoop(); \
|
vulkanExample->renderLoop(); \
|
||||||
delete(example); \
|
delete(vulkanExample); \
|
||||||
return 0; \
|
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
|
// 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) \
|
void android_main(android_app* state) \
|
||||||
{ \
|
{ \
|
||||||
app_dummy(); \
|
app_dummy(); \
|
||||||
example = new VulkanExample(); \
|
vulkanExample = new VulkanExample(); \
|
||||||
state->userData = vulkanExample; \
|
state->userData = vulkanExample; \
|
||||||
state->onAppCmd = VulkanExample::handleAppCommand; \
|
state->onAppCmd = VulkanExample::handleAppCommand; \
|
||||||
state->onInputEvent = VulkanExample::handleAppInput; \
|
state->onInputEvent = VulkanExample::handleAppInput; \
|
||||||
vulkanExample->androidApp = state; \
|
vulkanExample->androidApp = state; \
|
||||||
example->renderLoop(); \
|
vulkanExample->renderLoop(); \
|
||||||
delete(example); \
|
delete(vulkanExample); \
|
||||||
}
|
}
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
// Linux entry point
|
// Linux entry point
|
||||||
// todo: extract command line arguments
|
// 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[]) \
|
int main(const int argc, const char *argv[]) \
|
||||||
{ \
|
{ \
|
||||||
example = new VulkanExample(); \
|
vulkanExample = new VulkanExample(); \
|
||||||
example->setupWindow(); \
|
vulkanExample->setupWindow(); \
|
||||||
example->initSwapchain(); \
|
vulkanExample->initSwapchain(); \
|
||||||
example->prepare(); \
|
vulkanExample->prepare(); \
|
||||||
example->renderLoop(); \
|
vulkanExample->renderLoop(); \
|
||||||
delete(example); \
|
delete(vulkanExample); \
|
||||||
return 0; \
|
return 0; \
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
Loading…
Add table
Add a link
Reference in a new issue