Vulkan on Android 3 — Render Nothing with Lots of Hidden Details Part 1
We have enormous things to do merely in order to render an empty scene. Strictly speaking, we draw nothing but a single colored background and, accommodate with orientation change of device.
Full sample here.
Prebuild Layers
We just build layers from source code in the last article. But I found we do not quite need source code to trace what’s going on actually. The first reason is that reported message is detailed enough. Second, I often traced the layers code to somewhere so deep that I got a mental burden to impede debugging. Last but not least, it takes an eternity to build the layers.
Now we can safely unload and delete the module vulkanlayerlib
. Don’t forget to clean up dependencies of the module app
.
Specify where layer libs are in the build.gradle
of module app
.
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkDir = properties.getProperty('ndk.dir')
def valLayerBinDir = "${ndkDir}/sources/third_party/vulkan/src/build-android/jniLibs"
...
android {
...
sourceSets {
main {
jniLibs {
srcDirs = ["${valLayerBinDir}"]
}
}
}
}
Instance
We mentioned VkInstance
in the last article. Now we are going to integrate it into our OO architecture. Class Instance
holds the core memberVkInstance
for sure, a method to create the VkInstance
actually, and LayerAndExtension
used as an argument to CreateInstance
. we do not create a constructor like Instance(const LayerAndExtension&)
since the layers and extensions required are application by application. Hence we have BuildInstance
independent of Instance
as a flow controller with all parameters and post process of instance creation like registering debugging callback. vkCreateInstance
/ vkDesctroyInstance
do the actual creation/destruction job. Note AppendInstanceExtension
appends platform specific extension which is also worth being extracted out.
Surface
To display a rendering result we have to interact with a window system which is platform specific. So we need something to abstract native platform surface or window objects. That is what a surface is responsible for. However, the Vulkan API can be used without displaying results, WSI(window system integration) is provided as optional Vulkan extensions.
Besides the core member VkSurface
, surface creation is pertinent to VkInstance
and is a fixed workflow, so we need a constructor with arguments ANativeWindow
and VkInstance
. The vkCreateAndroidSurfaceKHR
/ vkDestroySurfaceKHR
pair create and destroy the VkSurface
. Note we put the constructor body to another file since ANativeWindow
is native to Android platform. Finally, as its name says, QuerySurfaceSupport
queries the capabilities of a VkSurface
.