134 {
135 uint32_t properties_count = 0;
136 XrResult result = xrEnumerateInstanceExtensionProperties(nullptr,
137 properties_count,
138 &properties_count,
139 nullptr);
140 if(!XR_SUCCEEDED(result)){
142 } else {
143 std::vector<XrExtensionProperties> props;
144 props.resize(properties_count);
145 for(auto& prop : props){
146 prop.type = XR_TYPE_EXTENSION_PROPERTIES;
147 prop.next = nullptr;
148 }
149 result = xrEnumerateInstanceExtensionProperties(nullptr,
150 properties_count,
151 &properties_count,
152 props.data());
153
154 bool found = false;
155 for(const auto& prop : props){
156 if(strcmp(prop.extensionName, XR_KHR_OPENGL_ENABLE_EXTENSION_NAME) == 0){
157 found = true;
158 break;
159 }
160 }
161 if(!found){
162 throw std::runtime_error("OpenXR runtime does not support OpenGL interop!");
163 }
164 }
165 const char* const enabledExtensions[] = {XR_KHR_OPENGL_ENABLE_EXTENSION_NAME};
166
167 XrInstanceCreateInfo instanceCreateInfo;
168 instanceCreateInfo.type = XR_TYPE_INSTANCE_CREATE_INFO;
169 instanceCreateInfo.next = NULL;
170 instanceCreateInfo.createFlags = 0;
171 instanceCreateInfo.enabledExtensionCount = 1;
172 instanceCreateInfo.enabledExtensionNames = enabledExtensions;
173 instanceCreateInfo.enabledApiLayerCount = 0;
174 strcpy(instanceCreateInfo.applicationInfo.applicationName, "UltraGrid OpenXR gl display");
175 strcpy(instanceCreateInfo.applicationInfo.engineName, "");
176 instanceCreateInfo.applicationInfo.applicationVersion = 1;
177 instanceCreateInfo.applicationInfo.engineVersion = 0;
178 instanceCreateInfo.applicationInfo.apiVersion = XR_CURRENT_API_VERSION;
179
180 result = xrCreateInstance(&instanceCreateInfo, &
instance);
181 if(!XR_SUCCEEDED(result)){
182 throw std::runtime_error("Failed to create OpenXR instance!");
183 }
184
185 XrInstanceProperties instanceProperties;
186 instanceProperties.type = XR_TYPE_INSTANCE_PROPERTIES;
187 instanceProperties.next = NULL;
188
189 result = xrGetInstanceProperties(
instance, &instanceProperties);
190
191 if(XR_SUCCEEDED(result)){
192 printf("Runtime Name: %s\n", instanceProperties.runtimeName);
193 printf("Runtime Version: %d.%d.%d\n",
194 XR_VERSION_MAJOR(instanceProperties.runtimeVersion),
195 XR_VERSION_MINOR(instanceProperties.runtimeVersion),
196 XR_VERSION_PATCH(instanceProperties.runtimeVersion));
197 }
198
199
200 }
void log_msg(int level, const char *format,...)
#define LOG_LEVEL_WARNING
less severe errors