Just FYI: I don't know Android well.
Creating Vulkan "texture" is done with vkCreateImage
. Unlike your OpenGL ES example there is some extra work managing the memory explicitly (with vkAllocateMemory
and vkBindImageMemory
).
Next step would be the hard one. There is apparently no SurfaceTexture
for Vulkan (yet).
The work making that efficient from Vulkan side was released quite recently.
I.e. VK_KHX_external_memory
and associated extensions of Vulkan. So hopefully the official Android SurfaceTexture
for Vulkan is comming too.
That being said, you could implement a new SurfaceTexture
yourself. Or at least "import" Vulkan Image into OpenGL ES. The problem with this is:
the extensions are considered experimental UPDATE: not anymore
- the drivers probably do not support the extensions anyway (yet)
- it is probably not trivial to program, and also may require messing with some low-level linux API on Android.
So, best way for now would be to create some shim, which copies the data.
I would:
It seems the MediaCodec
is able to work with a ByteBuffer
instead of Surface
. And ByteBuffer
can wrap raw bytes[]
.
Create VkImages
and VkBuffer
. The Image on the Device memory (the resulting object we want). And the Buffer on the Host side (to facilitate copying).
Map (vkMapMemory
), and wrap the Host side Buffer with the ByteBuffer
used by MediaCodec
.
Each time there's new data copy it with submitting vkCmdCopyBufferToImage
in Vulkan.
I omitted a lot of boilerplate (especially synchronization), but hopefully you get the idea.