I am writing a game for Android using the NDK. My game uses vulkan if it is available and otherwise uses OpenGL.
I have a problem where if you put the game in split screen mode with the device held in portrait orientation, then resize the game to full screen mode, an after image of the game on the old view is still visible. Note: doing this with the game triggers SurfaceHolder.Callback.surfaceDestroyed (in Java) to be called, which in turn shuts down my render thread in C++. My callback for surfaceDestroyed tells the C++ render thread to stop, then joins it.
I can fix this in OpenGL by calling glClearColor with any color, then calling eglSwapBuffers right before the render thread shuts down.
Is this a valid fix for OpenGL? Is there something else I should be doing to clean out the old surface? I verified that ANativeWindow_release is called on the window I get from ANativeWindow_fromSurface before I exit the render thread.
Then I tried to do the same thing in vulkan and ran into problems again... I used vkCmdClearColorImage by do ing the following:
(1) vkQueueWaitIdle(presentQueue)
(2) vkAquireNextImageKHR
(3) initialize the corresponding command buffer with:
(3a) ImageMemoryBarrier VK_IMAGE_LAYOUT_UNDEFINED -> VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 0 -> VK_ACCESS_TRANSFER_WRITE_BIT
(3b) vkCmdClearColor VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
(3c) ImageMemoryBarrier VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL -> VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, VK_ACCESS_TRANSFER_WRITE_BIT -> VK_ACCESS_MEMORY_READ_BIT
(4) vkQueueSubmit(graphicsQueue...)
(5) vkQueuePresentKHR(presentQueue...)
(6) vkQueueWaitIdle(presentQueue)
I got to 3a, and then I got an error in the validation layer saying that the image was not created with VK_IMAGE_USAGE_TRANSFER_DST_BIT usage flag. How do I cause the swapchain images to be created with this usage bit?
Please let me know if additional information is needed. Thanks!