openHMD-simple代码分析(2/2)
接上篇内容,这里主要以oculars在openHMD中的提交,来分析oculars的DK1/DK2在openHMD中是如何运行的。
simple代码的主流程看上篇文章”openHMD-simple代码分析(1/2)”。
打开设备:ohmd_list_open_device
//打开设备列表中第一个设备
ohmd_device* hmd = ohmd_list_open_device(ctx, 0);
if(!hmd){
printf("failed to open device: %s\n", ohmd_ctx_get_error(ctx));
return -1;
}
ohmd_list_open_device函数:
ohmd_device* OHMD_APIENTRY ohmd_list_open_device(ohmd_context* ctx, int index)
{
ohmd_device_settings settings;
//设置设备数据的更新方式:
//false:需要手动调用ohmd_ctx_update来更新数据
//true:创建线程,调用设备的update方法来更新数据(如rift.c里的update_devices)
settings.automatic_update = true;
return ohmd_list_open_device_s(ctx, index, &settings);
}
ohmd_list_open_device_s函数:
ohmd_device* OHMD_APIENTRY ohmd_list_open_device_s(ohmd_context* ctx, int index, ohmd_device_settings* settings)
{
ohmd_lock_mutex(ctx->update_mutex);
//轮询所有设备
if(index >= 0 && index < ctx->list.num_devices){
ohmd_device_desc* desc = &ctx->list.devices[index];
ohmd_driver* driver = (ohmd_driver*)desc->driver_ptr;
ohmd_device* device = driver->open_device(driver, desc);
if (device == NULL)
return</