Writing an initView Function#

Generic#

initView will be called once when the window has been created and initialised. If the application loses and regains the window/API/surface, initView will be called again after releaseView.

In initView, the window has already been created. The convention is to initialise the API here. All PowerVR SDK examples use PVRUtils to create the context (if OpenGL ES) or the instance, device surface, and swapchain (if Vulkan) here.

After initialising the API, initView can be used for one-shot initialisation of other API-specific code. In simple applications, this might be initialising all of the actual objects used. In more complex applications with streaming assets and so on, this may be initialising the resource managers and similar classes.

OpenGL ES#

Create the EGL/EAGL context here using pvr::createEglContext. The context needs to be initialised with the display and window handles returned by the getDisplay() and getWindow() functions of the shell, as well as some further parameters.

Next, create any OpenGL ES shader programs and other OpenGL objects that are required. Set up any default OpenGL ES states that would be persistent throughout the program, or any other OpenGL ES initialisation that may be needed.

Remember to use the pvr::utils namespace to simplify/automate tasks like texture uploading. If necessary, jump into functions to see their implementations. Not all are simple but they will usually point in the right direction.

Vulkan#

Create/get the basic Vulkan objects here, including the instance, physical device, device, surface, swapchain, and depth buffer. Unless doing a specific exercise, use the PVRUtilsVk helpers, otherwise the two to three lines of code can transform into the hundreds before even starting to code application logic.

An example of how to set up initView in Vulkan is explained in Example initView Setup for Vulkan.