Writing an initApplication Function#
The initApplication
function will always be called just once before initView
, and before any kind of window/surface/API initialisation.
Do any non-API specific application initialisation code, such as:
Loading objects that will be persistent throughout the application, but do not create API objects for them. For example, models may be loaded from file here, or PVRAssets may be used freely here.
Do not use
PVRVk/PVRUtilsVk/PVRUtilsES
at all yet. The underlying window has not yet been initialised/created so most functions would fail or crash, and the shell variables used for context creation (likeOSDisplay
andOSWindow
) are not yet initialised.Most importantly, if any application settings need to be changed from their defaults, they must be defined here. These are settings such as window size, window surface format, specific API versions, vsync, or other application customisations. The
setXXXXX()
shell functions give access to exactly this kind of customisation. Many of those settings may potentially be read from the command line as well. Keep in mind that setting them manually will override the corresponding command line arguments.
Any changes here will override changes passed to pvr::Shell
from the command line.
The initApplication
function in the SDK Vulkan example IntroducingPVRUtils is shown below:
pvr::Result VulkanIntroducingPVRUtils::initApplication()
{
// Load the _scene
_scene = pvr::assets::Model::createWithReader(pvr::assets::PODReader(getAssetStream(SceneFileName)));
// The cameras are stored in the file. We check it contains at least one.
if (_scene->getNumCameras() == 0)
{
throw pvr::InvalidDataError("ERROR: The scene does not contain a camera");
}
// We check the scene contains at least one light
if (_scene->getNumLights() == 0)
{
throw pvr::InvalidDataError("The scene does not contain a light\n");
}
// Ensure that all meshes use an indexed triangle list
for (uint32_t i = 0; i < _scene->getNumMeshes(); ++i)
{
if (_scene->getMesh(i).getPrimitiveType() != pvr::PrimitiveTopology::TriangleList || _scene->getMesh(i).getFaces().getDataSize() == 0)
{
throw pvr::InvalidDataError("ERROR: The meshes in the scene should use an indexed triangle list\n");
}
}
// Initialize variables used for the animation
_frame = 0;
_frameId = 0;
return pvr::Result::Success;
}
Here are a few examples of the most common functions that can be called in initApplication
:
setDimensions
(orsetWidth
andsetHeight
).setPreferredSwapchainLength
.setFullScreen
.setVsyncMode
.forceFrameTime
.setColorBitsPerPixel
,setDepthBitsPerPixel
andsetStencilBitsPerPixel
.setBackbufferColorspace
.