rtcore.cpp 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782
  1. // Copyright 2009-2021 Intel Corporation
  2. // SPDX-License-Identifier: Apache-2.0
  3. #define RTC_EXPORT_API
  4. #include "default.h"
  5. #include "device.h"
  6. #include "scene.h"
  7. #include "context.h"
  8. #include "../geometry/filter.h"
  9. #include "../../include/embree3/rtcore_ray.h"
  10. using namespace embree;
  11. RTC_NAMESPACE_BEGIN;
  12. /* mutex to make API thread safe */
  13. static MutexSys g_mutex;
  14. RTC_API RTCDevice rtcNewDevice(const char* config)
  15. {
  16. RTC_CATCH_BEGIN;
  17. RTC_TRACE(rtcNewDevice);
  18. Lock<MutexSys> lock(g_mutex);
  19. Device* device = new Device(config);
  20. return (RTCDevice) device->refInc();
  21. RTC_CATCH_END(nullptr);
  22. return (RTCDevice) nullptr;
  23. }
  24. RTC_API void rtcRetainDevice(RTCDevice hdevice)
  25. {
  26. Device* device = (Device*) hdevice;
  27. RTC_CATCH_BEGIN;
  28. RTC_TRACE(rtcRetainDevice);
  29. RTC_VERIFY_HANDLE(hdevice);
  30. Lock<MutexSys> lock(g_mutex);
  31. device->refInc();
  32. RTC_CATCH_END(nullptr);
  33. }
  34. RTC_API void rtcReleaseDevice(RTCDevice hdevice)
  35. {
  36. Device* device = (Device*) hdevice;
  37. RTC_CATCH_BEGIN;
  38. RTC_TRACE(rtcReleaseDevice);
  39. RTC_VERIFY_HANDLE(hdevice);
  40. Lock<MutexSys> lock(g_mutex);
  41. device->refDec();
  42. RTC_CATCH_END(nullptr);
  43. }
  44. RTC_API ssize_t rtcGetDeviceProperty(RTCDevice hdevice, RTCDeviceProperty prop)
  45. {
  46. Device* device = (Device*) hdevice;
  47. RTC_CATCH_BEGIN;
  48. RTC_TRACE(rtcGetDeviceProperty);
  49. RTC_VERIFY_HANDLE(hdevice);
  50. Lock<MutexSys> lock(g_mutex);
  51. return device->getProperty(prop);
  52. RTC_CATCH_END(device);
  53. return 0;
  54. }
  55. RTC_API void rtcSetDeviceProperty(RTCDevice hdevice, const RTCDeviceProperty prop, ssize_t val)
  56. {
  57. Device* device = (Device*) hdevice;
  58. RTC_CATCH_BEGIN;
  59. RTC_TRACE(rtcSetDeviceProperty);
  60. const bool internal_prop = (size_t)prop >= 1000000 && (size_t)prop < 1000004;
  61. if (!internal_prop) RTC_VERIFY_HANDLE(hdevice); // allow NULL device for special internal settings
  62. Lock<MutexSys> lock(g_mutex);
  63. device->setProperty(prop,val);
  64. RTC_CATCH_END(device);
  65. }
  66. RTC_API RTCError rtcGetDeviceError(RTCDevice hdevice)
  67. {
  68. Device* device = (Device*) hdevice;
  69. RTC_CATCH_BEGIN;
  70. RTC_TRACE(rtcGetDeviceError);
  71. if (device == nullptr) return Device::getThreadErrorCode();
  72. else return device->getDeviceErrorCode();
  73. RTC_CATCH_END(device);
  74. return RTC_ERROR_UNKNOWN;
  75. }
  76. RTC_API void rtcSetDeviceErrorFunction(RTCDevice hdevice, RTCErrorFunction error, void* userPtr)
  77. {
  78. Device* device = (Device*) hdevice;
  79. RTC_CATCH_BEGIN;
  80. RTC_TRACE(rtcSetDeviceErrorFunction);
  81. RTC_VERIFY_HANDLE(hdevice);
  82. device->setErrorFunction(error, userPtr);
  83. RTC_CATCH_END(device);
  84. }
  85. RTC_API void rtcSetDeviceMemoryMonitorFunction(RTCDevice hdevice, RTCMemoryMonitorFunction memoryMonitor, void* userPtr)
  86. {
  87. Device* device = (Device*) hdevice;
  88. RTC_CATCH_BEGIN;
  89. RTC_TRACE(rtcSetDeviceMemoryMonitorFunction);
  90. device->setMemoryMonitorFunction(memoryMonitor, userPtr);
  91. RTC_CATCH_END(device);
  92. }
  93. RTC_API RTCBuffer rtcNewBuffer(RTCDevice hdevice, size_t byteSize)
  94. {
  95. RTC_CATCH_BEGIN;
  96. RTC_TRACE(rtcNewBuffer);
  97. RTC_VERIFY_HANDLE(hdevice);
  98. Buffer* buffer = new Buffer((Device*)hdevice, byteSize);
  99. return (RTCBuffer)buffer->refInc();
  100. RTC_CATCH_END((Device*)hdevice);
  101. return nullptr;
  102. }
  103. RTC_API RTCBuffer rtcNewSharedBuffer(RTCDevice hdevice, void* ptr, size_t byteSize)
  104. {
  105. RTC_CATCH_BEGIN;
  106. RTC_TRACE(rtcNewSharedBuffer);
  107. RTC_VERIFY_HANDLE(hdevice);
  108. Buffer* buffer = new Buffer((Device*)hdevice, byteSize, ptr);
  109. return (RTCBuffer)buffer->refInc();
  110. RTC_CATCH_END((Device*)hdevice);
  111. return nullptr;
  112. }
  113. RTC_API void* rtcGetBufferData(RTCBuffer hbuffer)
  114. {
  115. Buffer* buffer = (Buffer*)hbuffer;
  116. RTC_CATCH_BEGIN;
  117. RTC_TRACE(rtcGetBufferData);
  118. RTC_VERIFY_HANDLE(hbuffer);
  119. return buffer->data();
  120. RTC_CATCH_END2(buffer);
  121. return nullptr;
  122. }
  123. RTC_API void rtcRetainBuffer(RTCBuffer hbuffer)
  124. {
  125. Buffer* buffer = (Buffer*)hbuffer;
  126. RTC_CATCH_BEGIN;
  127. RTC_TRACE(rtcRetainBuffer);
  128. RTC_VERIFY_HANDLE(hbuffer);
  129. buffer->refInc();
  130. RTC_CATCH_END2(buffer);
  131. }
  132. RTC_API void rtcReleaseBuffer(RTCBuffer hbuffer)
  133. {
  134. Buffer* buffer = (Buffer*)hbuffer;
  135. RTC_CATCH_BEGIN;
  136. RTC_TRACE(rtcReleaseBuffer);
  137. RTC_VERIFY_HANDLE(hbuffer);
  138. buffer->refDec();
  139. RTC_CATCH_END2(buffer);
  140. }
  141. RTC_API RTCScene rtcNewScene (RTCDevice hdevice)
  142. {
  143. RTC_CATCH_BEGIN;
  144. RTC_TRACE(rtcNewScene);
  145. RTC_VERIFY_HANDLE(hdevice);
  146. Scene* scene = new Scene((Device*)hdevice);
  147. return (RTCScene) scene->refInc();
  148. RTC_CATCH_END((Device*)hdevice);
  149. return nullptr;
  150. }
  151. RTC_API RTCDevice rtcGetSceneDevice(RTCScene hscene)
  152. {
  153. Scene* scene = (Scene*) hscene;
  154. RTC_CATCH_BEGIN;
  155. RTC_TRACE(rtcGetSceneDevice);
  156. RTC_VERIFY_HANDLE(hscene);
  157. return (RTCDevice)scene->device->refInc(); // user will own one additional device reference
  158. RTC_CATCH_END2(scene);
  159. return (RTCDevice)nullptr;
  160. }
  161. RTC_API void rtcSetSceneProgressMonitorFunction(RTCScene hscene, RTCProgressMonitorFunction progress, void* ptr)
  162. {
  163. Scene* scene = (Scene*) hscene;
  164. RTC_CATCH_BEGIN;
  165. RTC_TRACE(rtcSetSceneProgressMonitorFunction);
  166. RTC_VERIFY_HANDLE(hscene);
  167. Lock<MutexSys> lock(g_mutex);
  168. scene->setProgressMonitorFunction(progress,ptr);
  169. RTC_CATCH_END2(scene);
  170. }
  171. RTC_API void rtcSetSceneBuildQuality (RTCScene hscene, RTCBuildQuality quality)
  172. {
  173. Scene* scene = (Scene*) hscene;
  174. RTC_CATCH_BEGIN;
  175. RTC_TRACE(rtcSetSceneBuildQuality);
  176. RTC_VERIFY_HANDLE(hscene);
  177. if (quality != RTC_BUILD_QUALITY_LOW &&
  178. quality != RTC_BUILD_QUALITY_MEDIUM &&
  179. quality != RTC_BUILD_QUALITY_HIGH)
  180. // -- GODOT start --
  181. // throw std::runtime_error("invalid build quality");
  182. abort();
  183. // -- GODOT end --
  184. scene->setBuildQuality(quality);
  185. RTC_CATCH_END2(scene);
  186. }
  187. RTC_API void rtcSetSceneFlags (RTCScene hscene, RTCSceneFlags flags)
  188. {
  189. Scene* scene = (Scene*) hscene;
  190. RTC_CATCH_BEGIN;
  191. RTC_TRACE(rtcSetSceneFlags);
  192. RTC_VERIFY_HANDLE(hscene);
  193. scene->setSceneFlags(flags);
  194. RTC_CATCH_END2(scene);
  195. }
  196. RTC_API RTCSceneFlags rtcGetSceneFlags(RTCScene hscene)
  197. {
  198. Scene* scene = (Scene*) hscene;
  199. RTC_CATCH_BEGIN;
  200. RTC_TRACE(rtcGetSceneFlags);
  201. RTC_VERIFY_HANDLE(hscene);
  202. return scene->getSceneFlags();
  203. RTC_CATCH_END2(scene);
  204. return RTC_SCENE_FLAG_NONE;
  205. }
  206. RTC_API void rtcCommitScene (RTCScene hscene)
  207. {
  208. Scene* scene = (Scene*) hscene;
  209. RTC_CATCH_BEGIN;
  210. RTC_TRACE(rtcCommitScene);
  211. RTC_VERIFY_HANDLE(hscene);
  212. scene->commit(false);
  213. RTC_CATCH_END2(scene);
  214. }
  215. RTC_API void rtcJoinCommitScene (RTCScene hscene)
  216. {
  217. Scene* scene = (Scene*) hscene;
  218. RTC_CATCH_BEGIN;
  219. RTC_TRACE(rtcJoinCommitScene);
  220. RTC_VERIFY_HANDLE(hscene);
  221. scene->commit(true);
  222. RTC_CATCH_END2(scene);
  223. }
  224. RTC_API void rtcGetSceneBounds(RTCScene hscene, RTCBounds* bounds_o)
  225. {
  226. Scene* scene = (Scene*) hscene;
  227. RTC_CATCH_BEGIN;
  228. RTC_TRACE(rtcGetSceneBounds);
  229. RTC_VERIFY_HANDLE(hscene);
  230. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
  231. BBox3fa bounds = scene->bounds.bounds();
  232. bounds_o->lower_x = bounds.lower.x;
  233. bounds_o->lower_y = bounds.lower.y;
  234. bounds_o->lower_z = bounds.lower.z;
  235. bounds_o->align0 = 0;
  236. bounds_o->upper_x = bounds.upper.x;
  237. bounds_o->upper_y = bounds.upper.y;
  238. bounds_o->upper_z = bounds.upper.z;
  239. bounds_o->align1 = 0;
  240. RTC_CATCH_END2(scene);
  241. }
  242. RTC_API void rtcGetSceneLinearBounds(RTCScene hscene, RTCLinearBounds* bounds_o)
  243. {
  244. Scene* scene = (Scene*) hscene;
  245. RTC_CATCH_BEGIN;
  246. RTC_TRACE(rtcGetSceneBounds);
  247. RTC_VERIFY_HANDLE(hscene);
  248. if (bounds_o == nullptr)
  249. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"invalid destination pointer");
  250. if (scene->isModified())
  251. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
  252. bounds_o->bounds0.lower_x = scene->bounds.bounds0.lower.x;
  253. bounds_o->bounds0.lower_y = scene->bounds.bounds0.lower.y;
  254. bounds_o->bounds0.lower_z = scene->bounds.bounds0.lower.z;
  255. bounds_o->bounds0.align0 = 0;
  256. bounds_o->bounds0.upper_x = scene->bounds.bounds0.upper.x;
  257. bounds_o->bounds0.upper_y = scene->bounds.bounds0.upper.y;
  258. bounds_o->bounds0.upper_z = scene->bounds.bounds0.upper.z;
  259. bounds_o->bounds0.align1 = 0;
  260. bounds_o->bounds1.lower_x = scene->bounds.bounds1.lower.x;
  261. bounds_o->bounds1.lower_y = scene->bounds.bounds1.lower.y;
  262. bounds_o->bounds1.lower_z = scene->bounds.bounds1.lower.z;
  263. bounds_o->bounds1.align0 = 0;
  264. bounds_o->bounds1.upper_x = scene->bounds.bounds1.upper.x;
  265. bounds_o->bounds1.upper_y = scene->bounds.bounds1.upper.y;
  266. bounds_o->bounds1.upper_z = scene->bounds.bounds1.upper.z;
  267. bounds_o->bounds1.align1 = 0;
  268. RTC_CATCH_END2(scene);
  269. }
  270. RTC_API void rtcCollide (RTCScene hscene0, RTCScene hscene1, RTCCollideFunc callback, void* userPtr)
  271. {
  272. Scene* scene0 = (Scene*) hscene0;
  273. Scene* scene1 = (Scene*) hscene1;
  274. RTC_CATCH_BEGIN;
  275. RTC_TRACE(rtcCollide);
  276. #if defined(DEBUG)
  277. RTC_VERIFY_HANDLE(hscene0);
  278. RTC_VERIFY_HANDLE(hscene1);
  279. if (scene0->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene got not committed");
  280. if (scene1->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene got not committed");
  281. if (scene0->device != scene1->device) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scenes are from different devices");
  282. auto nUserPrims0 = scene0->getNumPrimitives (Geometry::MTY_USER_GEOMETRY, false);
  283. auto nUserPrims1 = scene1->getNumPrimitives (Geometry::MTY_USER_GEOMETRY, false);
  284. if (scene0->numPrimitives() != nUserPrims0 && scene1->numPrimitives() != nUserPrims1) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scenes must only contain user geometries with a single timestep");
  285. #endif
  286. scene0->intersectors.collide(scene0,scene1,callback,userPtr);
  287. RTC_CATCH_END(scene0->device);
  288. }
  289. inline bool pointQuery(Scene* scene, RTCPointQuery* query, RTCPointQueryContext* userContext, RTCPointQueryFunction queryFunc, void* userPtr)
  290. {
  291. bool changed = false;
  292. if (userContext->instStackSize > 0)
  293. {
  294. const AffineSpace3fa transform = AffineSpace3fa_load_unaligned((AffineSpace3fa*)userContext->world2inst[userContext->instStackSize-1]);
  295. float similarityScale = 0.f;
  296. const bool similtude = similarityTransform(transform, &similarityScale);
  297. assert((similtude && similarityScale > 0) || (!similtude && similarityScale == 0.f));
  298. PointQuery query_inst;
  299. query_inst.p = xfmPoint(transform, Vec3fa(query->x, query->y, query->z));
  300. query_inst.radius = query->radius * similarityScale;
  301. query_inst.time = query->time;
  302. PointQueryContext context_inst(scene, (PointQuery*)query,
  303. similtude ? POINT_QUERY_TYPE_SPHERE : POINT_QUERY_TYPE_AABB,
  304. queryFunc, userContext, similarityScale, userPtr);
  305. changed = scene->intersectors.pointQuery((PointQuery*)&query_inst, &context_inst);
  306. }
  307. else
  308. {
  309. PointQueryContext context(scene, (PointQuery*)query,
  310. POINT_QUERY_TYPE_SPHERE, queryFunc, userContext, 1.f, userPtr);
  311. changed = scene->intersectors.pointQuery((PointQuery*)query, &context);
  312. }
  313. return changed;
  314. }
  315. RTC_API bool rtcPointQuery(RTCScene hscene, RTCPointQuery* query, RTCPointQueryContext* userContext, RTCPointQueryFunction queryFunc, void* userPtr)
  316. {
  317. Scene* scene = (Scene*) hscene;
  318. RTC_CATCH_BEGIN;
  319. RTC_TRACE(rtcPointQuery);
  320. #if defined(DEBUG)
  321. RTC_VERIFY_HANDLE(hscene);
  322. RTC_VERIFY_HANDLE(userContext);
  323. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene got not committed");
  324. if (((size_t)query) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "query not aligned to 16 bytes");
  325. if (((size_t)userContext) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "context not aligned to 16 bytes");
  326. #endif
  327. return pointQuery(scene, query, userContext, queryFunc, userPtr);
  328. RTC_CATCH_END2_FALSE(scene);
  329. }
  330. RTC_API bool rtcPointQuery4 (const int* valid, RTCScene hscene, RTCPointQuery4* query, struct RTCPointQueryContext* userContext, RTCPointQueryFunction queryFunc, void** userPtrN)
  331. {
  332. Scene* scene = (Scene*) hscene;
  333. RTC_CATCH_BEGIN;
  334. RTC_TRACE(rtcPointQuery4);
  335. #if defined(DEBUG)
  336. RTC_VERIFY_HANDLE(hscene);
  337. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene got not committed");
  338. if (((size_t)valid) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "mask not aligned to 16 bytes");
  339. if (((size_t)query) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "query not aligned to 16 bytes");
  340. #endif
  341. STAT(size_t cnt=0; for (size_t i=0; i<4; i++) cnt += ((int*)valid)[i] == -1;);
  342. STAT3(point_query.travs,cnt,cnt,cnt);
  343. bool changed = false;
  344. PointQuery4* query4 = (PointQuery4*)query;
  345. PointQuery query1;
  346. for (size_t i=0; i<4; i++) {
  347. if (!valid[i]) continue;
  348. query4->get(i,query1);
  349. changed |= pointQuery(scene, (RTCPointQuery*)&query1, userContext, queryFunc, userPtrN?userPtrN[i]:NULL);
  350. query4->set(i,query1);
  351. }
  352. return changed;
  353. RTC_CATCH_END2_FALSE(scene);
  354. }
  355. RTC_API bool rtcPointQuery8 (const int* valid, RTCScene hscene, RTCPointQuery8* query, struct RTCPointQueryContext* userContext, RTCPointQueryFunction queryFunc, void** userPtrN)
  356. {
  357. Scene* scene = (Scene*) hscene;
  358. RTC_CATCH_BEGIN;
  359. RTC_TRACE(rtcPointQuery8);
  360. #if defined(DEBUG)
  361. RTC_VERIFY_HANDLE(hscene);
  362. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene got not committed");
  363. if (((size_t)valid) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "mask not aligned to 16 bytes");
  364. if (((size_t)query) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "query not aligned to 16 bytes");
  365. #endif
  366. STAT(size_t cnt=0; for (size_t i=0; i<4; i++) cnt += ((int*)valid)[i] == -1;);
  367. STAT3(point_query.travs,cnt,cnt,cnt);
  368. bool changed = false;
  369. PointQuery8* query8 = (PointQuery8*)query;
  370. PointQuery query1;
  371. for (size_t i=0; i<8; i++) {
  372. if (!valid[i]) continue;
  373. query8->get(i,query1);
  374. changed |= pointQuery(scene, (RTCPointQuery*)&query1, userContext, queryFunc, userPtrN?userPtrN[i]:NULL);
  375. query8->set(i,query1);
  376. }
  377. return changed;
  378. RTC_CATCH_END2_FALSE(scene);
  379. }
  380. RTC_API bool rtcPointQuery16 (const int* valid, RTCScene hscene, RTCPointQuery16* query, struct RTCPointQueryContext* userContext, RTCPointQueryFunction queryFunc, void** userPtrN)
  381. {
  382. Scene* scene = (Scene*) hscene;
  383. RTC_CATCH_BEGIN;
  384. RTC_TRACE(rtcPointQuery16);
  385. #if defined(DEBUG)
  386. RTC_VERIFY_HANDLE(hscene);
  387. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene got not committed");
  388. if (((size_t)valid) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "mask not aligned to 16 bytes");
  389. if (((size_t)query) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "query not aligned to 16 bytes");
  390. #endif
  391. STAT(size_t cnt=0; for (size_t i=0; i<4; i++) cnt += ((int*)valid)[i] == -1;);
  392. STAT3(point_query.travs,cnt,cnt,cnt);
  393. bool changed = false;
  394. PointQuery16* query16 = (PointQuery16*)query;
  395. PointQuery query1;
  396. for (size_t i=0; i<16; i++) {
  397. if (!valid[i]) continue;
  398. PointQuery query1; query16->get(i,query1);
  399. changed |= pointQuery(scene, (RTCPointQuery*)&query1, userContext, queryFunc, userPtrN?userPtrN[i]:NULL);
  400. query16->set(i,query1);
  401. }
  402. return changed;
  403. RTC_CATCH_END2_FALSE(scene);
  404. }
  405. RTC_API void rtcIntersect1 (RTCScene hscene, RTCIntersectContext* user_context, RTCRayHit* rayhit)
  406. {
  407. Scene* scene = (Scene*) hscene;
  408. RTC_CATCH_BEGIN;
  409. RTC_TRACE(rtcIntersect1);
  410. #if defined(DEBUG)
  411. RTC_VERIFY_HANDLE(hscene);
  412. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
  413. if (((size_t)rayhit) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 16 bytes");
  414. #endif
  415. STAT3(normal.travs,1,1,1);
  416. IntersectContext context(scene,user_context);
  417. scene->intersectors.intersect(*rayhit,&context);
  418. #if defined(DEBUG)
  419. ((RayHit*)rayhit)->verifyHit();
  420. #endif
  421. RTC_CATCH_END2(scene);
  422. }
  423. RTC_API void rtcIntersect4 (const int* valid, RTCScene hscene, RTCIntersectContext* user_context, RTCRayHit4* rayhit)
  424. {
  425. Scene* scene = (Scene*) hscene;
  426. RTC_CATCH_BEGIN;
  427. RTC_TRACE(rtcIntersect4);
  428. #if defined(DEBUG)
  429. RTC_VERIFY_HANDLE(hscene);
  430. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
  431. if (((size_t)valid) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "mask not aligned to 16 bytes");
  432. if (((size_t)rayhit) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit not aligned to 16 bytes");
  433. #endif
  434. STAT(size_t cnt=0; for (size_t i=0; i<4; i++) cnt += ((int*)valid)[i] == -1;);
  435. STAT3(normal.travs,cnt,cnt,cnt);
  436. IntersectContext context(scene,user_context);
  437. #if !defined(EMBREE_RAY_PACKETS)
  438. RayHit4* ray4 = (RayHit4*) rayhit;
  439. for (size_t i=0; i<4; i++) {
  440. if (!valid[i]) continue;
  441. RayHit ray1; ray4->get(i,ray1);
  442. scene->intersectors.intersect((RTCRayHit&)ray1,&context);
  443. ray4->set(i,ray1);
  444. }
  445. #else
  446. scene->intersectors.intersect4(valid,*rayhit,&context);
  447. #endif
  448. RTC_CATCH_END2(scene);
  449. }
  450. RTC_API void rtcIntersect8 (const int* valid, RTCScene hscene, RTCIntersectContext* user_context, RTCRayHit8* rayhit)
  451. {
  452. Scene* scene = (Scene*) hscene;
  453. RTC_CATCH_BEGIN;
  454. RTC_TRACE(rtcIntersect8);
  455. #if defined(DEBUG)
  456. RTC_VERIFY_HANDLE(hscene);
  457. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
  458. if (((size_t)valid) & 0x1F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "mask not aligned to 32 bytes");
  459. if (((size_t)rayhit) & 0x1F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit not aligned to 32 bytes");
  460. #endif
  461. STAT(size_t cnt=0; for (size_t i=0; i<8; i++) cnt += ((int*)valid)[i] == -1;);
  462. STAT3(normal.travs,cnt,cnt,cnt);
  463. IntersectContext context(scene,user_context);
  464. #if !defined(EMBREE_RAY_PACKETS)
  465. RayHit8* ray8 = (RayHit8*) rayhit;
  466. for (size_t i=0; i<8; i++) {
  467. if (!valid[i]) continue;
  468. RayHit ray1; ray8->get(i,ray1);
  469. scene->intersectors.intersect((RTCRayHit&)ray1,&context);
  470. ray8->set(i,ray1);
  471. }
  472. #else
  473. if (likely(scene->intersectors.intersector8))
  474. scene->intersectors.intersect8(valid,*rayhit,&context);
  475. else
  476. scene->device->rayStreamFilters.intersectSOA(scene,(char*)rayhit,8,1,sizeof(RTCRayHit8),&context);
  477. #endif
  478. RTC_CATCH_END2(scene);
  479. }
  480. RTC_API void rtcIntersect16 (const int* valid, RTCScene hscene, RTCIntersectContext* user_context, RTCRayHit16* rayhit)
  481. {
  482. Scene* scene = (Scene*) hscene;
  483. RTC_CATCH_BEGIN;
  484. RTC_TRACE(rtcIntersect16);
  485. #if defined(DEBUG)
  486. RTC_VERIFY_HANDLE(hscene);
  487. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
  488. if (((size_t)valid) & 0x3F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "mask not aligned to 64 bytes");
  489. if (((size_t)rayhit) & 0x3F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit not aligned to 64 bytes");
  490. #endif
  491. STAT(size_t cnt=0; for (size_t i=0; i<16; i++) cnt += ((int*)valid)[i] == -1;);
  492. STAT3(normal.travs,cnt,cnt,cnt);
  493. IntersectContext context(scene,user_context);
  494. #if !defined(EMBREE_RAY_PACKETS)
  495. RayHit16* ray16 = (RayHit16*) rayhit;
  496. for (size_t i=0; i<16; i++) {
  497. if (!valid[i]) continue;
  498. RayHit ray1; ray16->get(i,ray1);
  499. scene->intersectors.intersect((RTCRayHit&)ray1,&context);
  500. ray16->set(i,ray1);
  501. }
  502. #else
  503. if (likely(scene->intersectors.intersector16))
  504. scene->intersectors.intersect16(valid,*rayhit,&context);
  505. else
  506. scene->device->rayStreamFilters.intersectSOA(scene,(char*)rayhit,16,1,sizeof(RTCRayHit16),&context);
  507. #endif
  508. RTC_CATCH_END2(scene);
  509. }
  510. RTC_API void rtcIntersect1M (RTCScene hscene, RTCIntersectContext* user_context, RTCRayHit* rayhit, unsigned int M, size_t byteStride)
  511. {
  512. Scene* scene = (Scene*) hscene;
  513. RTC_CATCH_BEGIN;
  514. RTC_TRACE(rtcIntersect1M);
  515. #if defined (EMBREE_RAY_PACKETS)
  516. #if defined(DEBUG)
  517. RTC_VERIFY_HANDLE(hscene);
  518. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
  519. if (((size_t)rayhit ) & 0x03) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 4 bytes");
  520. #endif
  521. STAT3(normal.travs,M,M,M);
  522. IntersectContext context(scene,user_context);
  523. /* fast codepath for single rays */
  524. if (likely(M == 1)) {
  525. if (likely(rayhit->ray.tnear <= rayhit->ray.tfar))
  526. scene->intersectors.intersect(*rayhit,&context);
  527. }
  528. /* codepath for streams */
  529. else {
  530. scene->device->rayStreamFilters.intersectAOS(scene,rayhit,M,byteStride,&context);
  531. }
  532. #else
  533. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"rtcIntersect1M not supported");
  534. #endif
  535. RTC_CATCH_END2(scene);
  536. }
  537. RTC_API void rtcIntersect1Mp (RTCScene hscene, RTCIntersectContext* user_context, RTCRayHit** rn, unsigned int M)
  538. {
  539. Scene* scene = (Scene*) hscene;
  540. RTC_CATCH_BEGIN;
  541. RTC_TRACE(rtcIntersect1Mp);
  542. #if defined (EMBREE_RAY_PACKETS)
  543. #if defined(DEBUG)
  544. RTC_VERIFY_HANDLE(hscene);
  545. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
  546. if (((size_t)rn) & 0x03) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 4 bytes");
  547. #endif
  548. STAT3(normal.travs,M,M,M);
  549. IntersectContext context(scene,user_context);
  550. /* fast codepath for single rays */
  551. if (likely(M == 1)) {
  552. if (likely(rn[0]->ray.tnear <= rn[0]->ray.tfar))
  553. scene->intersectors.intersect(*rn[0],&context);
  554. }
  555. /* codepath for streams */
  556. else {
  557. scene->device->rayStreamFilters.intersectAOP(scene,rn,M,&context);
  558. }
  559. #else
  560. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"rtcIntersect1Mp not supported");
  561. #endif
  562. RTC_CATCH_END2(scene);
  563. }
  564. RTC_API void rtcIntersectNM (RTCScene hscene, RTCIntersectContext* user_context, struct RTCRayHitN* rayhit, unsigned int N, unsigned int M, size_t byteStride)
  565. {
  566. Scene* scene = (Scene*) hscene;
  567. RTC_CATCH_BEGIN;
  568. RTC_TRACE(rtcIntersectNM);
  569. #if defined (EMBREE_RAY_PACKETS)
  570. #if defined(DEBUG)
  571. RTC_VERIFY_HANDLE(hscene);
  572. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
  573. if (((size_t)rayhit) & 0x03) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 4 bytes");
  574. #endif
  575. STAT3(normal.travs,N*M,N*M,N*M);
  576. IntersectContext context(scene,user_context);
  577. /* code path for single ray streams */
  578. if (likely(N == 1))
  579. {
  580. /* fast code path for streams of size 1 */
  581. if (likely(M == 1)) {
  582. if (likely(((RTCRayHit*)rayhit)->ray.tnear <= ((RTCRayHit*)rayhit)->ray.tfar))
  583. scene->intersectors.intersect(*(RTCRayHit*)rayhit,&context);
  584. }
  585. /* normal codepath for single ray streams */
  586. else {
  587. scene->device->rayStreamFilters.intersectAOS(scene,(RTCRayHit*)rayhit,M,byteStride,&context);
  588. }
  589. }
  590. /* code path for ray packet streams */
  591. else {
  592. scene->device->rayStreamFilters.intersectSOA(scene,(char*)rayhit,N,M,byteStride,&context);
  593. }
  594. #else
  595. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"rtcIntersectNM not supported");
  596. #endif
  597. RTC_CATCH_END2(scene);
  598. }
  599. RTC_API void rtcIntersectNp (RTCScene hscene, RTCIntersectContext* user_context, const RTCRayHitNp* rayhit, unsigned int N)
  600. {
  601. Scene* scene = (Scene*) hscene;
  602. RTC_CATCH_BEGIN;
  603. RTC_TRACE(rtcIntersectNp);
  604. #if defined (EMBREE_RAY_PACKETS)
  605. #if defined(DEBUG)
  606. RTC_VERIFY_HANDLE(hscene);
  607. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
  608. if (((size_t)rayhit->ray.org_x ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->ray.org_x not aligned to 4 bytes");
  609. if (((size_t)rayhit->ray.org_y ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->ray.org_y not aligned to 4 bytes");
  610. if (((size_t)rayhit->ray.org_z ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->ray.org_z not aligned to 4 bytes");
  611. if (((size_t)rayhit->ray.dir_x ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->ray.dir_x not aligned to 4 bytes");
  612. if (((size_t)rayhit->ray.dir_y ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->ray.dir_y not aligned to 4 bytes");
  613. if (((size_t)rayhit->ray.dir_z ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->ray.dir_z not aligned to 4 bytes");
  614. if (((size_t)rayhit->ray.tnear ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->ray.dir_x not aligned to 4 bytes");
  615. if (((size_t)rayhit->ray.tfar ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->ray.tnear not aligned to 4 bytes");
  616. if (((size_t)rayhit->ray.time ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->ray.time not aligned to 4 bytes");
  617. if (((size_t)rayhit->ray.mask ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->ray.mask not aligned to 4 bytes");
  618. if (((size_t)rayhit->hit.Ng_x ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->hit.Ng_x not aligned to 4 bytes");
  619. if (((size_t)rayhit->hit.Ng_y ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->hit.Ng_y not aligned to 4 bytes");
  620. if (((size_t)rayhit->hit.Ng_z ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->hit.Ng_z not aligned to 4 bytes");
  621. if (((size_t)rayhit->hit.u ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->hit.u not aligned to 4 bytes");
  622. if (((size_t)rayhit->hit.v ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->hit.v not aligned to 4 bytes");
  623. if (((size_t)rayhit->hit.geomID) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->hit.geomID not aligned to 4 bytes");
  624. if (((size_t)rayhit->hit.primID) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->hit.primID not aligned to 4 bytes");
  625. if (((size_t)rayhit->hit.instID) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->hit.instID not aligned to 4 bytes");
  626. #endif
  627. STAT3(normal.travs,N,N,N);
  628. IntersectContext context(scene,user_context);
  629. scene->device->rayStreamFilters.intersectSOP(scene,rayhit,N,&context);
  630. #else
  631. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"rtcIntersectNp not supported");
  632. #endif
  633. RTC_CATCH_END2(scene);
  634. }
  635. RTC_API void rtcOccluded1 (RTCScene hscene, RTCIntersectContext* user_context, RTCRay* ray)
  636. {
  637. Scene* scene = (Scene*) hscene;
  638. RTC_CATCH_BEGIN;
  639. RTC_TRACE(rtcOccluded1);
  640. STAT3(shadow.travs,1,1,1);
  641. #if defined(DEBUG)
  642. RTC_VERIFY_HANDLE(hscene);
  643. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
  644. if (((size_t)ray) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 16 bytes");
  645. #endif
  646. IntersectContext context(scene,user_context);
  647. scene->intersectors.occluded(*ray,&context);
  648. RTC_CATCH_END2(scene);
  649. }
  650. RTC_API void rtcOccluded4 (const int* valid, RTCScene hscene, RTCIntersectContext* user_context, RTCRay4* ray)
  651. {
  652. Scene* scene = (Scene*) hscene;
  653. RTC_CATCH_BEGIN;
  654. RTC_TRACE(rtcOccluded4);
  655. #if defined(DEBUG)
  656. RTC_VERIFY_HANDLE(hscene);
  657. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
  658. if (((size_t)valid) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "mask not aligned to 16 bytes");
  659. if (((size_t)ray) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 16 bytes");
  660. #endif
  661. STAT(size_t cnt=0; for (size_t i=0; i<4; i++) cnt += ((int*)valid)[i] == -1;);
  662. STAT3(shadow.travs,cnt,cnt,cnt);
  663. IntersectContext context(scene,user_context);
  664. #if !defined(EMBREE_RAY_PACKETS)
  665. RayHit4* ray4 = (RayHit4*) ray;
  666. for (size_t i=0; i<4; i++) {
  667. if (!valid[i]) continue;
  668. RayHit ray1; ray4->get(i,ray1);
  669. scene->intersectors.occluded((RTCRay&)ray1,&context);
  670. ray4->geomID[i] = ray1.geomID;
  671. }
  672. #else
  673. scene->intersectors.occluded4(valid,*ray,&context);
  674. #endif
  675. RTC_CATCH_END2(scene);
  676. }
  677. RTC_API void rtcOccluded8 (const int* valid, RTCScene hscene, RTCIntersectContext* user_context, RTCRay8* ray)
  678. {
  679. Scene* scene = (Scene*) hscene;
  680. RTC_CATCH_BEGIN;
  681. RTC_TRACE(rtcOccluded8);
  682. #if defined(DEBUG)
  683. RTC_VERIFY_HANDLE(hscene);
  684. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
  685. if (((size_t)valid) & 0x1F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "mask not aligned to 32 bytes");
  686. if (((size_t)ray) & 0x1F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 32 bytes");
  687. #endif
  688. STAT(size_t cnt=0; for (size_t i=0; i<8; i++) cnt += ((int*)valid)[i] == -1;);
  689. STAT3(shadow.travs,cnt,cnt,cnt);
  690. IntersectContext context(scene,user_context);
  691. #if !defined(EMBREE_RAY_PACKETS)
  692. RayHit8* ray8 = (RayHit8*) ray;
  693. for (size_t i=0; i<8; i++) {
  694. if (!valid[i]) continue;
  695. RayHit ray1; ray8->get(i,ray1);
  696. scene->intersectors.occluded((RTCRay&)ray1,&context);
  697. ray8->set(i,ray1);
  698. }
  699. #else
  700. if (likely(scene->intersectors.intersector8))
  701. scene->intersectors.occluded8(valid,*ray,&context);
  702. else
  703. scene->device->rayStreamFilters.occludedSOA(scene,(char*)ray,8,1,sizeof(RTCRay8),&context);
  704. #endif
  705. RTC_CATCH_END2(scene);
  706. }
  707. RTC_API void rtcOccluded16 (const int* valid, RTCScene hscene, RTCIntersectContext* user_context, RTCRay16* ray)
  708. {
  709. Scene* scene = (Scene*) hscene;
  710. RTC_CATCH_BEGIN;
  711. RTC_TRACE(rtcOccluded16);
  712. #if defined(DEBUG)
  713. RTC_VERIFY_HANDLE(hscene);
  714. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
  715. if (((size_t)valid) & 0x3F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "mask not aligned to 64 bytes");
  716. if (((size_t)ray) & 0x3F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 64 bytes");
  717. #endif
  718. STAT(size_t cnt=0; for (size_t i=0; i<16; i++) cnt += ((int*)valid)[i] == -1;);
  719. STAT3(shadow.travs,cnt,cnt,cnt);
  720. IntersectContext context(scene,user_context);
  721. #if !defined(EMBREE_RAY_PACKETS)
  722. RayHit16* ray16 = (RayHit16*) ray;
  723. for (size_t i=0; i<16; i++) {
  724. if (!valid[i]) continue;
  725. RayHit ray1; ray16->get(i,ray1);
  726. scene->intersectors.occluded((RTCRay&)ray1,&context);
  727. ray16->set(i,ray1);
  728. }
  729. #else
  730. if (likely(scene->intersectors.intersector16))
  731. scene->intersectors.occluded16(valid,*ray,&context);
  732. else
  733. scene->device->rayStreamFilters.occludedSOA(scene,(char*)ray,16,1,sizeof(RTCRay16),&context);
  734. #endif
  735. RTC_CATCH_END2(scene);
  736. }
  737. RTC_API void rtcOccluded1M(RTCScene hscene, RTCIntersectContext* user_context, RTCRay* ray, unsigned int M, size_t byteStride)
  738. {
  739. Scene* scene = (Scene*) hscene;
  740. RTC_CATCH_BEGIN;
  741. RTC_TRACE(rtcOccluded1M);
  742. #if defined (EMBREE_RAY_PACKETS)
  743. #if defined(DEBUG)
  744. RTC_VERIFY_HANDLE(hscene);
  745. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
  746. if (((size_t)ray) & 0x03) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 4 bytes");
  747. #endif
  748. STAT3(shadow.travs,M,M,M);
  749. IntersectContext context(scene,user_context);
  750. /* fast codepath for streams of size 1 */
  751. if (likely(M == 1)) {
  752. if (likely(ray->tnear <= ray->tfar))
  753. scene->intersectors.occluded (*ray,&context);
  754. }
  755. /* codepath for normal streams */
  756. else {
  757. scene->device->rayStreamFilters.occludedAOS(scene,ray,M,byteStride,&context);
  758. }
  759. #else
  760. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"rtcOccluded1M not supported");
  761. #endif
  762. RTC_CATCH_END2(scene);
  763. }
  764. RTC_API void rtcOccluded1Mp(RTCScene hscene, RTCIntersectContext* user_context, RTCRay** ray, unsigned int M)
  765. {
  766. Scene* scene = (Scene*) hscene;
  767. RTC_CATCH_BEGIN;
  768. RTC_TRACE(rtcOccluded1Mp);
  769. #if defined (EMBREE_RAY_PACKETS)
  770. #if defined(DEBUG)
  771. RTC_VERIFY_HANDLE(hscene);
  772. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
  773. if (((size_t)ray) & 0x03) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 4 bytes");
  774. #endif
  775. STAT3(shadow.travs,M,M,M);
  776. IntersectContext context(scene,user_context);
  777. /* fast codepath for streams of size 1 */
  778. if (likely(M == 1)) {
  779. if (likely(ray[0]->tnear <= ray[0]->tfar))
  780. scene->intersectors.occluded (*ray[0],&context);
  781. }
  782. /* codepath for normal streams */
  783. else {
  784. scene->device->rayStreamFilters.occludedAOP(scene,ray,M,&context);
  785. }
  786. #else
  787. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"rtcOccluded1Mp not supported");
  788. #endif
  789. RTC_CATCH_END2(scene);
  790. }
  791. RTC_API void rtcOccludedNM(RTCScene hscene, RTCIntersectContext* user_context, RTCRayN* ray, unsigned int N, unsigned int M, size_t byteStride)
  792. {
  793. Scene* scene = (Scene*) hscene;
  794. RTC_CATCH_BEGIN;
  795. RTC_TRACE(rtcOccludedNM);
  796. #if defined (EMBREE_RAY_PACKETS)
  797. #if defined(DEBUG)
  798. RTC_VERIFY_HANDLE(hscene);
  799. if (byteStride < sizeof(RTCRayHit)) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"byteStride too small");
  800. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
  801. if (((size_t)ray) & 0x03) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 4 bytes");
  802. #endif
  803. STAT3(shadow.travs,N*M,N*N,N*N);
  804. IntersectContext context(scene,user_context);
  805. /* codepath for single rays */
  806. if (likely(N == 1))
  807. {
  808. /* fast path for streams of size 1 */
  809. if (likely(M == 1)) {
  810. if (likely(((RTCRay*)ray)->tnear <= ((RTCRay*)ray)->tfar))
  811. scene->intersectors.occluded (*(RTCRay*)ray,&context);
  812. }
  813. /* codepath for normal ray streams */
  814. else {
  815. scene->device->rayStreamFilters.occludedAOS(scene,(RTCRay*)ray,M,byteStride,&context);
  816. }
  817. }
  818. /* code path for ray packet streams */
  819. else {
  820. scene->device->rayStreamFilters.occludedSOA(scene,(char*)ray,N,M,byteStride,&context);
  821. }
  822. #else
  823. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"rtcOccludedNM not supported");
  824. #endif
  825. RTC_CATCH_END2(scene);
  826. }
  827. RTC_API void rtcOccludedNp(RTCScene hscene, RTCIntersectContext* user_context, const RTCRayNp* ray, unsigned int N)
  828. {
  829. Scene* scene = (Scene*) hscene;
  830. RTC_CATCH_BEGIN;
  831. RTC_TRACE(rtcOccludedNp);
  832. #if defined (EMBREE_RAY_PACKETS)
  833. #if defined(DEBUG)
  834. RTC_VERIFY_HANDLE(hscene);
  835. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
  836. if (((size_t)ray->org_x ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "org_x not aligned to 4 bytes");
  837. if (((size_t)ray->org_y ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "org_y not aligned to 4 bytes");
  838. if (((size_t)ray->org_z ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "org_z not aligned to 4 bytes");
  839. if (((size_t)ray->dir_x ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "dir_x not aligned to 4 bytes");
  840. if (((size_t)ray->dir_y ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "dir_y not aligned to 4 bytes");
  841. if (((size_t)ray->dir_z ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "dir_z not aligned to 4 bytes");
  842. if (((size_t)ray->tnear ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "dir_x not aligned to 4 bytes");
  843. if (((size_t)ray->tfar ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "tnear not aligned to 4 bytes");
  844. if (((size_t)ray->time ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "time not aligned to 4 bytes");
  845. if (((size_t)ray->mask ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "mask not aligned to 4 bytes");
  846. #endif
  847. STAT3(shadow.travs,N,N,N);
  848. IntersectContext context(scene,user_context);
  849. scene->device->rayStreamFilters.occludedSOP(scene,ray,N,&context);
  850. #else
  851. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"rtcOccludedNp not supported");
  852. #endif
  853. RTC_CATCH_END2(scene);
  854. }
  855. RTC_API void rtcRetainScene (RTCScene hscene)
  856. {
  857. Scene* scene = (Scene*) hscene;
  858. RTC_CATCH_BEGIN;
  859. RTC_TRACE(rtcRetainScene);
  860. RTC_VERIFY_HANDLE(hscene);
  861. scene->refInc();
  862. RTC_CATCH_END2(scene);
  863. }
  864. RTC_API void rtcReleaseScene (RTCScene hscene)
  865. {
  866. Scene* scene = (Scene*) hscene;
  867. RTC_CATCH_BEGIN;
  868. RTC_TRACE(rtcReleaseScene);
  869. RTC_VERIFY_HANDLE(hscene);
  870. scene->refDec();
  871. RTC_CATCH_END2(scene);
  872. }
  873. RTC_API void rtcSetGeometryInstancedScene(RTCGeometry hgeometry, RTCScene hscene)
  874. {
  875. Geometry* geometry = (Geometry*) hgeometry;
  876. Ref<Scene> scene = (Scene*) hscene;
  877. RTC_CATCH_BEGIN;
  878. RTC_TRACE(rtcSetGeometryInstancedScene);
  879. RTC_VERIFY_HANDLE(hgeometry);
  880. RTC_VERIFY_HANDLE(hscene);
  881. geometry->setInstancedScene(scene);
  882. RTC_CATCH_END2(geometry);
  883. }
  884. AffineSpace3fa loadTransform(RTCFormat format, const float* xfm)
  885. {
  886. AffineSpace3fa space = one;
  887. switch (format)
  888. {
  889. case RTC_FORMAT_FLOAT3X4_ROW_MAJOR:
  890. space = AffineSpace3fa(Vec3fa(xfm[ 0], xfm[ 4], xfm[ 8]),
  891. Vec3fa(xfm[ 1], xfm[ 5], xfm[ 9]),
  892. Vec3fa(xfm[ 2], xfm[ 6], xfm[10]),
  893. Vec3fa(xfm[ 3], xfm[ 7], xfm[11]));
  894. break;
  895. case RTC_FORMAT_FLOAT3X4_COLUMN_MAJOR:
  896. space = AffineSpace3fa(Vec3fa(xfm[ 0], xfm[ 1], xfm[ 2]),
  897. Vec3fa(xfm[ 3], xfm[ 4], xfm[ 5]),
  898. Vec3fa(xfm[ 6], xfm[ 7], xfm[ 8]),
  899. Vec3fa(xfm[ 9], xfm[10], xfm[11]));
  900. break;
  901. case RTC_FORMAT_FLOAT4X4_COLUMN_MAJOR:
  902. space = AffineSpace3fa(Vec3fa(xfm[ 0], xfm[ 1], xfm[ 2]),
  903. Vec3fa(xfm[ 4], xfm[ 5], xfm[ 6]),
  904. Vec3fa(xfm[ 8], xfm[ 9], xfm[10]),
  905. Vec3fa(xfm[12], xfm[13], xfm[14]));
  906. break;
  907. default:
  908. throw_RTCError(RTC_ERROR_INVALID_OPERATION, "invalid matrix format");
  909. break;
  910. }
  911. return space;
  912. }
  913. void storeTransform(const AffineSpace3fa& space, RTCFormat format, float* xfm)
  914. {
  915. switch (format)
  916. {
  917. case RTC_FORMAT_FLOAT3X4_ROW_MAJOR:
  918. xfm[ 0] = space.l.vx.x; xfm[ 1] = space.l.vy.x; xfm[ 2] = space.l.vz.x; xfm[ 3] = space.p.x;
  919. xfm[ 4] = space.l.vx.y; xfm[ 5] = space.l.vy.y; xfm[ 6] = space.l.vz.y; xfm[ 7] = space.p.y;
  920. xfm[ 8] = space.l.vx.z; xfm[ 9] = space.l.vy.z; xfm[10] = space.l.vz.z; xfm[11] = space.p.z;
  921. break;
  922. case RTC_FORMAT_FLOAT3X4_COLUMN_MAJOR:
  923. xfm[ 0] = space.l.vx.x; xfm[ 1] = space.l.vx.y; xfm[ 2] = space.l.vx.z;
  924. xfm[ 3] = space.l.vy.x; xfm[ 4] = space.l.vy.y; xfm[ 5] = space.l.vy.z;
  925. xfm[ 6] = space.l.vz.x; xfm[ 7] = space.l.vz.y; xfm[ 8] = space.l.vz.z;
  926. xfm[ 9] = space.p.x; xfm[10] = space.p.y; xfm[11] = space.p.z;
  927. break;
  928. case RTC_FORMAT_FLOAT4X4_COLUMN_MAJOR:
  929. xfm[ 0] = space.l.vx.x; xfm[ 1] = space.l.vx.y; xfm[ 2] = space.l.vx.z; xfm[ 3] = 0.f;
  930. xfm[ 4] = space.l.vy.x; xfm[ 5] = space.l.vy.y; xfm[ 6] = space.l.vy.z; xfm[ 7] = 0.f;
  931. xfm[ 8] = space.l.vz.x; xfm[ 9] = space.l.vz.y; xfm[10] = space.l.vz.z; xfm[11] = 0.f;
  932. xfm[12] = space.p.x; xfm[13] = space.p.y; xfm[14] = space.p.z; xfm[15] = 1.f;
  933. break;
  934. default:
  935. throw_RTCError(RTC_ERROR_INVALID_OPERATION, "invalid matrix format");
  936. break;
  937. }
  938. }
  939. RTC_API void rtcSetGeometryTransform(RTCGeometry hgeometry, unsigned int timeStep, RTCFormat format, const void* xfm)
  940. {
  941. Geometry* geometry = (Geometry*) hgeometry;
  942. RTC_CATCH_BEGIN;
  943. RTC_TRACE(rtcSetGeometryTransform);
  944. RTC_VERIFY_HANDLE(hgeometry);
  945. RTC_VERIFY_HANDLE(xfm);
  946. const AffineSpace3fa transform = loadTransform(format, (const float*)xfm);
  947. geometry->setTransform(transform, timeStep);
  948. RTC_CATCH_END2(geometry);
  949. }
  950. RTC_API void rtcSetGeometryTransformQuaternion(RTCGeometry hgeometry, unsigned int timeStep, const RTCQuaternionDecomposition* qd)
  951. {
  952. Geometry* geometry = (Geometry*) hgeometry;
  953. RTC_CATCH_BEGIN;
  954. RTC_TRACE(rtcSetGeometryTransformQuaternion);
  955. RTC_VERIFY_HANDLE(hgeometry);
  956. RTC_VERIFY_HANDLE(qd);
  957. AffineSpace3fx transform;
  958. transform.l.vx.x = qd->scale_x;
  959. transform.l.vy.y = qd->scale_y;
  960. transform.l.vz.z = qd->scale_z;
  961. transform.l.vy.x = qd->skew_xy;
  962. transform.l.vz.x = qd->skew_xz;
  963. transform.l.vz.y = qd->skew_yz;
  964. transform.l.vx.y = qd->translation_x;
  965. transform.l.vx.z = qd->translation_y;
  966. transform.l.vy.z = qd->translation_z;
  967. transform.p.x = qd->shift_x;
  968. transform.p.y = qd->shift_y;
  969. transform.p.z = qd->shift_z;
  970. // normalize quaternion
  971. Quaternion3f q(qd->quaternion_r, qd->quaternion_i, qd->quaternion_j, qd->quaternion_k);
  972. q = normalize(q);
  973. transform.l.vx.w = q.i;
  974. transform.l.vy.w = q.j;
  975. transform.l.vz.w = q.k;
  976. transform.p.w = q.r;
  977. geometry->setQuaternionDecomposition(transform, timeStep);
  978. RTC_CATCH_END2(geometry);
  979. }
  980. RTC_API void rtcGetGeometryTransform(RTCGeometry hgeometry, float time, RTCFormat format, void* xfm)
  981. {
  982. Geometry* geometry = (Geometry*) hgeometry;
  983. RTC_CATCH_BEGIN;
  984. RTC_TRACE(rtcGetGeometryTransform);
  985. const AffineSpace3fa transform = geometry->getTransform(time);
  986. storeTransform(transform, format, (float*)xfm);
  987. RTC_CATCH_END2(geometry);
  988. }
  989. RTC_API void rtcFilterIntersection(const struct RTCIntersectFunctionNArguments* const args_i, const struct RTCFilterFunctionNArguments* filter_args)
  990. {
  991. IntersectFunctionNArguments* args = (IntersectFunctionNArguments*) args_i;
  992. isa::reportIntersection1(args, filter_args);
  993. }
  994. RTC_API void rtcFilterOcclusion(const struct RTCOccludedFunctionNArguments* const args_i, const struct RTCFilterFunctionNArguments* filter_args)
  995. {
  996. OccludedFunctionNArguments* args = (OccludedFunctionNArguments*) args_i;
  997. isa::reportOcclusion1(args,filter_args);
  998. }
  999. RTC_API RTCGeometry rtcNewGeometry (RTCDevice hdevice, RTCGeometryType type)
  1000. {
  1001. Device* device = (Device*) hdevice;
  1002. RTC_CATCH_BEGIN;
  1003. RTC_TRACE(rtcNewGeometry);
  1004. RTC_VERIFY_HANDLE(hdevice);
  1005. switch (type)
  1006. {
  1007. case RTC_GEOMETRY_TYPE_TRIANGLE:
  1008. {
  1009. #if defined(EMBREE_GEOMETRY_TRIANGLE)
  1010. createTriangleMeshTy createTriangleMesh = nullptr;
  1011. SELECT_SYMBOL_DEFAULT_AVX_AVX2_AVX512(device->enabled_cpu_features,createTriangleMesh);
  1012. Geometry* geom = createTriangleMesh(device);
  1013. return (RTCGeometry) geom->refInc();
  1014. #else
  1015. throw_RTCError(RTC_ERROR_UNKNOWN,"RTC_GEOMETRY_TYPE_TRIANGLE is not supported");
  1016. #endif
  1017. }
  1018. case RTC_GEOMETRY_TYPE_QUAD:
  1019. {
  1020. #if defined(EMBREE_GEOMETRY_QUAD)
  1021. createQuadMeshTy createQuadMesh = nullptr;
  1022. SELECT_SYMBOL_DEFAULT_AVX_AVX2_AVX512(device->enabled_cpu_features,createQuadMesh);
  1023. Geometry* geom = createQuadMesh(device);
  1024. return (RTCGeometry) geom->refInc();
  1025. #else
  1026. throw_RTCError(RTC_ERROR_UNKNOWN,"RTC_GEOMETRY_TYPE_QUAD is not supported");
  1027. #endif
  1028. }
  1029. case RTC_GEOMETRY_TYPE_SPHERE_POINT:
  1030. case RTC_GEOMETRY_TYPE_DISC_POINT:
  1031. case RTC_GEOMETRY_TYPE_ORIENTED_DISC_POINT:
  1032. {
  1033. #if defined(EMBREE_GEOMETRY_POINT)
  1034. createPointsTy createPoints = nullptr;
  1035. SELECT_SYMBOL_DEFAULT_AVX_AVX2_AVX512(device->enabled_builder_cpu_features, createPoints);
  1036. Geometry *geom;
  1037. switch(type) {
  1038. case RTC_GEOMETRY_TYPE_SPHERE_POINT:
  1039. geom = createPoints(device, Geometry::GTY_SPHERE_POINT);
  1040. break;
  1041. case RTC_GEOMETRY_TYPE_DISC_POINT:
  1042. geom = createPoints(device, Geometry::GTY_DISC_POINT);
  1043. break;
  1044. case RTC_GEOMETRY_TYPE_ORIENTED_DISC_POINT:
  1045. geom = createPoints(device, Geometry::GTY_ORIENTED_DISC_POINT);
  1046. break;
  1047. default:
  1048. geom = nullptr;
  1049. break;
  1050. }
  1051. return (RTCGeometry) geom->refInc();
  1052. #else
  1053. throw_RTCError(RTC_ERROR_UNKNOWN,"RTC_GEOMETRY_TYPE_POINT is not supported");
  1054. #endif
  1055. }
  1056. case RTC_GEOMETRY_TYPE_CONE_LINEAR_CURVE:
  1057. case RTC_GEOMETRY_TYPE_ROUND_LINEAR_CURVE:
  1058. case RTC_GEOMETRY_TYPE_FLAT_LINEAR_CURVE:
  1059. case RTC_GEOMETRY_TYPE_ROUND_BEZIER_CURVE:
  1060. case RTC_GEOMETRY_TYPE_FLAT_BEZIER_CURVE:
  1061. case RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_BEZIER_CURVE:
  1062. case RTC_GEOMETRY_TYPE_ROUND_BSPLINE_CURVE:
  1063. case RTC_GEOMETRY_TYPE_FLAT_BSPLINE_CURVE:
  1064. case RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_BSPLINE_CURVE:
  1065. case RTC_GEOMETRY_TYPE_ROUND_HERMITE_CURVE:
  1066. case RTC_GEOMETRY_TYPE_FLAT_HERMITE_CURVE:
  1067. case RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_HERMITE_CURVE:
  1068. case RTC_GEOMETRY_TYPE_ROUND_CATMULL_ROM_CURVE:
  1069. case RTC_GEOMETRY_TYPE_FLAT_CATMULL_ROM_CURVE:
  1070. case RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_CATMULL_ROM_CURVE:
  1071. {
  1072. #if defined(EMBREE_GEOMETRY_CURVE)
  1073. createLineSegmentsTy createLineSegments = nullptr;
  1074. SELECT_SYMBOL_DEFAULT_AVX_AVX2_AVX512(device->enabled_cpu_features,createLineSegments);
  1075. createCurvesTy createCurves = nullptr;
  1076. SELECT_SYMBOL_DEFAULT_AVX_AVX2_AVX512(device->enabled_cpu_features,createCurves);
  1077. Geometry* geom;
  1078. switch (type) {
  1079. case RTC_GEOMETRY_TYPE_CONE_LINEAR_CURVE : geom = createLineSegments (device,Geometry::GTY_CONE_LINEAR_CURVE); break;
  1080. case RTC_GEOMETRY_TYPE_ROUND_LINEAR_CURVE : geom = createLineSegments (device,Geometry::GTY_ROUND_LINEAR_CURVE); break;
  1081. case RTC_GEOMETRY_TYPE_FLAT_LINEAR_CURVE : geom = createLineSegments (device,Geometry::GTY_FLAT_LINEAR_CURVE); break;
  1082. //case RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_LINEAR_CURVE : geom = createLineSegments (device,Geometry::GTY_ORIENTED_LINEAR_CURVE); break;
  1083. case RTC_GEOMETRY_TYPE_ROUND_BEZIER_CURVE : geom = createCurves(device,Geometry::GTY_ROUND_BEZIER_CURVE); break;
  1084. case RTC_GEOMETRY_TYPE_FLAT_BEZIER_CURVE : geom = createCurves(device,Geometry::GTY_FLAT_BEZIER_CURVE); break;
  1085. case RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_BEZIER_CURVE : geom = createCurves(device,Geometry::GTY_ORIENTED_BEZIER_CURVE); break;
  1086. case RTC_GEOMETRY_TYPE_ROUND_BSPLINE_CURVE : geom = createCurves(device,Geometry::GTY_ROUND_BSPLINE_CURVE); break;
  1087. case RTC_GEOMETRY_TYPE_FLAT_BSPLINE_CURVE : geom = createCurves(device,Geometry::GTY_FLAT_BSPLINE_CURVE); break;
  1088. case RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_BSPLINE_CURVE : geom = createCurves(device,Geometry::GTY_ORIENTED_BSPLINE_CURVE); break;
  1089. case RTC_GEOMETRY_TYPE_ROUND_HERMITE_CURVE : geom = createCurves(device,Geometry::GTY_ROUND_HERMITE_CURVE); break;
  1090. case RTC_GEOMETRY_TYPE_FLAT_HERMITE_CURVE : geom = createCurves(device,Geometry::GTY_FLAT_HERMITE_CURVE); break;
  1091. case RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_HERMITE_CURVE : geom = createCurves(device,Geometry::GTY_ORIENTED_HERMITE_CURVE); break;
  1092. case RTC_GEOMETRY_TYPE_ROUND_CATMULL_ROM_CURVE : geom = createCurves(device,Geometry::GTY_ROUND_CATMULL_ROM_CURVE); break;
  1093. case RTC_GEOMETRY_TYPE_FLAT_CATMULL_ROM_CURVE : geom = createCurves(device,Geometry::GTY_FLAT_CATMULL_ROM_CURVE); break;
  1094. case RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_CATMULL_ROM_CURVE : geom = createCurves(device,Geometry::GTY_ORIENTED_CATMULL_ROM_CURVE); break;
  1095. default: geom = nullptr; break;
  1096. }
  1097. return (RTCGeometry) geom->refInc();
  1098. #else
  1099. throw_RTCError(RTC_ERROR_UNKNOWN,"RTC_GEOMETRY_TYPE_CURVE is not supported");
  1100. #endif
  1101. }
  1102. case RTC_GEOMETRY_TYPE_SUBDIVISION:
  1103. {
  1104. #if defined(EMBREE_GEOMETRY_SUBDIVISION)
  1105. createSubdivMeshTy createSubdivMesh = nullptr;
  1106. SELECT_SYMBOL_DEFAULT_AVX(device->enabled_cpu_features,createSubdivMesh);
  1107. //SELECT_SYMBOL_DEFAULT_AVX_AVX2_AVX512(device->enabled_cpu_features,createSubdivMesh); // FIXME: this does not work for some reason?
  1108. Geometry* geom = createSubdivMesh(device);
  1109. return (RTCGeometry) geom->refInc();
  1110. #else
  1111. throw_RTCError(RTC_ERROR_UNKNOWN,"RTC_GEOMETRY_TYPE_SUBDIVISION is not supported");
  1112. #endif
  1113. }
  1114. case RTC_GEOMETRY_TYPE_USER:
  1115. {
  1116. #if defined(EMBREE_GEOMETRY_USER)
  1117. createUserGeometryTy createUserGeometry = nullptr;
  1118. SELECT_SYMBOL_DEFAULT_AVX_AVX2_AVX512(device->enabled_cpu_features,createUserGeometry);
  1119. Geometry* geom = createUserGeometry(device);
  1120. return (RTCGeometry) geom->refInc();
  1121. #else
  1122. throw_RTCError(RTC_ERROR_UNKNOWN,"RTC_GEOMETRY_TYPE_USER is not supported");
  1123. #endif
  1124. }
  1125. case RTC_GEOMETRY_TYPE_INSTANCE:
  1126. {
  1127. #if defined(EMBREE_GEOMETRY_INSTANCE)
  1128. createInstanceTy createInstance = nullptr;
  1129. SELECT_SYMBOL_DEFAULT_AVX_AVX2_AVX512(device->enabled_cpu_features,createInstance);
  1130. Geometry* geom = createInstance(device);
  1131. return (RTCGeometry) geom->refInc();
  1132. #else
  1133. throw_RTCError(RTC_ERROR_UNKNOWN,"RTC_GEOMETRY_TYPE_INSTANCE is not supported");
  1134. #endif
  1135. }
  1136. case RTC_GEOMETRY_TYPE_GRID:
  1137. {
  1138. #if defined(EMBREE_GEOMETRY_GRID)
  1139. createGridMeshTy createGridMesh = nullptr;
  1140. SELECT_SYMBOL_DEFAULT_AVX_AVX2_AVX512(device->enabled_cpu_features,createGridMesh);
  1141. Geometry* geom = createGridMesh(device);
  1142. return (RTCGeometry) geom->refInc();
  1143. #else
  1144. throw_RTCError(RTC_ERROR_UNKNOWN,"RTC_GEOMETRY_TYPE_GRID is not supported");
  1145. #endif
  1146. }
  1147. default:
  1148. throw_RTCError(RTC_ERROR_UNKNOWN,"invalid geometry type");
  1149. }
  1150. RTC_CATCH_END(device);
  1151. return nullptr;
  1152. }
  1153. RTC_API void rtcSetGeometryUserPrimitiveCount(RTCGeometry hgeometry, unsigned int userPrimitiveCount)
  1154. {
  1155. Geometry* geometry = (Geometry*) hgeometry;
  1156. RTC_CATCH_BEGIN;
  1157. RTC_TRACE(rtcSetGeometryUserPrimitiveCount);
  1158. RTC_VERIFY_HANDLE(hgeometry);
  1159. if (unlikely(geometry->getType() != Geometry::GTY_USER_GEOMETRY))
  1160. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation only allowed for user geometries");
  1161. geometry->setNumPrimitives(userPrimitiveCount);
  1162. RTC_CATCH_END2(geometry);
  1163. }
  1164. RTC_API void rtcSetGeometryTimeStepCount(RTCGeometry hgeometry, unsigned int timeStepCount)
  1165. {
  1166. Geometry* geometry = (Geometry*) hgeometry;
  1167. RTC_CATCH_BEGIN;
  1168. RTC_TRACE(rtcSetGeometryTimeStepCount);
  1169. RTC_VERIFY_HANDLE(hgeometry);
  1170. if (timeStepCount > RTC_MAX_TIME_STEP_COUNT)
  1171. throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"number of time steps is out of range");
  1172. geometry->setNumTimeSteps(timeStepCount);
  1173. RTC_CATCH_END2(geometry);
  1174. }
  1175. RTC_API void rtcSetGeometryTimeRange(RTCGeometry hgeometry, float startTime, float endTime)
  1176. {
  1177. Ref<Geometry> geometry = (Geometry*) hgeometry;
  1178. RTC_CATCH_BEGIN;
  1179. RTC_TRACE(rtcSetGeometryTimeRange);
  1180. RTC_VERIFY_HANDLE(hgeometry);
  1181. if (startTime > endTime)
  1182. throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"startTime has to be smaller or equal to the endTime");
  1183. geometry->setTimeRange(BBox1f(startTime,endTime));
  1184. RTC_CATCH_END2(geometry);
  1185. }
  1186. RTC_API void rtcSetGeometryVertexAttributeCount(RTCGeometry hgeometry, unsigned int N)
  1187. {
  1188. Geometry* geometry = (Geometry*) hgeometry;
  1189. RTC_CATCH_BEGIN;
  1190. RTC_TRACE(rtcSetGeometryVertexAttributeCount);
  1191. RTC_VERIFY_HANDLE(hgeometry);
  1192. geometry->setVertexAttributeCount(N);
  1193. RTC_CATCH_END2(geometry);
  1194. }
  1195. RTC_API void rtcSetGeometryTopologyCount(RTCGeometry hgeometry, unsigned int N)
  1196. {
  1197. Geometry* geometry = (Geometry*) hgeometry;
  1198. RTC_CATCH_BEGIN;
  1199. RTC_TRACE(rtcSetGeometryTopologyCount);
  1200. RTC_VERIFY_HANDLE(hgeometry);
  1201. geometry->setTopologyCount(N);
  1202. RTC_CATCH_END2(geometry);
  1203. }
  1204. RTC_API void rtcSetGeometryBuildQuality (RTCGeometry hgeometry, RTCBuildQuality quality)
  1205. {
  1206. Geometry* geometry = (Geometry*) hgeometry;
  1207. RTC_CATCH_BEGIN;
  1208. RTC_TRACE(rtcSetGeometryBuildQuality);
  1209. RTC_VERIFY_HANDLE(hgeometry);
  1210. if (quality != RTC_BUILD_QUALITY_LOW &&
  1211. quality != RTC_BUILD_QUALITY_MEDIUM &&
  1212. quality != RTC_BUILD_QUALITY_HIGH &&
  1213. quality != RTC_BUILD_QUALITY_REFIT)
  1214. // -- GODOT start --
  1215. // throw std::runtime_error("invalid build quality");
  1216. abort();
  1217. // -- GODOT end --
  1218. geometry->setBuildQuality(quality);
  1219. RTC_CATCH_END2(geometry);
  1220. }
  1221. RTC_API void rtcSetGeometryMaxRadiusScale(RTCGeometry hgeometry, float maxRadiusScale)
  1222. {
  1223. Geometry* geometry = (Geometry*) hgeometry;
  1224. RTC_CATCH_BEGIN;
  1225. RTC_TRACE(rtcSetGeometryMaxRadiusScale);
  1226. RTC_VERIFY_HANDLE(hgeometry);
  1227. #if RTC_MIN_WIDTH
  1228. if (maxRadiusScale < 1.0f) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"maximal radius scale has to be larger or equal to 1");
  1229. geometry->setMaxRadiusScale(maxRadiusScale);
  1230. #else
  1231. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"min-width feature is not enabled");
  1232. #endif
  1233. RTC_CATCH_END2(geometry);
  1234. }
  1235. RTC_API void rtcSetGeometryMask (RTCGeometry hgeometry, unsigned int mask)
  1236. {
  1237. Geometry* geometry = (Geometry*) hgeometry;
  1238. RTC_CATCH_BEGIN;
  1239. RTC_TRACE(rtcSetGeometryMask);
  1240. RTC_VERIFY_HANDLE(hgeometry);
  1241. geometry->setMask(mask);
  1242. RTC_CATCH_END2(geometry);
  1243. }
  1244. RTC_API void rtcSetGeometrySubdivisionMode (RTCGeometry hgeometry, unsigned topologyID, RTCSubdivisionMode mode)
  1245. {
  1246. Geometry* geometry = (Geometry*) hgeometry;
  1247. RTC_CATCH_BEGIN;
  1248. RTC_TRACE(rtcSetGeometrySubdivisionMode);
  1249. RTC_VERIFY_HANDLE(hgeometry);
  1250. geometry->setSubdivisionMode(topologyID,mode);
  1251. RTC_CATCH_END2(geometry);
  1252. }
  1253. RTC_API void rtcSetGeometryVertexAttributeTopology(RTCGeometry hgeometry, unsigned int vertexAttributeID, unsigned int topologyID)
  1254. {
  1255. Geometry* geometry = (Geometry*) hgeometry;
  1256. RTC_CATCH_BEGIN;
  1257. RTC_TRACE(rtcSetGeometryVertexAttributeTopology);
  1258. RTC_VERIFY_HANDLE(hgeometry);
  1259. geometry->setVertexAttributeTopology(vertexAttributeID, topologyID);
  1260. RTC_CATCH_END2(geometry);
  1261. }
  1262. RTC_API void rtcSetGeometryBuffer(RTCGeometry hgeometry, RTCBufferType type, unsigned int slot, RTCFormat format, RTCBuffer hbuffer, size_t byteOffset, size_t byteStride, size_t itemCount)
  1263. {
  1264. Geometry* geometry = (Geometry*) hgeometry;
  1265. Ref<Buffer> buffer = (Buffer*)hbuffer;
  1266. RTC_CATCH_BEGIN;
  1267. RTC_TRACE(rtcSetGeometryBuffer);
  1268. RTC_VERIFY_HANDLE(hgeometry);
  1269. RTC_VERIFY_HANDLE(hbuffer);
  1270. if (geometry->device != buffer->device)
  1271. throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"inputs are from different devices");
  1272. if (itemCount > 0xFFFFFFFFu)
  1273. throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"buffer too large");
  1274. geometry->setBuffer(type, slot, format, buffer, byteOffset, byteStride, (unsigned int)itemCount);
  1275. RTC_CATCH_END2(geometry);
  1276. }
  1277. RTC_API void rtcSetSharedGeometryBuffer(RTCGeometry hgeometry, RTCBufferType type, unsigned int slot, RTCFormat format, const void* ptr, size_t byteOffset, size_t byteStride, size_t itemCount)
  1278. {
  1279. Geometry* geometry = (Geometry*) hgeometry;
  1280. RTC_CATCH_BEGIN;
  1281. RTC_TRACE(rtcSetSharedGeometryBuffer);
  1282. RTC_VERIFY_HANDLE(hgeometry);
  1283. if (itemCount > 0xFFFFFFFFu)
  1284. throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"buffer too large");
  1285. Ref<Buffer> buffer = new Buffer(geometry->device, itemCount*byteStride, (char*)ptr + byteOffset);
  1286. geometry->setBuffer(type, slot, format, buffer, 0, byteStride, (unsigned int)itemCount);
  1287. RTC_CATCH_END2(geometry);
  1288. }
  1289. RTC_API void* rtcSetNewGeometryBuffer(RTCGeometry hgeometry, RTCBufferType type, unsigned int slot, RTCFormat format, size_t byteStride, size_t itemCount)
  1290. {
  1291. Geometry* geometry = (Geometry*) hgeometry;
  1292. RTC_CATCH_BEGIN;
  1293. RTC_TRACE(rtcSetNewGeometryBuffer);
  1294. RTC_VERIFY_HANDLE(hgeometry);
  1295. if (itemCount > 0xFFFFFFFFu)
  1296. throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"buffer too large");
  1297. /* vertex buffers need to get overallocated slightly as elements are accessed using SSE loads */
  1298. size_t bytes = itemCount*byteStride;
  1299. if (type == RTC_BUFFER_TYPE_VERTEX || type == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE)
  1300. bytes += (16 - (byteStride%16))%16;
  1301. Ref<Buffer> buffer = new Buffer(geometry->device, bytes);
  1302. geometry->setBuffer(type, slot, format, buffer, 0, byteStride, (unsigned int)itemCount);
  1303. return buffer->data();
  1304. RTC_CATCH_END2(geometry);
  1305. return nullptr;
  1306. }
  1307. RTC_API void* rtcGetGeometryBufferData(RTCGeometry hgeometry, RTCBufferType type, unsigned int slot)
  1308. {
  1309. Geometry* geometry = (Geometry*) hgeometry;
  1310. RTC_CATCH_BEGIN;
  1311. RTC_TRACE(rtcGetGeometryBufferData);
  1312. RTC_VERIFY_HANDLE(hgeometry);
  1313. return geometry->getBuffer(type, slot);
  1314. RTC_CATCH_END2(geometry);
  1315. return nullptr;
  1316. }
  1317. RTC_API void rtcEnableGeometry (RTCGeometry hgeometry)
  1318. {
  1319. Geometry* geometry = (Geometry*) hgeometry;
  1320. RTC_CATCH_BEGIN;
  1321. RTC_TRACE(rtcEnableGeometry);
  1322. RTC_VERIFY_HANDLE(hgeometry);
  1323. geometry->enable();
  1324. RTC_CATCH_END2(geometry);
  1325. }
  1326. RTC_API void rtcUpdateGeometryBuffer (RTCGeometry hgeometry, RTCBufferType type, unsigned int slot)
  1327. {
  1328. Geometry* geometry = (Geometry*) hgeometry;
  1329. RTC_CATCH_BEGIN;
  1330. RTC_TRACE(rtcUpdateGeometryBuffer);
  1331. RTC_VERIFY_HANDLE(hgeometry);
  1332. geometry->updateBuffer(type, slot);
  1333. RTC_CATCH_END2(geometry);
  1334. }
  1335. RTC_API void rtcDisableGeometry (RTCGeometry hgeometry)
  1336. {
  1337. Geometry* geometry = (Geometry*) hgeometry;
  1338. RTC_CATCH_BEGIN;
  1339. RTC_TRACE(rtcDisableGeometry);
  1340. RTC_VERIFY_HANDLE(hgeometry);
  1341. geometry->disable();
  1342. RTC_CATCH_END2(geometry);
  1343. }
  1344. RTC_API void rtcSetGeometryTessellationRate (RTCGeometry hgeometry, float tessellationRate)
  1345. {
  1346. Geometry* geometry = (Geometry*) hgeometry;
  1347. RTC_CATCH_BEGIN;
  1348. RTC_TRACE(rtcSetGeometryTessellationRate);
  1349. RTC_VERIFY_HANDLE(hgeometry);
  1350. geometry->setTessellationRate(tessellationRate);
  1351. RTC_CATCH_END2(geometry);
  1352. }
  1353. RTC_API void rtcSetGeometryUserData (RTCGeometry hgeometry, void* ptr)
  1354. {
  1355. Geometry* geometry = (Geometry*) hgeometry;
  1356. RTC_CATCH_BEGIN;
  1357. RTC_TRACE(rtcSetGeometryUserData);
  1358. RTC_VERIFY_HANDLE(hgeometry);
  1359. geometry->setUserData(ptr);
  1360. RTC_CATCH_END2(geometry);
  1361. }
  1362. RTC_API void* rtcGetGeometryUserData (RTCGeometry hgeometry)
  1363. {
  1364. Geometry* geometry = (Geometry*) hgeometry; // no ref counting here!
  1365. RTC_CATCH_BEGIN;
  1366. RTC_TRACE(rtcGetGeometryUserData);
  1367. RTC_VERIFY_HANDLE(hgeometry);
  1368. return geometry->getUserData();
  1369. RTC_CATCH_END2(geometry);
  1370. return nullptr;
  1371. }
  1372. RTC_API void rtcSetGeometryBoundsFunction (RTCGeometry hgeometry, RTCBoundsFunction bounds, void* userPtr)
  1373. {
  1374. Geometry* geometry = (Geometry*) hgeometry;
  1375. RTC_CATCH_BEGIN;
  1376. RTC_TRACE(rtcSetGeometryBoundsFunction);
  1377. RTC_VERIFY_HANDLE(hgeometry);
  1378. geometry->setBoundsFunction(bounds,userPtr);
  1379. RTC_CATCH_END2(geometry);
  1380. }
  1381. RTC_API void rtcSetGeometryDisplacementFunction (RTCGeometry hgeometry, RTCDisplacementFunctionN displacement)
  1382. {
  1383. Geometry* geometry = (Geometry*) hgeometry;
  1384. RTC_CATCH_BEGIN;
  1385. RTC_TRACE(rtcSetGeometryDisplacementFunction);
  1386. RTC_VERIFY_HANDLE(hgeometry);
  1387. geometry->setDisplacementFunction(displacement);
  1388. RTC_CATCH_END2(geometry);
  1389. }
  1390. RTC_API void rtcSetGeometryIntersectFunction (RTCGeometry hgeometry, RTCIntersectFunctionN intersect)
  1391. {
  1392. Geometry* geometry = (Geometry*) hgeometry;
  1393. RTC_CATCH_BEGIN;
  1394. RTC_TRACE(rtcSetGeometryIntersectFunction);
  1395. RTC_VERIFY_HANDLE(hgeometry);
  1396. geometry->setIntersectFunctionN(intersect);
  1397. RTC_CATCH_END2(geometry);
  1398. }
  1399. RTC_API void rtcSetGeometryPointQueryFunction(RTCGeometry hgeometry, RTCPointQueryFunction pointQuery)
  1400. {
  1401. Geometry* geometry = (Geometry*) hgeometry;
  1402. RTC_CATCH_BEGIN;
  1403. RTC_TRACE(rtcSetGeometryPointQueryFunction);
  1404. RTC_VERIFY_HANDLE(hgeometry);
  1405. geometry->setPointQueryFunction(pointQuery);
  1406. RTC_CATCH_END2(geometry);
  1407. }
  1408. RTC_API unsigned int rtcGetGeometryFirstHalfEdge(RTCGeometry hgeometry, unsigned int faceID)
  1409. {
  1410. Geometry* geometry = (Geometry*) hgeometry;
  1411. RTC_CATCH_BEGIN;
  1412. RTC_TRACE(rtcGetGeometryFirstHalfEdge);
  1413. return geometry->getFirstHalfEdge(faceID);
  1414. RTC_CATCH_END2(geometry);
  1415. return -1;
  1416. }
  1417. RTC_API unsigned int rtcGetGeometryFace(RTCGeometry hgeometry, unsigned int edgeID)
  1418. {
  1419. Geometry* geometry = (Geometry*) hgeometry;
  1420. RTC_CATCH_BEGIN;
  1421. RTC_TRACE(rtcGetGeometryFace);
  1422. return geometry->getFace(edgeID);
  1423. RTC_CATCH_END2(geometry);
  1424. return -1;
  1425. }
  1426. RTC_API unsigned int rtcGetGeometryNextHalfEdge(RTCGeometry hgeometry, unsigned int edgeID)
  1427. {
  1428. Geometry* geometry = (Geometry*) hgeometry;
  1429. RTC_CATCH_BEGIN;
  1430. RTC_TRACE(rtcGetGeometryNextHalfEdge);
  1431. return geometry->getNextHalfEdge(edgeID);
  1432. RTC_CATCH_END2(geometry);
  1433. return -1;
  1434. }
  1435. RTC_API unsigned int rtcGetGeometryPreviousHalfEdge(RTCGeometry hgeometry, unsigned int edgeID)
  1436. {
  1437. Geometry* geometry = (Geometry*) hgeometry;
  1438. RTC_CATCH_BEGIN;
  1439. RTC_TRACE(rtcGetGeometryPreviousHalfEdge);
  1440. return geometry->getPreviousHalfEdge(edgeID);
  1441. RTC_CATCH_END2(geometry);
  1442. return -1;
  1443. }
  1444. RTC_API unsigned int rtcGetGeometryOppositeHalfEdge(RTCGeometry hgeometry, unsigned int topologyID, unsigned int edgeID)
  1445. {
  1446. Geometry* geometry = (Geometry*) hgeometry;
  1447. RTC_CATCH_BEGIN;
  1448. RTC_TRACE(rtcGetGeometryOppositeHalfEdge);
  1449. return geometry->getOppositeHalfEdge(topologyID,edgeID);
  1450. RTC_CATCH_END2(geometry);
  1451. return -1;
  1452. }
  1453. RTC_API void rtcSetGeometryOccludedFunction (RTCGeometry hgeometry, RTCOccludedFunctionN occluded)
  1454. {
  1455. Geometry* geometry = (Geometry*) hgeometry;
  1456. RTC_CATCH_BEGIN;
  1457. RTC_TRACE(rtcSetOccludedFunctionN);
  1458. RTC_VERIFY_HANDLE(hgeometry);
  1459. geometry->setOccludedFunctionN(occluded);
  1460. RTC_CATCH_END2(geometry);
  1461. }
  1462. RTC_API void rtcSetGeometryIntersectFilterFunction (RTCGeometry hgeometry, RTCFilterFunctionN filter)
  1463. {
  1464. Geometry* geometry = (Geometry*) hgeometry;
  1465. RTC_CATCH_BEGIN;
  1466. RTC_TRACE(rtcSetGeometryIntersectFilterFunction);
  1467. RTC_VERIFY_HANDLE(hgeometry);
  1468. geometry->setIntersectionFilterFunctionN(filter);
  1469. RTC_CATCH_END2(geometry);
  1470. }
  1471. RTC_API void rtcSetGeometryOccludedFilterFunction (RTCGeometry hgeometry, RTCFilterFunctionN filter)
  1472. {
  1473. Geometry* geometry = (Geometry*) hgeometry;
  1474. RTC_CATCH_BEGIN;
  1475. RTC_TRACE(rtcSetGeometryOccludedFilterFunction);
  1476. RTC_VERIFY_HANDLE(hgeometry);
  1477. geometry->setOcclusionFilterFunctionN(filter);
  1478. RTC_CATCH_END2(geometry);
  1479. }
  1480. RTC_API void rtcInterpolate(const RTCInterpolateArguments* const args)
  1481. {
  1482. Geometry* geometry = (Geometry*) args->geometry;
  1483. RTC_CATCH_BEGIN;
  1484. RTC_TRACE(rtcInterpolate);
  1485. #if defined(DEBUG)
  1486. RTC_VERIFY_HANDLE(args->geometry);
  1487. #endif
  1488. geometry->interpolate(args);
  1489. RTC_CATCH_END2(geometry);
  1490. }
  1491. RTC_API void rtcInterpolateN(const RTCInterpolateNArguments* const args)
  1492. {
  1493. Geometry* geometry = (Geometry*) args->geometry;
  1494. RTC_CATCH_BEGIN;
  1495. RTC_TRACE(rtcInterpolateN);
  1496. #if defined(DEBUG)
  1497. RTC_VERIFY_HANDLE(args->geometry);
  1498. #endif
  1499. geometry->interpolateN(args);
  1500. RTC_CATCH_END2(geometry);
  1501. }
  1502. RTC_API void rtcCommitGeometry (RTCGeometry hgeometry)
  1503. {
  1504. Geometry* geometry = (Geometry*) hgeometry;
  1505. RTC_CATCH_BEGIN;
  1506. RTC_TRACE(rtcCommitGeometry);
  1507. RTC_VERIFY_HANDLE(hgeometry);
  1508. return geometry->commit();
  1509. RTC_CATCH_END2(geometry);
  1510. }
  1511. RTC_API unsigned int rtcAttachGeometry (RTCScene hscene, RTCGeometry hgeometry)
  1512. {
  1513. Scene* scene = (Scene*) hscene;
  1514. Geometry* geometry = (Geometry*) hgeometry;
  1515. RTC_CATCH_BEGIN;
  1516. RTC_TRACE(rtcAttachGeometry);
  1517. RTC_VERIFY_HANDLE(hscene);
  1518. RTC_VERIFY_HANDLE(hgeometry);
  1519. if (scene->device != geometry->device)
  1520. throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"inputs are from different devices");
  1521. return scene->bind(RTC_INVALID_GEOMETRY_ID,geometry);
  1522. RTC_CATCH_END2(scene);
  1523. return -1;
  1524. }
  1525. RTC_API void rtcAttachGeometryByID (RTCScene hscene, RTCGeometry hgeometry, unsigned int geomID)
  1526. {
  1527. Scene* scene = (Scene*) hscene;
  1528. Geometry* geometry = (Geometry*) hgeometry;
  1529. RTC_CATCH_BEGIN;
  1530. RTC_TRACE(rtcAttachGeometryByID);
  1531. RTC_VERIFY_HANDLE(hscene);
  1532. RTC_VERIFY_HANDLE(hgeometry);
  1533. RTC_VERIFY_GEOMID(geomID);
  1534. if (scene->device != geometry->device)
  1535. throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"inputs are from different devices");
  1536. scene->bind(geomID,geometry);
  1537. RTC_CATCH_END2(scene);
  1538. }
  1539. RTC_API void rtcDetachGeometry (RTCScene hscene, unsigned int geomID)
  1540. {
  1541. Scene* scene = (Scene*) hscene;
  1542. RTC_CATCH_BEGIN;
  1543. RTC_TRACE(rtcDetachGeometry);
  1544. RTC_VERIFY_HANDLE(hscene);
  1545. RTC_VERIFY_GEOMID(geomID);
  1546. scene->detachGeometry(geomID);
  1547. RTC_CATCH_END2(scene);
  1548. }
  1549. RTC_API void rtcRetainGeometry (RTCGeometry hgeometry)
  1550. {
  1551. Geometry* geometry = (Geometry*) hgeometry;
  1552. RTC_CATCH_BEGIN;
  1553. RTC_TRACE(rtcRetainGeometry);
  1554. RTC_VERIFY_HANDLE(hgeometry);
  1555. geometry->refInc();
  1556. RTC_CATCH_END2(geometry);
  1557. }
  1558. RTC_API void rtcReleaseGeometry (RTCGeometry hgeometry)
  1559. {
  1560. Geometry* geometry = (Geometry*) hgeometry;
  1561. RTC_CATCH_BEGIN;
  1562. RTC_TRACE(rtcReleaseGeometry);
  1563. RTC_VERIFY_HANDLE(hgeometry);
  1564. geometry->refDec();
  1565. RTC_CATCH_END2(geometry);
  1566. }
  1567. RTC_API RTCGeometry rtcGetGeometry (RTCScene hscene, unsigned int geomID)
  1568. {
  1569. Scene* scene = (Scene*) hscene;
  1570. RTC_CATCH_BEGIN;
  1571. RTC_TRACE(rtcGetGeometry);
  1572. #if defined(DEBUG)
  1573. RTC_VERIFY_HANDLE(hscene);
  1574. RTC_VERIFY_GEOMID(geomID);
  1575. #endif
  1576. return (RTCGeometry) scene->get(geomID);
  1577. RTC_CATCH_END2(scene);
  1578. return nullptr;
  1579. }
  1580. RTC_API RTCGeometry rtcGetGeometryThreadSafe (RTCScene hscene, unsigned int geomID)
  1581. {
  1582. Scene* scene = (Scene*) hscene;
  1583. RTC_CATCH_BEGIN;
  1584. RTC_TRACE(rtcGetGeometryThreadSafe);
  1585. #if defined(DEBUG)
  1586. RTC_VERIFY_HANDLE(hscene);
  1587. RTC_VERIFY_GEOMID(geomID);
  1588. #endif
  1589. Ref<Geometry> geom = scene->get_locked(geomID);
  1590. return (RTCGeometry) geom.ptr;
  1591. RTC_CATCH_END2(scene);
  1592. return nullptr;
  1593. }
  1594. RTC_NAMESPACE_END