rtcore.cpp 64 KB

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