/** * This is the main entry point of a native application that is using * android_native_app_glue. It runs in its own thread, with its own * event loop for receiving input events and doing other things. */ void android_main(struct android_app* state) { VulkanExample *engine = new VulkanExample(); //memset(&engine, 0, sizeof(engine)); state->userData = engine; state->onAppCmd = handleCommand; state->onInputEvent = handleInput; engine->app = state; engine->animating = 1; // loop waiting for stuff to do. while (1) { // Read all pending events. int ident; int events; struct android_poll_source* source; while ((ident = ALooper_pollAll(engine->animating ? 0 : -1, NULL, &events, (void**)&source)) >= 0) { if (source != NULL) { source->process(state, source); } if (state->destroyRequested != 0) { engine->cleanupVulkan(); return; } } // Render frame if (engine->prepared) { if (engine->animating) { // Update rotation engine->state.rotation.y += 0.5f; if (engine->state.rotation.y > 360.0f) { engine->state.rotation.y -= 360.0f; } engine->updateUniformBuffers(); } engine->draw(); } } }
static void handleCommand(struct android_app* app, int32_t cmd) { VulkanExample* vulkanExample = (VulkanExample*)app->userData; switch (cmd) { case APP_CMD_SAVE_STATE: vulkanExample->app->savedState = malloc(sizeof(struct saved_state)); *((struct saved_state*)vulkanExample->app->savedState) = vulkanExample->state; vulkanExample->app->savedStateSize = sizeof(struct saved_state); break; case APP_CMD_INIT_WINDOW: if (vulkanExample->app->window != NULL) { vulkanExample->initVulkan(); assert(vulkanExample->prepared); } break; case APP_CMD_LOST_FOCUS: vulkanExample->animating = 0; break; } }
/** * This is the main entry point of a native application that is using * android_native_app_glue. It runs in its own thread, with its own * event loop for receiving input events and doing other things. */ void android_main(struct android_app* state) { VulkanExample *engine = new VulkanExample(); state->userData = engine; state->onAppCmd = handleCommand; state->onInputEvent = handleInput; engine->app = state; engine->animating = 1; // loop waiting for stuff to do. while (1) { // Read all pending events. int ident; int events; struct android_poll_source* source; while ((ident = ALooper_pollAll(engine->animating ? 0 : -1, NULL, &events, (void**)&source)) >= 0) { if (source != NULL) { source->process(state, source); } if (state->destroyRequested != 0) { engine->cleanupVulkan(); return; } } engine->render(); } }