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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
// This file is part of libigl, a simple c++ geometry processing library.
//
// Copyright (C) 2020 Vladimir Fonov <vladimir.fonov@gmail.com>
// 2013 Alec Jacobson <alecjacobson@gmail.com>
// 2014 Christian Schüller <schuellchr@gmail.com>
//
// This Source Code Form is subject to the terms of the Mozilla Public License
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
// obtain one at http://mozilla.org/MPL/2.0/.
//
#ifndef IGL_EMBREE_EMBREE_DEVICE_H
#define IGL_EMBREE_EMBREE_DEVICE_H
#include <embree3/rtcore.h>
#include <iostream>
namespace igl
{
namespace embree
{
// keep track of embree device
struct EmbreeDevice
{
RTCDevice embree_device;
int embree_device_cntr;
static EmbreeDevice & instance()
{
static EmbreeDevice s;
return s;
} // instance
EmbreeDevice(const EmbreeDevice &) = delete;
EmbreeDevice & operator = (const EmbreeDevice &) = delete;
static RTCDevice get_device(const char *config=nullptr)
{
return instance().get(config);
}
static void release_device(void)
{
instance().release();
}
private:
EmbreeDevice():embree_device(nullptr),embree_device_cntr(0) {}
~EmbreeDevice()
{
if(embree_device)
rtcReleaseDevice(embree_device);
}
RTCDevice get(const char *config=nullptr)
{
if(!embree_device)
{
embree_device = rtcNewDevice (config);
if(rtcGetDeviceError (embree_device) != RTC_ERROR_NONE)
std::cerr << "Embree: An error occurred while initializing embree core!" << std::endl;
#ifdef IGL_VERBOSE
else
std::cerr << "Embree: core initialized." << std::endl;
#endif
}
++embree_device_cntr;
return embree_device;
}
void release()
{
if(!--embree_device_cntr) {
rtcReleaseDevice (embree_device);
embree_device = nullptr;
#ifdef IGL_VERBOSE
std::cerr << "Embree: core released." << std::endl;
#endif
}
}
};
}
}
#endif // IGL_EMBREE_EMBREE_DEVICE_H
|