libigl v2.5.0
Loading...
Searching...
No Matches
EmbreeDevice.h
Go to the documentation of this file.
1// This file is part of libigl, a simple c++ geometry processing library.
2//
3// Copyright (C) 2020 Vladimir Fonov <vladimir.fonov@gmail.com>
4// 2013 Alec Jacobson <alecjacobson@gmail.com>
5// 2014 Christian Schüller <schuellchr@gmail.com>
6//
7// This Source Code Form is subject to the terms of the Mozilla Public License
8// v. 2.0. If a copy of the MPL was not distributed with this file, You can
9// obtain one at http://mozilla.org/MPL/2.0/.
10//
11
12#ifndef IGL_EMBREE_EMBREE_DEVICE_H
13#define IGL_EMBREE_EMBREE_DEVICE_H
14#include <embree3/rtcore.h>
15#include <iostream>
16
17namespace igl
18{
19 namespace embree
20 {
23 {
24 RTCDevice embree_device;
26
28 {
29 static EmbreeDevice s;
30 return s;
31 } // instance
32
33 EmbreeDevice(const EmbreeDevice &) = delete;
35
36 static RTCDevice get_device(const char *config=nullptr)
37 {
38 return instance().get(config);
39 }
40
41 static void release_device(void)
42 {
43 instance().release();
44 }
45
46 private:
47
49
50 ~EmbreeDevice()
51 {
53 rtcReleaseDevice(embree_device);
54 }
55
56 RTCDevice get(const char *config=nullptr)
57 {
58 if(!embree_device)
59 {
60 embree_device = rtcNewDevice (config);
61 if(rtcGetDeviceError (embree_device) != RTC_ERROR_NONE)
62 std::cerr << "Embree: An error occurred while initializing embree core!" << std::endl;
63 #ifdef IGL_VERBOSE
64 else
65 std::cerr << "Embree: core initialized." << std::endl;
66 #endif
67 }
69 return embree_device;
70 }
71
72 void release()
73 {
74 if(!--embree_device_cntr) {
75 rtcReleaseDevice (embree_device);
76 embree_device = nullptr;
77 #ifdef IGL_VERBOSE
78 std::cerr << "Embree: core released." << std::endl;
79 #endif
80 }
81 }
82 };
83 }
84}
85
86#endif // IGL_EMBREE_EMBREE_DEVICE_H
Definition AABB.h:17
keep track of embree device instance
Definition EmbreeDevice.h:23
EmbreeDevice & operator=(const EmbreeDevice &)=delete
int embree_device_cntr
Definition EmbreeDevice.h:25
RTCDevice embree_device
Definition EmbreeDevice.h:24
static void release_device(void)
Definition EmbreeDevice.h:41
static EmbreeDevice & instance()
Definition EmbreeDevice.h:27
static RTCDevice get_device(const char *config=nullptr)
Definition EmbreeDevice.h:36
EmbreeDevice(const EmbreeDevice &)=delete