4. Instance
OpenXR instance是一个允许OpenXR application和runtime进行通信的句柄对象。application通过调用xrCreateInstance()和接收一个XrInstance对应的handle完成通信。
XrInstance对象存储和追踪OpenXR相关应用的状态,不需要在application的全局地址空间中存储任何这样的状态。由于instance对象对于application是不透明的,因此application可以创建多个instance,并安全封装application的OpenXR state。
OpenXR runtime可能会限制同时创建和使用XrInstance对象的数量,但他们必须支持每个进程至少创建和使用一个XrInstance对象。
4.1 API layers
API layers或者扩展层可以提供附加功能。API Layer禁止添加或者修改OpenXR function的定义,而扩展层(extensions)可以。
API layers函数集的使能要在创建instance时指定,这些API layers能够拦截(intercept)任何分发给该instance或者它的子类对象的函数。
API layers示例可以包含(但不限制于):
- dump out OpenXR API的调用
- 执行OpenXR校验。
4.1.1. xrEnumerateApiLayerProperties()
XrResult xrEnumerateApiLayerProperties(
uint32_t propertyCapacityInput,
uint32_t* propertyCountOutput,
XrApiLayerProperties* properties);
- 该函数决定哪些API layers集是可用的。
- 参数propertyCapacityInput是属性array的容量值,0表示请求检索需要的capacity。
- 参数propertyCountOutput是指向要写入属性数量的指针,或者是指向所需capacity的指针,以防propertyCapacityInput不足的情况。
- 属性是指向XrApiLayerProperties结构体数组的指针,如果propertyCapacityInput=0,则可以为NULL。
- 由于Runtime的外部操作,layers的可用列表在任何时间可能变化,因此该方法的使用相同的参数调用两次,返回结果可能不同。
一旦创建了instance,使能的layers在该instance的有效生命周期内都会继续enabled和valid,即使其中一些layer对未来的instance不可用。
4.1.2. XrApiLayerProperties结构体
typedef struct XrApiLayerProperties {
XrStructureType type;
void* next;
char layerName[XR_MAX_API_LAYER_NAME_SIZE];
XrV