| 259 | } |
| 260 | |
| 261 | OIDN_API OIDNDevice oidnNewDevice(OIDNDeviceType inType) |
| 262 | { |
| 263 | DeviceType type = static_cast<DeviceType>(inType); |
| 264 | Ref<Device> device = nullptr; |
| 265 | |
| 266 | OIDN_TRY |
| 267 | OIDN_INIT_CONTEXT(ctx, type); |
| 268 | |
| 269 | if (type == DeviceType::Default) |
| 270 | { |
| 271 | const int numDevices = ctx.getNumPhysicalDevices(); |
| 272 | if (numDevices == 0) |
| 273 | throw Exception(Error::UnsupportedHardware, "no supported devices found"); |
| 274 | |
| 275 | // Check whether the user wants to override the default device |
| 276 | std::string deviceStr; |
| 277 | if (getEnvVar("OIDN_DEFAULT_DEVICE", deviceStr) && !deviceStr.empty()) |
| 278 | { |
| 279 | if (isdigit(deviceStr[0])) |
| 280 | { |
| 281 | const int id = fromString<int>(deviceStr); |
| 282 | if (id >= 0 && id < numDevices) |
| 283 | device = ctx.newDevice(id); |
| 284 | } |
| 285 | else |
| 286 | { |
| 287 | try |
| 288 | { |
| 289 | type = fromString<DeviceType>(deviceStr); |
| 290 | } |
| 291 | catch (...) {} |
| 292 | |
| 293 | if (ctx.isDeviceSupported(type)) |
| 294 | device = ctx.newDevice(type); |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | if (!device) |
| 299 | device = ctx.newDevice(0); |
| 300 | } |
| 301 | else |
| 302 | { |
| 303 | device = ctx.newDevice(type); |
| 304 | } |
| 305 | OIDN_CATCH |
| 306 | |
| 307 | return reinterpret_cast<OIDNDevice>(device.detach()); |
| 308 | } |
| 309 | |
| 310 | OIDN_API OIDNDevice oidnNewDeviceByID(int physicalDeviceID) |
| 311 | { |
nothing calls this directly
no test coverage detected