-
Notifications
You must be signed in to change notification settings - Fork 2
/
AndroidMain.cpp
42 lines (37 loc) · 1.21 KB
/
AndroidMain.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <android/log.h>
#include <android_native_app_glue.h>
#include "VulkanMain.h"
// Process the next main command.
void handle_cmd(android_app* app, int32_t cmd) {
switch (cmd) {
case APP_CMD_INIT_WINDOW:
// The window is being shown, get it ready.
InitVulkanContext(app);
break;
case APP_CMD_TERM_WINDOW:
// The window is being hidden or closed, clean it up.
DeleteVulkanContext();
break;
default:
__android_log_print(ANDROID_LOG_INFO, "VULKAN", "event not handled: %d", cmd);
}
}
void android_main(struct android_app* app) {
// Set the callback to process system events
app->onAppCmd = handle_cmd;
// Used to poll the events in the main loop
int events;
android_poll_source* source;
// Main loop
do {
if (ALooper_pollAll(IsVulkanReady() ? 1 : 0, nullptr, &events, (void**)&source) >= 0) {
if (source != NULL) source->process(app, source);
}
// render if vulkan is ready
if (IsVulkanReady() == true) {
LOGI("Hello World");
break;
VulkanDrawFrame(app);
}
} while (app->destroyRequested == 0);
}