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 <embree4/rtcore.h>
15#include <cassert>
16#include <iostream>
17#include <cassert>
18
19namespace igl
20{
21 namespace embree
22 {
25 {
26 RTCDevice embree_device;
28
30 {
31 static EmbreeDevice s;
32 return s;
33 } // instance
34
35 EmbreeDevice(const EmbreeDevice &) = delete;
37
38 static RTCDevice get_device(const char *config=nullptr)
39 {
40 return instance().get(config);
41 }
42
43 static void release_device(void)
44 {
45 instance().release();
46 }
47
48 private:
49
51
52 ~EmbreeDevice()
53 {
55 rtcReleaseDevice(embree_device);
56 }
57
58 RTCDevice get(const char *config=nullptr)
59 {
60 if(!embree_device)
61 {
62 embree_device = rtcNewDevice (config);
63 if(rtcGetDeviceError (embree_device) != RTC_ERROR_NONE)
64 {
65 assert(false && "Embree: An error occurred while initializing embree core!");
66#ifdef IGL_VERBOSE
67 std::cerr << "Embree: An error occurred while initializing embree core!" << std::endl;
68 }
69 else
70 {
71 std::cerr << "Embree: core initialized." << std::endl;
72#endif
73 }
74 }
76 return embree_device;
77 }
78
79 void release()
80 {
81 if(!--embree_device_cntr) {
82 rtcReleaseDevice (embree_device);
83 embree_device = nullptr;
84#ifdef IGL_VERBOSE
85 std::cerr << "Embree: core released." << std::endl;
86#endif
87 }
88 }
89 };
90 }
91}
92
93#endif // IGL_EMBREE_EMBREE_DEVICE_H
Definition ambient_occlusion.h:15
Definition AABB.h:18
EmbreeDevice & operator=(const EmbreeDevice &)=delete
int embree_device_cntr
Definition EmbreeDevice.h:27
RTCDevice embree_device
Definition EmbreeDevice.h:26
static void release_device(void)
Definition EmbreeDevice.h:43
static EmbreeDevice & instance()
Definition EmbreeDevice.h:29
static RTCDevice get_device(const char *config=nullptr)
Definition EmbreeDevice.h:38
EmbreeDevice(const EmbreeDevice &)=delete