#pragma once
#include "rtcore_scene.h"
RTC_NAMESPACE_BEGIN
typedef struct RTCBVHTy* RTCBVH;
struct RTC_ALIGN(32) RTCBuildPrimitive
{
float lower_x, lower_y, lower_z;
unsigned int geomID;
float upper_x, upper_y, upper_z;
unsigned int primID;
};
typedef struct RTCThreadLocalAllocatorTy* RTCThreadLocalAllocator;
typedef void* (*RTCCreateNodeFunction) (RTCThreadLocalAllocator allocator, unsigned int childCount, void* userPtr);
typedef void (*RTCSetNodeChildrenFunction) (void* nodePtr, void** children, unsigned int childCount, void* userPtr);
typedef void (*RTCSetNodeBoundsFunction) (void* nodePtr, const struct RTCBounds** bounds, unsigned int childCount, void* userPtr);
typedef void* (*RTCCreateLeafFunction) (RTCThreadLocalAllocator allocator, const struct RTCBuildPrimitive* primitives, size_t primitiveCount, void* userPtr);
typedef void (*RTCSplitPrimitiveFunction) (const struct RTCBuildPrimitive* primitive, unsigned int dimension, float position, struct RTCBounds* leftBounds, struct RTCBounds* rightBounds, void* userPtr);
enum RTCBuildFlags
{
RTC_BUILD_FLAG_NONE = 0,
RTC_BUILD_FLAG_DYNAMIC = (1 << 0),
};
enum RTCBuildConstants
{
RTC_BUILD_MAX_PRIMITIVES_PER_LEAF = 32
};
struct RTCBuildArguments
{
size_t byteSize;
enum RTCBuildQuality buildQuality;
enum RTCBuildFlags buildFlags;
unsigned int maxBranchingFactor;
unsigned int maxDepth;
unsigned int sahBlockSize;
unsigned int minLeafSize;
unsigned int maxLeafSize;
float traversalCost;
float intersectionCost;
RTCBVH bvh;
struct RTCBuildPrimitive* primitives;
size_t primitiveCount;
size_t primitiveArrayCapacity;
RTCCreateNodeFunction createNode;
RTCSetNodeChildrenFunction setNodeChildren;
RTCSetNodeBoundsFunction setNodeBounds;
RTCCreateLeafFunction createLeaf;
RTCSplitPrimitiveFunction splitPrimitive;
RTCProgressMonitorFunction buildProgress;
void* userPtr;
};
RTC_FORCEINLINE struct RTCBuildArguments rtcDefaultBuildArguments()
{
struct RTCBuildArguments args;
args.byteSize = sizeof(args);
args.buildQuality = RTC_BUILD_QUALITY_MEDIUM;
args.buildFlags = RTC_BUILD_FLAG_NONE;
args.maxBranchingFactor = 2;
args.maxDepth = 32;
args.sahBlockSize = 1;
args.minLeafSize = 1;
args.maxLeafSize = RTC_BUILD_MAX_PRIMITIVES_PER_LEAF;
args.traversalCost = 1.0f;
args.intersectionCost = 1.0f;
args.bvh = NULL;
args.primitives = NULL;
args.primitiveCount = 0;
args.primitiveArrayCapacity = 0;
args.createNode = NULL;
args.setNodeChildren = NULL;
args.setNodeBounds = NULL;
args.createLeaf = NULL;
args.splitPrimitive = NULL;
args.buildProgress = NULL;
args.userPtr = NULL;
return args;
}
RTC_API RTCBVH rtcNewBVH(RTCDevice device);
RTC_API void* rtcBuildBVH(const struct RTCBuildArguments* args);
RTC_API void* rtcThreadLocalAlloc(RTCThreadLocalAllocator allocator, size_t bytes, size_t align);
RTC_API void rtcRetainBVH(RTCBVH bvh);
RTC_API void rtcReleaseBVH(RTCBVH bvh);
RTC_NAMESPACE_END