HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rtcore_common.h
Go to the documentation of this file.
1 // Copyright 2009-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 
4 #pragma once
5 
6 #include <stddef.h>
7 #include <sys/types.h>
8 #include <stdbool.h>
9 
10 #include "rtcore_config.h"
11 
13 
14 #if defined(_WIN32)
15 #if defined(_M_X64)
16 typedef long long ssize_t;
17 #else
18 typedef int ssize_t;
19 #endif
20 #endif
21 
22 #ifdef _WIN32
23 # define RTC_ALIGN(...) __declspec(align(__VA_ARGS__))
24 #else
25 # define RTC_ALIGN(...) __attribute__((aligned(__VA_ARGS__)))
26 #endif
27 
28 #if !defined (RTC_DEPRECATED)
29 #ifdef __GNUC__
30  #define RTC_DEPRECATED __attribute__((deprecated))
31 #elif defined(_MSC_VER)
32  #define RTC_DEPRECATED __declspec(deprecated)
33 #else
34  #define RTC_DEPRECATED
35 #endif
36 #endif
37 
38 #if defined(_WIN32)
39 # define RTC_FORCEINLINE __forceinline
40 #else
41 # define RTC_FORCEINLINE inline __attribute__((always_inline))
42 #endif
43 
44 /* Invalid geometry ID */
45 #define RTC_INVALID_GEOMETRY_ID ((unsigned int)-1)
46 
47 /* Maximum number of time steps */
48 #define RTC_MAX_TIME_STEP_COUNT 129
49 
50 /* Formats of buffers and other data structures */
52 {
54 
55  /* 8-bit unsigned integer */
56  RTC_FORMAT_UCHAR = 0x1001,
60 
61  /* 8-bit signed integer */
62  RTC_FORMAT_CHAR = 0x2001,
66 
67  /* 16-bit unsigned integer */
72 
73  /* 16-bit signed integer */
74  RTC_FORMAT_SHORT = 0x4001,
78 
79  /* 32-bit unsigned integer */
80  RTC_FORMAT_UINT = 0x5001,
84 
85  /* 32-bit signed integer */
86  RTC_FORMAT_INT = 0x6001,
90 
91  /* 64-bit unsigned integer */
96 
97  /* 64-bit signed integer */
98  RTC_FORMAT_LLONG = 0x8001,
102 
103  /* 32-bit float */
120 
121  /* 32-bit float matrix (row-major order) */
131 
132  /* 32-bit float matrix (column-major order) */
142 
143  /* special 12-byte format for grids */
145 };
146 
147 /* Build quality levels */
149 {
154 };
155 
156 /* Axis-aligned bounding box representation */
157 struct RTC_ALIGN(16) RTCBounds
158 {
159  float lower_x, lower_y, lower_z, align0;
160  float upper_x, upper_y, upper_z, align1;
161 };
162 
163 /* Linear axis-aligned bounding box representation */
164 struct RTC_ALIGN(16) RTCLinearBounds
165 {
166  struct RTCBounds bounds0;
167  struct RTCBounds bounds1;
168 };
169 
170 /* Intersection context flags */
172 {
174  RTC_INTERSECT_CONTEXT_FLAG_INCOHERENT = (0 << 0), // optimize for incoherent rays
175  RTC_INTERSECT_CONTEXT_FLAG_COHERENT = (1 << 0) // optimize for coherent rays
176 };
177 
178 /* Arguments for RTCFilterFunctionN */
180 {
181  int* valid;
184  struct RTCRayN* ray;
185  struct RTCHitN* hit;
186  unsigned int N;
187 };
188 
189 /* Filter callback function */
191 
192 /* Intersection context passed to intersect/occluded calls */
194 {
195  enum RTCIntersectContextFlags flags; // intersection flags
196  RTCFilterFunctionN filter; // filter function to execute
197 
198 #if RTC_MAX_INSTANCE_LEVEL_COUNT > 1
199  unsigned int instStackSize; // Number of instances currently on the stack.
200 #endif
201  unsigned int instID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // The current stack of instance ids.
202 
203 #if RTC_MIN_WIDTH
204  float minWidthDistanceFactor; // curve radius is set to this factor times distance to ray origin
205 #endif
206 };
207 
208 /* Initializes an intersection context. */
210 {
211  unsigned l = 0;
213  context->filter = NULL;
214 
215 #if RTC_MAX_INSTANCE_LEVEL_COUNT > 1
216  context->instStackSize = 0;
217 #endif
218  for (; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l)
219  context->instID[l] = RTC_INVALID_GEOMETRY_ID;
220 
221 #if RTC_MIN_WIDTH
222  context->minWidthDistanceFactor = 0.0f;
223 #endif
224 }
225 
226 /* Point query structure for closest point query */
227 struct RTC_ALIGN(16) RTCPointQuery
228 {
229  float x; // x coordinate of the query point
230  float y; // y coordinate of the query point
231  float z; // z coordinate of the query point
232  float time; // time of the point query
233  float radius; // radius of the point query
234 };
235 
236 /* Structure of a packet of 4 query points */
237 struct RTC_ALIGN(16) RTCPointQuery4
238 {
239  float x[4]; // x coordinate of the query point
240  float y[4]; // y coordinate of the query point
241  float z[4]; // z coordinate of the query point
242  float time[4]; // time of the point query
243  float radius[4]; // radius of the point query
244 };
245 
246 /* Structure of a packet of 8 query points */
247 struct RTC_ALIGN(32) RTCPointQuery8
248 {
249  float x[8]; // x coordinate of the query point
250  float y[8]; // y coordinate of the query point
251  float z[8]; // z coordinate of the query point
252  float time[8]; // time of the point query
253  float radius[8]; // radius ofr the point query
254 };
255 
256 /* Structure of a packet of 16 query points */
257 struct RTC_ALIGN(64) RTCPointQuery16
258 {
259  float x[16]; // x coordinate of the query point
260  float y[16]; // y coordinate of the query point
261  float z[16]; // z coordinate of the query point
262  float time[16]; // time of the point quey
263  float radius[16]; // radius of the point query
264 };
265 
266 struct RTCPointQueryN;
267 
268 struct RTC_ALIGN(16) RTCPointQueryContext
269 {
270  // accumulated 4x4 column major matrices from world space to instance space.
271  // undefined if size == 0.
272  float world2inst[RTC_MAX_INSTANCE_LEVEL_COUNT][16];
273 
274  // accumulated 4x4 column major matrices from instance space to world space.
275  // undefined if size == 0.
276  float inst2world[RTC_MAX_INSTANCE_LEVEL_COUNT][16];
277 
278  // instance ids.
279  unsigned int instID[RTC_MAX_INSTANCE_LEVEL_COUNT];
280 
281  // number of instances currently on the stack.
282  unsigned int instStackSize;
283 };
284 
285 /* Initializes an intersection context. */
286 RTC_FORCEINLINE void rtcInitPointQueryContext(struct RTCPointQueryContext* context)
287 {
288  context->instStackSize = 0;
289  context->instID[0] = RTC_INVALID_GEOMETRY_ID;
290 }
291 
292 struct RTC_ALIGN(16) RTCPointQueryFunctionArguments
293 {
294  // The (world space) query object that was passed as an argument of rtcPointQuery. The
295  // radius of the query can be decreased inside the callback to shrink the
296  // search domain. Increasing the radius or modifying the time or position of
297  // the query results in undefined behaviour.
298  struct RTCPointQuery* query;
299 
300  // Used for user input/output data. Will not be read or modified internally.
301  void* userPtr;
302 
303  // primitive and geometry ID of primitive
304  unsigned int primID;
305  unsigned int geomID;
306 
307  // the context with transformation and instance ID stack
308  struct RTCPointQueryContext* context;
309 
310  // If the current instance transform M (= context->world2inst[context->instStackSize])
311  // is a similarity matrix, i.e there is a constant factor similarityScale such that,
312  // for all x,y: dist(Mx, My) = similarityScale * dist(x, y),
313  // The similarity scale is 0, if the current instance transform is not a
314  // similarity transform and vice versa. The similarity scale allows to compute
315  // distance information in instance space and scale the distances into world
316  // space by dividing with the similarity scale, for example, to update the
317  // query radius. If the current instance transform is not a similarity
318  // transform (similarityScale = 0), the distance computation has to be
319  // performed in world space to ensure correctness. if there is no instance
320  // transform (context->instStackSize == 0), the similarity scale is 1.
321  float similarityScale;
322 };
323 
324 typedef bool (*RTCPointQueryFunction)(struct RTCPointQueryFunctionArguments* args);
325 
#define RTC_MIN_WIDTH
Definition: rtcore_config.h:15
GLenum query
Definition: glad.h:2772
void
Definition: png.h:1083
GT_API const UT_StringHolder time
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:848
GLint y
Definition: glcorearb.h:103
#define RTC_FORCEINLINE
Definition: rtcore_common.h:41
struct RTCIntersectContext * context
RTCBuildQuality
#define RTC_INVALID_GEOMETRY_ID
Definition: rtcore_common.h:45
#define RTC_ALIGN(...)
Definition: rtcore_common.h:25
enum RTCIntersectContextFlags flags
RTC_FORCEINLINE void rtcInitPointQueryContext(struct RTCPointQueryContext *context)
void(* RTCFilterFunctionN)(const struct RTCFilterFunctionNArguments *args)
RTCIntersectContextFlags
#define RTC_MAX_INSTANCE_LEVEL_COUNT
Definition: rtcore_config.h:12
GLint GLenum GLint x
Definition: glcorearb.h:409
#define RTC_NAMESPACE_END
Definition: rtcore_config.h:23
RTC_FORCEINLINE void rtcInitIntersectContext(struct RTCIntersectContext *context)
unsigned int instStackSize
**If you just want to fire and args
Definition: thread.h:609
unsigned int instID[RTC_MAX_INSTANCE_LEVEL_COUNT]
RTCFormat
Definition: rtcore_common.h:51
bool(* RTCPointQueryFunction)(struct RTCPointQueryFunctionArguments *args)
RTCFilterFunctionN filter
#define RTC_NAMESPACE_BEGIN
Definition: rtcore_config.h:22