igl
igl copied to clipboard
Vulkan | Switch between the foreground and background
JNIEXPORT void JNICALL Java_com_facebook_igl_shell_SampleLib_surfaceDestroyed(JNIEnv* env,
jobject /*obj*/,
jobject surface) {
// For Vulkan we deallocate the whole renderer and recreate it when surface is re-created.
// This is done because we currently don't have an easy way to destroy the surface + swapchain
// independent of the whole device.
// This is not needed for GL
if (activeBackendTypeID == BackendTypeID::Vulkan && renderers[activeBackendTypeID] != nullptr) {
renderers[activeBackendTypeID]->onSurfaceDestroyed(
surface ? ANativeWindow_fromSurface(env, surface) : nullptr);
auto& renderer = renderers[activeBackendTypeID];
renderer.reset();
renderers[activeBackendTypeID] = nullptr;
}
}
When I tried to switch between the foreground and background on Vulkan, I found that it is currently not possible. This is because every time the surface is destroyed, the entire render, including all data and textures, needs to be destroyed. This is unacceptable in a real app. Is it possible to only replace the surface while keeping the device available during the switch between foreground and background?