1 | // Copyright 2009-2021 Intel Corporation |
2 | // SPDX-License-Identifier: Apache-2.0 |
3 | |
4 | #pragma once |
5 | |
6 | #include "rtcore_buffer.h" |
7 | #include "rtcore_quaternion.h" |
8 | |
9 | RTC_NAMESPACE_BEGIN |
10 | |
11 | /* Opaque scene type */ |
12 | typedef struct RTCSceneTy* RTCScene; |
13 | |
14 | /* Opaque geometry type */ |
15 | typedef struct RTCGeometryTy* RTCGeometry; |
16 | |
17 | /* Types of geometries */ |
18 | enum RTCGeometryType |
19 | { |
20 | RTC_GEOMETRY_TYPE_TRIANGLE = 0, // triangle mesh |
21 | RTC_GEOMETRY_TYPE_QUAD = 1, // quad (triangle pair) mesh |
22 | RTC_GEOMETRY_TYPE_GRID = 2, // grid mesh |
23 | |
24 | RTC_GEOMETRY_TYPE_SUBDIVISION = 8, // Catmull-Clark subdivision surface |
25 | |
26 | RTC_GEOMETRY_TYPE_CONE_LINEAR_CURVE = 15, // Cone linear curves - discontinuous at edge boundaries |
27 | RTC_GEOMETRY_TYPE_ROUND_LINEAR_CURVE = 16, // Round (rounded cone like) linear curves |
28 | RTC_GEOMETRY_TYPE_FLAT_LINEAR_CURVE = 17, // flat (ribbon-like) linear curves |
29 | |
30 | RTC_GEOMETRY_TYPE_ROUND_BEZIER_CURVE = 24, // round (tube-like) Bezier curves |
31 | RTC_GEOMETRY_TYPE_FLAT_BEZIER_CURVE = 25, // flat (ribbon-like) Bezier curves |
32 | RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_BEZIER_CURVE = 26, // flat normal-oriented Bezier curves |
33 | |
34 | RTC_GEOMETRY_TYPE_ROUND_BSPLINE_CURVE = 32, // round (tube-like) B-spline curves |
35 | RTC_GEOMETRY_TYPE_FLAT_BSPLINE_CURVE = 33, // flat (ribbon-like) B-spline curves |
36 | RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_BSPLINE_CURVE = 34, // flat normal-oriented B-spline curves |
37 | |
38 | RTC_GEOMETRY_TYPE_ROUND_HERMITE_CURVE = 40, // round (tube-like) Hermite curves |
39 | RTC_GEOMETRY_TYPE_FLAT_HERMITE_CURVE = 41, // flat (ribbon-like) Hermite curves |
40 | RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_HERMITE_CURVE = 42, // flat normal-oriented Hermite curves |
41 | |
42 | RTC_GEOMETRY_TYPE_SPHERE_POINT = 50, |
43 | RTC_GEOMETRY_TYPE_DISC_POINT = 51, |
44 | RTC_GEOMETRY_TYPE_ORIENTED_DISC_POINT = 52, |
45 | |
46 | RTC_GEOMETRY_TYPE_ROUND_CATMULL_ROM_CURVE = 58, // round (tube-like) Catmull-Rom curves |
47 | RTC_GEOMETRY_TYPE_FLAT_CATMULL_ROM_CURVE = 59, // flat (ribbon-like) Catmull-Rom curves |
48 | RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_CATMULL_ROM_CURVE = 60, // flat normal-oriented Catmull-Rom curves |
49 | |
50 | RTC_GEOMETRY_TYPE_USER = 120, // user-defined geometry |
51 | RTC_GEOMETRY_TYPE_INSTANCE = 121 // scene instance |
52 | }; |
53 | |
54 | /* Interpolation modes for subdivision surfaces */ |
55 | enum RTCSubdivisionMode |
56 | { |
57 | RTC_SUBDIVISION_MODE_NO_BOUNDARY = 0, |
58 | RTC_SUBDIVISION_MODE_SMOOTH_BOUNDARY = 1, |
59 | RTC_SUBDIVISION_MODE_PIN_CORNERS = 2, |
60 | RTC_SUBDIVISION_MODE_PIN_BOUNDARY = 3, |
61 | RTC_SUBDIVISION_MODE_PIN_ALL = 4, |
62 | }; |
63 | |
64 | /* Curve segment flags */ |
65 | enum RTCCurveFlags |
66 | { |
67 | RTC_CURVE_FLAG_NEIGHBOR_LEFT = (1 << 0), // left segments exists |
68 | RTC_CURVE_FLAG_NEIGHBOR_RIGHT = (1 << 1) // right segment exists |
69 | }; |
70 | |
71 | /* Arguments for RTCBoundsFunction */ |
72 | struct RTCBoundsFunctionArguments |
73 | { |
74 | void* geometryUserPtr; |
75 | unsigned int primID; |
76 | unsigned int timeStep; |
77 | struct RTCBounds* bounds_o; |
78 | }; |
79 | |
80 | /* Bounding callback function */ |
81 | typedef void (*RTCBoundsFunction)(const struct RTCBoundsFunctionArguments* args); |
82 | |
83 | /* Arguments for RTCIntersectFunctionN */ |
84 | struct RTCIntersectFunctionNArguments |
85 | { |
86 | int* valid; |
87 | void* geometryUserPtr; |
88 | unsigned int primID; |
89 | struct RTCIntersectContext* context; |
90 | struct RTCRayHitN* rayhit; |
91 | unsigned int N; |
92 | unsigned int geomID; |
93 | }; |
94 | |
95 | /* Intersection callback function */ |
96 | typedef void (*RTCIntersectFunctionN)(const struct RTCIntersectFunctionNArguments* args); |
97 | |
98 | /* Arguments for RTCOccludedFunctionN */ |
99 | struct RTCOccludedFunctionNArguments |
100 | { |
101 | int* valid; |
102 | void* geometryUserPtr; |
103 | unsigned int primID; |
104 | struct RTCIntersectContext* context; |
105 | struct RTCRayN* ray; |
106 | unsigned int N; |
107 | unsigned int geomID; |
108 | }; |
109 | |
110 | /* Occlusion callback function */ |
111 | typedef void (*RTCOccludedFunctionN)(const struct RTCOccludedFunctionNArguments* args); |
112 | |
113 | /* Arguments for RTCDisplacementFunctionN */ |
114 | struct RTCDisplacementFunctionNArguments |
115 | { |
116 | void* geometryUserPtr; |
117 | RTCGeometry geometry; |
118 | unsigned int primID; |
119 | unsigned int timeStep; |
120 | const float* u; |
121 | const float* v; |
122 | const float* Ng_x; |
123 | const float* Ng_y; |
124 | const float* Ng_z; |
125 | float* P_x; |
126 | float* P_y; |
127 | float* P_z; |
128 | unsigned int N; |
129 | }; |
130 | |
131 | /* Displacement mapping callback function */ |
132 | typedef void (*RTCDisplacementFunctionN)(const struct RTCDisplacementFunctionNArguments* args); |
133 | |
134 | /* Creates a new geometry of specified type. */ |
135 | RTC_API RTCGeometry rtcNewGeometry(RTCDevice device, enum RTCGeometryType type); |
136 | |
137 | /* Retains the geometry (increments the reference count). */ |
138 | RTC_API void rtcRetainGeometry(RTCGeometry geometry); |
139 | |
140 | /* Releases the geometry (decrements the reference count) */ |
141 | RTC_API void rtcReleaseGeometry(RTCGeometry geometry); |
142 | |
143 | /* Commits the geometry. */ |
144 | RTC_API void rtcCommitGeometry(RTCGeometry geometry); |
145 | |
146 | |
147 | /* Enables the geometry. */ |
148 | RTC_API void rtcEnableGeometry(RTCGeometry geometry); |
149 | |
150 | /* Disables the geometry. */ |
151 | RTC_API void rtcDisableGeometry(RTCGeometry geometry); |
152 | |
153 | |
154 | /* Sets the number of motion blur time steps of the geometry. */ |
155 | RTC_API void rtcSetGeometryTimeStepCount(RTCGeometry geometry, unsigned int timeStepCount); |
156 | |
157 | /* Sets the motion blur time range of the geometry. */ |
158 | RTC_API void rtcSetGeometryTimeRange(RTCGeometry geometry, float startTime, float endTime); |
159 | |
160 | /* Sets the number of vertex attributes of the geometry. */ |
161 | RTC_API void rtcSetGeometryVertexAttributeCount(RTCGeometry geometry, unsigned int vertexAttributeCount); |
162 | |
163 | /* Sets the ray mask of the geometry. */ |
164 | RTC_API void rtcSetGeometryMask(RTCGeometry geometry, unsigned int mask); |
165 | |
166 | /* Sets the build quality of the geometry. */ |
167 | RTC_API void rtcSetGeometryBuildQuality(RTCGeometry geometry, enum RTCBuildQuality quality); |
168 | |
169 | /* Sets the maximal curve or point radius scale allowed by min-width feature. */ |
170 | RTC_API void rtcSetGeometryMaxRadiusScale(RTCGeometry geometry, float maxRadiusScale); |
171 | |
172 | |
173 | /* Sets a geometry buffer. */ |
174 | RTC_API void rtcSetGeometryBuffer(RTCGeometry geometry, enum RTCBufferType type, unsigned int slot, enum RTCFormat format, RTCBuffer buffer, size_t byteOffset, size_t byteStride, size_t itemCount); |
175 | |
176 | /* Sets a shared geometry buffer. */ |
177 | RTC_API void rtcSetSharedGeometryBuffer(RTCGeometry geometry, enum RTCBufferType type, unsigned int slot, enum RTCFormat format, const void* ptr, size_t byteOffset, size_t byteStride, size_t itemCount); |
178 | |
179 | /* Creates and sets a new geometry buffer. */ |
180 | RTC_API void* rtcSetNewGeometryBuffer(RTCGeometry geometry, enum RTCBufferType type, unsigned int slot, enum RTCFormat format, size_t byteStride, size_t itemCount); |
181 | |
182 | /* Returns the pointer to the data of a buffer. */ |
183 | RTC_API void* rtcGetGeometryBufferData(RTCGeometry geometry, enum RTCBufferType type, unsigned int slot); |
184 | |
185 | /* Updates a geometry buffer. */ |
186 | RTC_API void rtcUpdateGeometryBuffer(RTCGeometry geometry, enum RTCBufferType type, unsigned int slot); |
187 | |
188 | |
189 | /* Sets the intersection filter callback function of the geometry. */ |
190 | RTC_API void rtcSetGeometryIntersectFilterFunction(RTCGeometry geometry, RTCFilterFunctionN filter); |
191 | |
192 | /* Sets the occlusion filter callback function of the geometry. */ |
193 | RTC_API void rtcSetGeometryOccludedFilterFunction(RTCGeometry geometry, RTCFilterFunctionN filter); |
194 | |
195 | /* Sets the user-defined data pointer of the geometry. */ |
196 | RTC_API void rtcSetGeometryUserData(RTCGeometry geometry, void* ptr); |
197 | |
198 | /* Gets the user-defined data pointer of the geometry. */ |
199 | RTC_API void* rtcGetGeometryUserData(RTCGeometry geometry); |
200 | |
201 | /* Set the point query callback function of a geometry. */ |
202 | RTC_API void rtcSetGeometryPointQueryFunction(RTCGeometry geometry, RTCPointQueryFunction pointQuery); |
203 | |
204 | /* Sets the number of primitives of a user geometry. */ |
205 | RTC_API void rtcSetGeometryUserPrimitiveCount(RTCGeometry geometry, unsigned int userPrimitiveCount); |
206 | |
207 | /* Sets the bounding callback function to calculate bounding boxes for user primitives. */ |
208 | RTC_API void rtcSetGeometryBoundsFunction(RTCGeometry geometry, RTCBoundsFunction bounds, void* userPtr); |
209 | |
210 | /* Set the intersect callback function of a user geometry. */ |
211 | RTC_API void rtcSetGeometryIntersectFunction(RTCGeometry geometry, RTCIntersectFunctionN intersect); |
212 | |
213 | /* Set the occlusion callback function of a user geometry. */ |
214 | RTC_API void rtcSetGeometryOccludedFunction(RTCGeometry geometry, RTCOccludedFunctionN occluded); |
215 | |
216 | /* Invokes the intersection filter from the intersection callback function. */ |
217 | RTC_API void rtcFilterIntersection(const struct RTCIntersectFunctionNArguments* args, const struct RTCFilterFunctionNArguments* filterArgs); |
218 | |
219 | /* Invokes the occlusion filter from the occlusion callback function. */ |
220 | RTC_API void rtcFilterOcclusion(const struct RTCOccludedFunctionNArguments* args, const struct RTCFilterFunctionNArguments* filterArgs); |
221 | |
222 | |
223 | /* Sets the instanced scene of an instance geometry. */ |
224 | RTC_API void rtcSetGeometryInstancedScene(RTCGeometry geometry, RTCScene scene); |
225 | |
226 | /* Sets the transformation of an instance for the specified time step. */ |
227 | RTC_API void rtcSetGeometryTransform(RTCGeometry geometry, unsigned int timeStep, enum RTCFormat format, const void* xfm); |
228 | |
229 | /* Sets the transformation quaternion of an instance for the specified time step. */ |
230 | RTC_API void rtcSetGeometryTransformQuaternion(RTCGeometry geometry, unsigned int timeStep, const struct RTCQuaternionDecomposition* qd); |
231 | |
232 | /* Returns the interpolated transformation of an instance for the specified time. */ |
233 | RTC_API void rtcGetGeometryTransform(RTCGeometry geometry, float time, enum RTCFormat format, void* xfm); |
234 | |
235 | |
236 | /* Sets the uniform tessellation rate of the geometry. */ |
237 | RTC_API void rtcSetGeometryTessellationRate(RTCGeometry geometry, float tessellationRate); |
238 | |
239 | /* Sets the number of topologies of a subdivision surface. */ |
240 | RTC_API void rtcSetGeometryTopologyCount(RTCGeometry geometry, unsigned int topologyCount); |
241 | |
242 | /* Sets the subdivision interpolation mode. */ |
243 | RTC_API void rtcSetGeometrySubdivisionMode(RTCGeometry geometry, unsigned int topologyID, enum RTCSubdivisionMode mode); |
244 | |
245 | /* Binds a vertex attribute to a topology of the geometry. */ |
246 | RTC_API void rtcSetGeometryVertexAttributeTopology(RTCGeometry geometry, unsigned int vertexAttributeID, unsigned int topologyID); |
247 | |
248 | /* Sets the displacement callback function of a subdivision surface. */ |
249 | RTC_API void rtcSetGeometryDisplacementFunction(RTCGeometry geometry, RTCDisplacementFunctionN displacement); |
250 | |
251 | /* Returns the first half edge of a face. */ |
252 | RTC_API unsigned int rtcGetGeometryFirstHalfEdge(RTCGeometry geometry, unsigned int faceID); |
253 | |
254 | /* Returns the face the half edge belongs to. */ |
255 | RTC_API unsigned int rtcGetGeometryFace(RTCGeometry geometry, unsigned int edgeID); |
256 | |
257 | /* Returns next half edge. */ |
258 | RTC_API unsigned int rtcGetGeometryNextHalfEdge(RTCGeometry geometry, unsigned int edgeID); |
259 | |
260 | /* Returns previous half edge. */ |
261 | RTC_API unsigned int rtcGetGeometryPreviousHalfEdge(RTCGeometry geometry, unsigned int edgeID); |
262 | |
263 | /* Returns opposite half edge. */ |
264 | RTC_API unsigned int rtcGetGeometryOppositeHalfEdge(RTCGeometry geometry, unsigned int topologyID, unsigned int edgeID); |
265 | |
266 | |
267 | /* Arguments for rtcInterpolate */ |
268 | struct RTCInterpolateArguments |
269 | { |
270 | RTCGeometry geometry; |
271 | unsigned int primID; |
272 | float u; |
273 | float v; |
274 | enum RTCBufferType bufferType; |
275 | unsigned int bufferSlot; |
276 | float* P; |
277 | float* dPdu; |
278 | float* dPdv; |
279 | float* ddPdudu; |
280 | float* ddPdvdv; |
281 | float* ddPdudv; |
282 | unsigned int valueCount; |
283 | }; |
284 | |
285 | /* Interpolates vertex data to some u/v location and optionally calculates all derivatives. */ |
286 | RTC_API void rtcInterpolate(const struct RTCInterpolateArguments* args); |
287 | |
288 | /* Interpolates vertex data to some u/v location. */ |
289 | RTC_FORCEINLINE void rtcInterpolate0(RTCGeometry geometry, unsigned int primID, float u, float v, enum RTCBufferType bufferType, unsigned int bufferSlot, float* P, unsigned int valueCount) |
290 | { |
291 | struct RTCInterpolateArguments args; |
292 | args.geometry = geometry; |
293 | args.primID = primID; |
294 | args.u = u; |
295 | args.v = v; |
296 | args.bufferType = bufferType; |
297 | args.bufferSlot = bufferSlot; |
298 | args.P = P; |
299 | args.dPdu = NULL; |
300 | args.dPdv = NULL; |
301 | args.ddPdudu = NULL; |
302 | args.ddPdvdv = NULL; |
303 | args.ddPdudv = NULL; |
304 | args.valueCount = valueCount; |
305 | rtcInterpolate(&args); |
306 | } |
307 | |
308 | /* Interpolates vertex data to some u/v location and calculates first order derivatives. */ |
309 | RTC_FORCEINLINE void rtcInterpolate1(RTCGeometry geometry, unsigned int primID, float u, float v, enum RTCBufferType bufferType, unsigned int bufferSlot, |
310 | float* P, float* dPdu, float* dPdv, unsigned int valueCount) |
311 | { |
312 | struct RTCInterpolateArguments args; |
313 | args.geometry = geometry; |
314 | args.primID = primID; |
315 | args.u = u; |
316 | args.v = v; |
317 | args.bufferType = bufferType; |
318 | args.bufferSlot = bufferSlot; |
319 | args.P = P; |
320 | args.dPdu = dPdu; |
321 | args.dPdv = dPdv; |
322 | args.ddPdudu = NULL; |
323 | args.ddPdvdv = NULL; |
324 | args.ddPdudv = NULL; |
325 | args.valueCount = valueCount; |
326 | rtcInterpolate(&args); |
327 | } |
328 | |
329 | /* Interpolates vertex data to some u/v location and calculates first and second order derivatives. */ |
330 | RTC_FORCEINLINE void rtcInterpolate2(RTCGeometry geometry, unsigned int primID, float u, float v, enum RTCBufferType bufferType, unsigned int bufferSlot, |
331 | float* P, float* dPdu, float* dPdv, float* ddPdudu, float* ddPdvdv, float* ddPdudv, unsigned int valueCount) |
332 | { |
333 | struct RTCInterpolateArguments args; |
334 | args.geometry = geometry; |
335 | args.primID = primID; |
336 | args.u = u; |
337 | args.v = v; |
338 | args.bufferType = bufferType; |
339 | args.bufferSlot = bufferSlot; |
340 | args.P = P; |
341 | args.dPdu = dPdu; |
342 | args.dPdv = dPdv; |
343 | args.ddPdudu = ddPdudu; |
344 | args.ddPdvdv = ddPdvdv; |
345 | args.ddPdudv = ddPdudv; |
346 | args.valueCount = valueCount; |
347 | rtcInterpolate(&args); |
348 | } |
349 | |
350 | /* Arguments for rtcInterpolateN */ |
351 | struct RTCInterpolateNArguments |
352 | { |
353 | RTCGeometry geometry; |
354 | const void* valid; |
355 | const unsigned int* primIDs; |
356 | const float* u; |
357 | const float* v; |
358 | unsigned int N; |
359 | enum RTCBufferType bufferType; |
360 | unsigned int bufferSlot; |
361 | float* P; |
362 | float* dPdu; |
363 | float* dPdv; |
364 | float* ddPdudu; |
365 | float* ddPdvdv; |
366 | float* ddPdudv; |
367 | unsigned int valueCount; |
368 | }; |
369 | |
370 | /* Interpolates vertex data to an array of u/v locations. */ |
371 | RTC_API void rtcInterpolateN(const struct RTCInterpolateNArguments* args); |
372 | |
373 | /* RTCGrid primitive for grid mesh */ |
374 | struct RTCGrid |
375 | { |
376 | unsigned int startVertexID; |
377 | unsigned int stride; |
378 | unsigned short width,height; // max is a 32k x 32k grid |
379 | }; |
380 | |
381 | RTC_NAMESPACE_END |
382 | |
383 | |
384 | |