igl icon indicating copy to clipboard operation
igl copied to clipboard

Vulkan | Switch between the foreground and background

Open vinsentli opened this issue 7 months ago • 6 comments

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?

vinsentli avatar Jul 10 '24 08:07 vinsentli