rtcore_scene.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. // Copyright 2009-2021 Intel Corporation
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include "rtcore_device.h"
  5. RTC_NAMESPACE_BEGIN
  6. /* Forward declarations for ray structures */
  7. struct RTCRayHit;
  8. struct RTCRayHit4;
  9. struct RTCRayHit8;
  10. struct RTCRayHit16;
  11. /* Scene flags */
  12. enum RTCSceneFlags
  13. {
  14. RTC_SCENE_FLAG_NONE = 0,
  15. RTC_SCENE_FLAG_DYNAMIC = (1 << 0),
  16. RTC_SCENE_FLAG_COMPACT = (1 << 1),
  17. RTC_SCENE_FLAG_ROBUST = (1 << 2),
  18. RTC_SCENE_FLAG_FILTER_FUNCTION_IN_ARGUMENTS = (1 << 3)
  19. };
  20. /* Additional arguments for rtcIntersect1/4/8/16 calls */
  21. struct RTCIntersectArguments
  22. {
  23. enum RTCRayQueryFlags flags; // intersection flags
  24. enum RTCFeatureFlags feature_mask; // selectively enable features for traversal
  25. struct RTCRayQueryContext* context; // optional pointer to ray query context
  26. RTCFilterFunctionN filter; // filter function to execute
  27. RTCIntersectFunctionN intersect; // user geometry intersection callback to execute
  28. #if RTC_MIN_WIDTH
  29. float minWidthDistanceFactor; // curve radius is set to this factor times distance to ray origin
  30. #endif
  31. };
  32. /* Initializes intersection arguments. */
  33. RTC_FORCEINLINE void rtcInitIntersectArguments(struct RTCIntersectArguments* args)
  34. {
  35. args->flags = RTC_RAY_QUERY_FLAG_INCOHERENT;
  36. args->feature_mask = RTC_FEATURE_FLAG_ALL;
  37. args->context = NULL;
  38. args->filter = NULL;
  39. args->intersect = NULL;
  40. #if RTC_MIN_WIDTH
  41. args->minWidthDistanceFactor = 0.0f;
  42. #endif
  43. }
  44. /* Additional arguments for rtcOccluded1/4/8/16 calls */
  45. struct RTCOccludedArguments
  46. {
  47. enum RTCRayQueryFlags flags; // intersection flags
  48. enum RTCFeatureFlags feature_mask; // selectively enable features for traversal
  49. struct RTCRayQueryContext* context; // optional pointer to ray query context
  50. RTCFilterFunctionN filter; // filter function to execute
  51. RTCOccludedFunctionN occluded; // user geometry occlusion callback to execute
  52. #if RTC_MIN_WIDTH
  53. float minWidthDistanceFactor; // curve radius is set to this factor times distance to ray origin
  54. #endif
  55. };
  56. /* Initializes an intersection arguments. */
  57. RTC_FORCEINLINE void rtcInitOccludedArguments(struct RTCOccludedArguments* args)
  58. {
  59. args->flags = RTC_RAY_QUERY_FLAG_INCOHERENT;
  60. args->feature_mask = RTC_FEATURE_FLAG_ALL;
  61. args->context = NULL;
  62. args->filter = NULL;
  63. args->occluded = NULL;
  64. #if RTC_MIN_WIDTH
  65. args->minWidthDistanceFactor = 0.0f;
  66. #endif
  67. }
  68. /* Creates a new scene. */
  69. RTC_API RTCScene rtcNewScene(RTCDevice device);
  70. /* Returns the device the scene got created in. The reference count of
  71. * the device is incremented by this function. */
  72. RTC_API RTCDevice rtcGetSceneDevice(RTCScene hscene);
  73. /* Retains the scene (increments the reference count). */
  74. RTC_API void rtcRetainScene(RTCScene scene);
  75. /* Releases the scene (decrements the reference count). */
  76. RTC_API void rtcReleaseScene(RTCScene scene);
  77. /* Attaches the geometry to a scene. */
  78. RTC_API unsigned int rtcAttachGeometry(RTCScene scene, RTCGeometry geometry);
  79. /* Attaches the geometry to a scene using the specified geometry ID. */
  80. RTC_API void rtcAttachGeometryByID(RTCScene scene, RTCGeometry geometry, unsigned int geomID);
  81. /* Detaches the geometry from the scene. */
  82. RTC_API void rtcDetachGeometry(RTCScene scene, unsigned int geomID);
  83. /* Gets a geometry handle from the scene. This function is not thread safe and should get used during rendering. */
  84. RTC_API RTCGeometry rtcGetGeometry(RTCScene scene, unsigned int geomID);
  85. /* Gets a geometry handle from the scene. This function is thread safe and should NOT get used during rendering. */
  86. RTC_API RTCGeometry rtcGetGeometryThreadSafe(RTCScene scene, unsigned int geomID);
  87. /* Gets the user-defined data pointer of the geometry. This function is not thread safe and should get used during rendering. */
  88. RTC_SYCL_API void* rtcGetGeometryUserDataFromScene(RTCScene scene, unsigned int geomID);
  89. /* Returns the interpolated transformation of an instance for the specified time. */
  90. RTC_SYCL_API void rtcGetGeometryTransformFromScene(RTCScene scene, unsigned int geomID, float time, enum RTCFormat format, void* xfm);
  91. /* Commits the scene. */
  92. RTC_API void rtcCommitScene(RTCScene scene);
  93. /* Commits the scene from multiple threads. */
  94. RTC_API void rtcJoinCommitScene(RTCScene scene);
  95. /* Progress monitor callback function */
  96. typedef bool (*RTCProgressMonitorFunction)(void* ptr, double n);
  97. /* Sets the progress monitor callback function of the scene. */
  98. RTC_API void rtcSetSceneProgressMonitorFunction(RTCScene scene, RTCProgressMonitorFunction progress, void* ptr);
  99. /* Sets the build quality of the scene. */
  100. RTC_API void rtcSetSceneBuildQuality(RTCScene scene, enum RTCBuildQuality quality);
  101. /* Sets the scene flags. */
  102. RTC_API void rtcSetSceneFlags(RTCScene scene, enum RTCSceneFlags flags);
  103. /* Returns the scene flags. */
  104. RTC_API enum RTCSceneFlags rtcGetSceneFlags(RTCScene scene);
  105. /* Returns the axis-aligned bounds of the scene. */
  106. RTC_API void rtcGetSceneBounds(RTCScene scene, struct RTCBounds* bounds_o);
  107. /* Returns the linear axis-aligned bounds of the scene. */
  108. RTC_API void rtcGetSceneLinearBounds(RTCScene scene, struct RTCLinearBounds* bounds_o);
  109. /* Perform a closest point query of the scene. */
  110. RTC_API bool rtcPointQuery(RTCScene scene, struct RTCPointQuery* query, struct RTCPointQueryContext* context, RTCPointQueryFunction queryFunc, void* userPtr);
  111. /* Perform a closest point query with a packet of 4 points with the scene. */
  112. RTC_API bool rtcPointQuery4(const int* valid, RTCScene scene, struct RTCPointQuery4* query, struct RTCPointQueryContext* context, RTCPointQueryFunction queryFunc, void** userPtr);
  113. /* Perform a closest point query with a packet of 4 points with the scene. */
  114. RTC_API bool rtcPointQuery8(const int* valid, RTCScene scene, struct RTCPointQuery8* query, struct RTCPointQueryContext* context, RTCPointQueryFunction queryFunc, void** userPtr);
  115. /* Perform a closest point query with a packet of 4 points with the scene. */
  116. RTC_API bool rtcPointQuery16(const int* valid, RTCScene scene, struct RTCPointQuery16* query, struct RTCPointQueryContext* context, RTCPointQueryFunction queryFunc, void** userPtr);
  117. /* Intersects a single ray with the scene. */
  118. RTC_SYCL_API void rtcIntersect1(RTCScene scene, struct RTCRayHit* rayhit, struct RTCIntersectArguments* args RTC_OPTIONAL_ARGUMENT);
  119. /* Intersects a packet of 4 rays with the scene. */
  120. RTC_API void rtcIntersect4(const int* valid, RTCScene scene, struct RTCRayHit4* rayhit, struct RTCIntersectArguments* args RTC_OPTIONAL_ARGUMENT);
  121. /* Intersects a packet of 8 rays with the scene. */
  122. RTC_API void rtcIntersect8(const int* valid, RTCScene scene, struct RTCRayHit8* rayhit, struct RTCIntersectArguments* args RTC_OPTIONAL_ARGUMENT);
  123. /* Intersects a packet of 16 rays with the scene. */
  124. RTC_API void rtcIntersect16(const int* valid, RTCScene scene, struct RTCRayHit16* rayhit, struct RTCIntersectArguments* args RTC_OPTIONAL_ARGUMENT);
  125. /* Forwards ray inside user geometry callback. */
  126. RTC_SYCL_API void rtcForwardIntersect1(const struct RTCIntersectFunctionNArguments* args, RTCScene scene, struct RTCRay* ray, unsigned int instID);
  127. /* Forwards ray inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */
  128. RTC_SYCL_API void rtcForwardIntersect1Ex(const struct RTCIntersectFunctionNArguments* args, RTCScene scene, struct RTCRay* ray, unsigned int instID, unsigned int instPrimID);
  129. /* Forwards ray packet of size 4 inside user geometry callback. */
  130. RTC_API void rtcForwardIntersect4(const int* valid, const struct RTCIntersectFunctionNArguments* args, RTCScene scene, struct RTCRay4* ray, unsigned int instID);
  131. /* Forwards ray packet of size 4 inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */
  132. RTC_API void rtcForwardIntersect4Ex(const int* valid, const struct RTCIntersectFunctionNArguments* args, RTCScene scene, struct RTCRay4* ray, unsigned int instID, unsigned int primInstID);
  133. /* Forwards ray packet of size 8 inside user geometry callback. */
  134. RTC_API void rtcForwardIntersect8(const int* valid, const struct RTCIntersectFunctionNArguments* args, RTCScene scene, struct RTCRay8* ray, unsigned int instID);
  135. /* Forwards ray packet of size 4 inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */
  136. RTC_API void rtcForwardIntersect8Ex(const int* valid, const struct RTCIntersectFunctionNArguments* args, RTCScene scene, struct RTCRay8* ray, unsigned int instID, unsigned int primInstID);
  137. /* Forwards ray packet of size 16 inside user geometry callback. */
  138. RTC_API void rtcForwardIntersect16(const int* valid, const struct RTCIntersectFunctionNArguments* args, RTCScene scene, struct RTCRay16* ray, unsigned int instID);
  139. /* Forwards ray packet of size 4 inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */
  140. RTC_API void rtcForwardIntersect16Ex(const int* valid, const struct RTCIntersectFunctionNArguments* args, RTCScene scene, struct RTCRay16* ray, unsigned int instID, unsigned int primInstID);
  141. /* Tests a single ray for occlusion with the scene. */
  142. RTC_SYCL_API void rtcOccluded1(RTCScene scene, struct RTCRay* ray, struct RTCOccludedArguments* args RTC_OPTIONAL_ARGUMENT);
  143. /* Tests a packet of 4 rays for occlusion occluded with the scene. */
  144. RTC_API void rtcOccluded4(const int* valid, RTCScene scene, struct RTCRay4* ray, struct RTCOccludedArguments* args RTC_OPTIONAL_ARGUMENT);
  145. /* Tests a packet of 8 rays for occlusion with the scene. */
  146. RTC_API void rtcOccluded8(const int* valid, RTCScene scene, struct RTCRay8* ray, struct RTCOccludedArguments* args RTC_OPTIONAL_ARGUMENT);
  147. /* Tests a packet of 16 rays for occlusion with the scene. */
  148. RTC_API void rtcOccluded16(const int* valid, RTCScene scene, struct RTCRay16* ray, struct RTCOccludedArguments* args RTC_OPTIONAL_ARGUMENT);
  149. /* Forwards single occlusion ray inside user geometry callback. */
  150. RTC_SYCL_API void rtcForwardOccluded1(const struct RTCOccludedFunctionNArguments* args, RTCScene scene, struct RTCRay* ray, unsigned int instID);
  151. /* Forwards single occlusion ray inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */
  152. RTC_SYCL_API void rtcForwardOccluded1Ex(const struct RTCOccludedFunctionNArguments* args, RTCScene scene, struct RTCRay* ray, unsigned int instID, unsigned int instPrimID);
  153. /* Forwards occlusion ray packet of size 4 inside user geometry callback. */
  154. RTC_API void rtcForwardOccluded4(const int* valid, const struct RTCOccludedFunctionNArguments* args, RTCScene scene, struct RTCRay4* ray, unsigned int instID);
  155. /* Forwards occlusion ray packet of size 4 inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */
  156. RTC_API void rtcForwardOccluded4Ex(const int* valid, const struct RTCOccludedFunctionNArguments* args, RTCScene scene, struct RTCRay4* ray, unsigned int instID, unsigned int instPrimID);
  157. /* Forwards occlusion ray packet of size 8 inside user geometry callback. */
  158. RTC_API void rtcForwardOccluded8(const int* valid, const struct RTCOccludedFunctionNArguments* args, RTCScene scene, struct RTCRay8* ray, unsigned int instID);
  159. /* Forwards occlusion ray packet of size 8 inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */
  160. RTC_API void rtcForwardOccluded8Ex(const int* valid, const struct RTCOccludedFunctionNArguments* args, RTCScene scene, struct RTCRay8* ray, unsigned int instID, unsigned int instPrimID);
  161. /* Forwards occlusion ray packet of size 16 inside user geometry callback. */
  162. RTC_API void rtcForwardOccluded16(const int* valid, const struct RTCOccludedFunctionNArguments* args, RTCScene scene, struct RTCRay16* ray, unsigned int instID);
  163. /* Forwards occlusion ray packet of size 16 inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */
  164. RTC_API void rtcForwardOccluded16Ex(const int* valid, const struct RTCOccludedFunctionNArguments* args, RTCScene scene, struct RTCRay16* ray, unsigned int instID, unsigned int instPrimID);
  165. /*! collision callback */
  166. struct RTCCollision { unsigned int geomID0; unsigned int primID0; unsigned int geomID1; unsigned int primID1; };
  167. typedef void (*RTCCollideFunc) (void* userPtr, struct RTCCollision* collisions, unsigned int num_collisions);
  168. /*! Performs collision detection of two scenes */
  169. RTC_API void rtcCollide (RTCScene scene0, RTCScene scene1, RTCCollideFunc callback, void* userPtr);
  170. #if defined(__cplusplus)
  171. /* Helper for easily combining scene flags */
  172. inline RTCSceneFlags operator|(RTCSceneFlags a, RTCSceneFlags b) {
  173. return (RTCSceneFlags)((size_t)a | (size_t)b);
  174. }
  175. #endif
  176. RTC_NAMESPACE_END