rtcore_common.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. // ======================================================================== //
  2. // Copyright 2009-2018 Intel Corporation //
  3. // //
  4. // Licensed under the Apache License, Version 2.0 (the "License"); //
  5. // you may not use this file except in compliance with the License. //
  6. // You may obtain a copy of the License at //
  7. // //
  8. // http://www.apache.org/licenses/LICENSE-2.0 //
  9. // //
  10. // Unless required by applicable law or agreed to in writing, software //
  11. // distributed under the License is distributed on an "AS IS" BASIS, //
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
  13. // See the License for the specific language governing permissions and //
  14. // limitations under the License. //
  15. // ======================================================================== //
  16. #pragma once
  17. #include <stddef.h>
  18. #include <sys/types.h>
  19. #include <stdbool.h>
  20. #include "rtcore_version.h"
  21. RTC_NAMESPACE_BEGIN
  22. #if defined(_WIN32)
  23. #if defined(_M_X64)
  24. typedef long long ssize_t;
  25. #else
  26. typedef int ssize_t;
  27. #endif
  28. #endif
  29. #ifdef _WIN32
  30. # define RTC_ALIGN(...) __declspec(align(__VA_ARGS__))
  31. #else
  32. # define RTC_ALIGN(...) __attribute__((aligned(__VA_ARGS__)))
  33. #endif
  34. #if !defined (RTC_DEPRECATED)
  35. #ifdef __GNUC__
  36. #define RTC_DEPRECATED __attribute__((deprecated))
  37. #elif defined(_MSC_VER)
  38. #define RTC_DEPRECATED __declspec(deprecated)
  39. #else
  40. #define RTC_DEPRECATED
  41. #endif
  42. #endif
  43. #if defined(_WIN32)
  44. # define RTC_FORCEINLINE __forceinline
  45. #else
  46. # define RTC_FORCEINLINE inline __attribute__((always_inline))
  47. #endif
  48. /* Invalid geometry ID */
  49. #define RTC_INVALID_GEOMETRY_ID ((unsigned int)-1)
  50. /* Maximum number of time steps */
  51. #define RTC_MAX_TIME_STEP_COUNT 129
  52. /* Maximum number of instancing levels */
  53. #define RTC_MAX_INSTANCE_LEVEL_COUNT 1
  54. /* Formats of buffers and other data structures */
  55. enum RTCFormat
  56. {
  57. RTC_FORMAT_UNDEFINED = 0,
  58. /* 8-bit unsigned integer */
  59. RTC_FORMAT_UCHAR = 0x1001,
  60. RTC_FORMAT_UCHAR2,
  61. RTC_FORMAT_UCHAR3,
  62. RTC_FORMAT_UCHAR4,
  63. /* 8-bit signed integer */
  64. RTC_FORMAT_CHAR = 0x2001,
  65. RTC_FORMAT_CHAR2,
  66. RTC_FORMAT_CHAR3,
  67. RTC_FORMAT_CHAR4,
  68. /* 16-bit unsigned integer */
  69. RTC_FORMAT_USHORT = 0x3001,
  70. RTC_FORMAT_USHORT2,
  71. RTC_FORMAT_USHORT3,
  72. RTC_FORMAT_USHORT4,
  73. /* 16-bit signed integer */
  74. RTC_FORMAT_SHORT = 0x4001,
  75. RTC_FORMAT_SHORT2,
  76. RTC_FORMAT_SHORT3,
  77. RTC_FORMAT_SHORT4,
  78. /* 32-bit unsigned integer */
  79. RTC_FORMAT_UINT = 0x5001,
  80. RTC_FORMAT_UINT2,
  81. RTC_FORMAT_UINT3,
  82. RTC_FORMAT_UINT4,
  83. /* 32-bit signed integer */
  84. RTC_FORMAT_INT = 0x6001,
  85. RTC_FORMAT_INT2,
  86. RTC_FORMAT_INT3,
  87. RTC_FORMAT_INT4,
  88. /* 64-bit unsigned integer */
  89. RTC_FORMAT_ULLONG = 0x7001,
  90. RTC_FORMAT_ULLONG2,
  91. RTC_FORMAT_ULLONG3,
  92. RTC_FORMAT_ULLONG4,
  93. /* 64-bit signed integer */
  94. RTC_FORMAT_LLONG = 0x8001,
  95. RTC_FORMAT_LLONG2,
  96. RTC_FORMAT_LLONG3,
  97. RTC_FORMAT_LLONG4,
  98. /* 32-bit float */
  99. RTC_FORMAT_FLOAT = 0x9001,
  100. RTC_FORMAT_FLOAT2,
  101. RTC_FORMAT_FLOAT3,
  102. RTC_FORMAT_FLOAT4,
  103. RTC_FORMAT_FLOAT5,
  104. RTC_FORMAT_FLOAT6,
  105. RTC_FORMAT_FLOAT7,
  106. RTC_FORMAT_FLOAT8,
  107. RTC_FORMAT_FLOAT9,
  108. RTC_FORMAT_FLOAT10,
  109. RTC_FORMAT_FLOAT11,
  110. RTC_FORMAT_FLOAT12,
  111. RTC_FORMAT_FLOAT13,
  112. RTC_FORMAT_FLOAT14,
  113. RTC_FORMAT_FLOAT15,
  114. RTC_FORMAT_FLOAT16,
  115. /* 32-bit float matrix (row-major order) */
  116. RTC_FORMAT_FLOAT2X2_ROW_MAJOR = 0x9122,
  117. RTC_FORMAT_FLOAT2X3_ROW_MAJOR = 0x9123,
  118. RTC_FORMAT_FLOAT2X4_ROW_MAJOR = 0x9124,
  119. RTC_FORMAT_FLOAT3X2_ROW_MAJOR = 0x9132,
  120. RTC_FORMAT_FLOAT3X3_ROW_MAJOR = 0x9133,
  121. RTC_FORMAT_FLOAT3X4_ROW_MAJOR = 0x9134,
  122. RTC_FORMAT_FLOAT4X2_ROW_MAJOR = 0x9142,
  123. RTC_FORMAT_FLOAT4X3_ROW_MAJOR = 0x9143,
  124. RTC_FORMAT_FLOAT4X4_ROW_MAJOR = 0x9144,
  125. /* 32-bit float matrix (column-major order) */
  126. RTC_FORMAT_FLOAT2X2_COLUMN_MAJOR = 0x9222,
  127. RTC_FORMAT_FLOAT2X3_COLUMN_MAJOR = 0x9223,
  128. RTC_FORMAT_FLOAT2X4_COLUMN_MAJOR = 0x9224,
  129. RTC_FORMAT_FLOAT3X2_COLUMN_MAJOR = 0x9232,
  130. RTC_FORMAT_FLOAT3X3_COLUMN_MAJOR = 0x9233,
  131. RTC_FORMAT_FLOAT3X4_COLUMN_MAJOR = 0x9234,
  132. RTC_FORMAT_FLOAT4X2_COLUMN_MAJOR = 0x9242,
  133. RTC_FORMAT_FLOAT4X3_COLUMN_MAJOR = 0x9243,
  134. RTC_FORMAT_FLOAT4X4_COLUMN_MAJOR = 0x9244,
  135. /* special 12-byte format for grids */
  136. RTC_FORMAT_GRID = 0xA001
  137. };
  138. /* Build quality levels */
  139. enum RTCBuildQuality
  140. {
  141. RTC_BUILD_QUALITY_LOW = 0,
  142. RTC_BUILD_QUALITY_MEDIUM = 1,
  143. RTC_BUILD_QUALITY_HIGH = 2,
  144. RTC_BUILD_QUALITY_REFIT = 3,
  145. };
  146. /* Axis-aligned bounding box representation */
  147. struct RTC_ALIGN(16) RTCBounds
  148. {
  149. float lower_x, lower_y, lower_z, align0;
  150. float upper_x, upper_y, upper_z, align1;
  151. };
  152. /* Linear axis-aligned bounding box representation */
  153. struct RTC_ALIGN(16) RTCLinearBounds
  154. {
  155. struct RTCBounds bounds0;
  156. struct RTCBounds bounds1;
  157. };
  158. /* Intersection context flags */
  159. enum RTCIntersectContextFlags
  160. {
  161. RTC_INTERSECT_CONTEXT_FLAG_NONE = 0,
  162. RTC_INTERSECT_CONTEXT_FLAG_INCOHERENT = (0 << 0), // optimize for incoherent rays
  163. RTC_INTERSECT_CONTEXT_FLAG_COHERENT = (1 << 0) // optimize for coherent rays
  164. };
  165. /* Arguments for RTCFilterFunctionN */
  166. struct RTCFilterFunctionNArguments
  167. {
  168. int* valid;
  169. void* geometryUserPtr;
  170. const struct RTCIntersectContext* context;
  171. struct RTCRayN* ray;
  172. struct RTCHitN* hit;
  173. unsigned int N;
  174. };
  175. /* Filter callback function */
  176. typedef void (*RTCFilterFunctionN)(const struct RTCFilterFunctionNArguments* args);
  177. /* Intersection context passed to intersect/occluded calls */
  178. struct RTCIntersectContext
  179. {
  180. enum RTCIntersectContextFlags flags; // intersection flags
  181. RTCFilterFunctionN filter; // filter function to execute
  182. unsigned int instID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // will be set to geomID of instance when instance is entered
  183. };
  184. /* Initializes an intersection context. */
  185. RTC_FORCEINLINE void rtcInitIntersectContext(struct RTCIntersectContext* context)
  186. {
  187. context->flags = RTC_INTERSECT_CONTEXT_FLAG_INCOHERENT;
  188. context->filter = NULL;
  189. context->instID[0] = RTC_INVALID_GEOMETRY_ID;
  190. }
  191. RTC_NAMESPACE_END