1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
// Copyright 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
#pragma once
// ospray
#include "ospray/ospray.h"
// std
#include <iostream>
#include <stdexcept>
inline void initializeOSPRay(
int argc, const char **argv, bool errorsFatal = true)
{
// initialize OSPRay; OSPRay parses (and removes) its commandline parameters,
// e.g. "--osp:debug"
OSPError initError = ospInit(&argc, argv);
if (initError != OSP_NO_ERROR)
throw std::runtime_error("OSPRay not initialized correctly!");
OSPDevice device = ospGetCurrentDevice();
if (!device)
throw std::runtime_error("OSPRay device could not be fetched!");
// set an error callback to catch any OSPRay errors and exit the application
if (errorsFatal) {
ospDeviceSetErrorCallback(
device,
[](void *, OSPError error, const char *errorDetails) {
std::cerr << "OSPRay error: " << errorDetails << std::endl;
exit(error);
},
nullptr);
} else {
ospDeviceSetErrorCallback(
device,
[](void *, OSPError, const char *errorDetails) {
std::cerr << "OSPRay error: " << errorDetails << std::endl;
},
nullptr);
}
ospDeviceSetStatusCallback(
device, [](void *, const char *msg) { std::cout << msg; }, nullptr);
bool warnAsErrors = true;
auto logLevel = OSP_LOG_WARNING;
ospDeviceSetParam(device, "warnAsError", OSP_BOOL, &warnAsErrors);
ospDeviceSetParam(device, "logLevel", OSP_UINT, &logLevel);
ospDeviceCommit(device);
ospDeviceRelease(device);
}
|