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
12RTC_NAMESPACE_BEGIN
13
14#if defined(_WIN32)
15#if defined(_M_X64)
16typedef long long ssize_t;
17#else
18typedef int ssize_t;
19#endif
20#endif
21
22#if defined(_WIN32) && !defined(__MINGW32__)
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 */
51enum RTCFormat
52{
53 RTC_FORMAT_UNDEFINED = 0,
54
55 /* 8-bit unsigned integer */
56 RTC_FORMAT_UCHAR = 0x1001,
57 RTC_FORMAT_UCHAR2,
58 RTC_FORMAT_UCHAR3,
59 RTC_FORMAT_UCHAR4,
60
61 /* 8-bit signed integer */
62 RTC_FORMAT_CHAR = 0x2001,
63 RTC_FORMAT_CHAR2,
64 RTC_FORMAT_CHAR3,
65 RTC_FORMAT_CHAR4,
66
67 /* 16-bit unsigned integer */
68 RTC_FORMAT_USHORT = 0x3001,
69 RTC_FORMAT_USHORT2,
70 RTC_FORMAT_USHORT3,
71 RTC_FORMAT_USHORT4,
72
73 /* 16-bit signed integer */
74 RTC_FORMAT_SHORT = 0x4001,
75 RTC_FORMAT_SHORT2,
76 RTC_FORMAT_SHORT3,
77 RTC_FORMAT_SHORT4,
78
79 /* 32-bit unsigned integer */
80 RTC_FORMAT_UINT = 0x5001,
81 RTC_FORMAT_UINT2,
82 RTC_FORMAT_UINT3,
83 RTC_FORMAT_UINT4,
84
85 /* 32-bit signed integer */
86 RTC_FORMAT_INT = 0x6001,
87 RTC_FORMAT_INT2,
88 RTC_FORMAT_INT3,
89 RTC_FORMAT_INT4,
90
91 /* 64-bit unsigned integer */
92 RTC_FORMAT_ULLONG = 0x7001,
93 RTC_FORMAT_ULLONG2,
94 RTC_FORMAT_ULLONG3,
95 RTC_FORMAT_ULLONG4,
96
97 /* 64-bit signed integer */
98 RTC_FORMAT_LLONG = 0x8001,
99 RTC_FORMAT_LLONG2,
100 RTC_FORMAT_LLONG3,
101 RTC_FORMAT_LLONG4,
102
103 /* 32-bit float */
104 RTC_FORMAT_FLOAT = 0x9001,
105 RTC_FORMAT_FLOAT2,
106 RTC_FORMAT_FLOAT3,
107 RTC_FORMAT_FLOAT4,
108 RTC_FORMAT_FLOAT5,
109 RTC_FORMAT_FLOAT6,
110 RTC_FORMAT_FLOAT7,
111 RTC_FORMAT_FLOAT8,
112 RTC_FORMAT_FLOAT9,
113 RTC_FORMAT_FLOAT10,
114 RTC_FORMAT_FLOAT11,
115 RTC_FORMAT_FLOAT12,
116 RTC_FORMAT_FLOAT13,
117 RTC_FORMAT_FLOAT14,
118 RTC_FORMAT_FLOAT15,
119 RTC_FORMAT_FLOAT16,
120
121 /* 32-bit float matrix (row-major order) */
122 RTC_FORMAT_FLOAT2X2_ROW_MAJOR = 0x9122,
123 RTC_FORMAT_FLOAT2X3_ROW_MAJOR = 0x9123,
124 RTC_FORMAT_FLOAT2X4_ROW_MAJOR = 0x9124,
125 RTC_FORMAT_FLOAT3X2_ROW_MAJOR = 0x9132,
126 RTC_FORMAT_FLOAT3X3_ROW_MAJOR = 0x9133,
127 RTC_FORMAT_FLOAT3X4_ROW_MAJOR = 0x9134,
128 RTC_FORMAT_FLOAT4X2_ROW_MAJOR = 0x9142,
129 RTC_FORMAT_FLOAT4X3_ROW_MAJOR = 0x9143,
130 RTC_FORMAT_FLOAT4X4_ROW_MAJOR = 0x9144,
131
132 /* 32-bit float matrix (column-major order) */
133 RTC_FORMAT_FLOAT2X2_COLUMN_MAJOR = 0x9222,
134 RTC_FORMAT_FLOAT2X3_COLUMN_MAJOR = 0x9223,
135 RTC_FORMAT_FLOAT2X4_COLUMN_MAJOR = 0x9224,
136 RTC_FORMAT_FLOAT3X2_COLUMN_MAJOR = 0x9232,
137 RTC_FORMAT_FLOAT3X3_COLUMN_MAJOR = 0x9233,
138 RTC_FORMAT_FLOAT3X4_COLUMN_MAJOR = 0x9234,
139 RTC_FORMAT_FLOAT4X2_COLUMN_MAJOR = 0x9242,
140 RTC_FORMAT_FLOAT4X3_COLUMN_MAJOR = 0x9243,
141 RTC_FORMAT_FLOAT4X4_COLUMN_MAJOR = 0x9244,
142
143 /* special 12-byte format for grids */
144 RTC_FORMAT_GRID = 0xA001
145};
146
147/* Build quality levels */
148enum RTCBuildQuality
149{
150 RTC_BUILD_QUALITY_LOW = 0,
151 RTC_BUILD_QUALITY_MEDIUM = 1,
152 RTC_BUILD_QUALITY_HIGH = 2,
153 RTC_BUILD_QUALITY_REFIT = 3,
154};
155
156/* Axis-aligned bounding box representation */
157struct 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 */
164struct RTC_ALIGN(16) RTCLinearBounds
165{
166 struct RTCBounds bounds0;
167 struct RTCBounds bounds1;
168};
169
170/* Intersection context flags */
171enum RTCIntersectContextFlags
172{
173 RTC_INTERSECT_CONTEXT_FLAG_NONE = 0,
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 */
179struct RTCFilterFunctionNArguments
180{
181 int* valid;
182 void* geometryUserPtr;
183 struct RTCIntersectContext* context;
184 struct RTCRayN* ray;
185 struct RTCHitN* hit;
186 unsigned int N;
187};
188
189/* Filter callback function */
190typedef void (*RTCFilterFunctionN)(const struct RTCFilterFunctionNArguments* args);
191
192/* Intersection context passed to intersect/occluded calls */
193struct RTCIntersectContext
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. */
209RTC_FORCEINLINE void rtcInitIntersectContext(struct RTCIntersectContext* context)
210{
211 unsigned l = 0;
212 context->flags = RTC_INTERSECT_CONTEXT_FLAG_INCOHERENT;
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 */
227struct 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 */
237struct 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 */
247struct 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 */
257struct 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
266struct RTCPointQueryN;
267
268struct 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. */
286RTC_FORCEINLINE void rtcInitPointQueryContext(struct RTCPointQueryContext* context)
287{
288 context->instStackSize = 0;
289 context->instID[0] = RTC_INVALID_GEOMETRY_ID;
290}
291
292struct 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
324typedef bool (*RTCPointQueryFunction)(struct RTCPointQueryFunctionArguments* args);
325
326RTC_NAMESPACE_END
327

source code of qtquick3d/src/3rdparty/embree/include/embree3/rtcore_common.h