Path: blob/master/thirdparty/embree/include/embree4/rtcore_builder.h
9905 views
// Copyright 2009-2021 Intel Corporation1// SPDX-License-Identifier: Apache-2.023#pragma once45#include "rtcore_scene.h"67RTC_NAMESPACE_BEGIN89/* Opaque BVH type */10typedef struct RTCBVHTy* RTCBVH;1112/* Input build primitives for the builder */13struct RTC_ALIGN(32) RTCBuildPrimitive14{15float lower_x, lower_y, lower_z;16unsigned int geomID;17float upper_x, upper_y, upper_z;18unsigned int primID;19};2021/* Opaque thread local allocator type */22typedef struct RTCThreadLocalAllocatorTy* RTCThreadLocalAllocator;2324/* Callback to create a node */25typedef void* (*RTCCreateNodeFunction) (RTCThreadLocalAllocator allocator, unsigned int childCount, void* userPtr);2627/* Callback to set the pointer to all children */28typedef void (*RTCSetNodeChildrenFunction) (void* nodePtr, void** children, unsigned int childCount, void* userPtr);2930/* Callback to set the bounds of all children */31typedef void (*RTCSetNodeBoundsFunction) (void* nodePtr, const struct RTCBounds** bounds, unsigned int childCount, void* userPtr);3233/* Callback to create a leaf node */34typedef void* (*RTCCreateLeafFunction) (RTCThreadLocalAllocator allocator, const struct RTCBuildPrimitive* primitives, size_t primitiveCount, void* userPtr);3536/* Callback to split a build primitive */37typedef void (*RTCSplitPrimitiveFunction) (const struct RTCBuildPrimitive* primitive, unsigned int dimension, float position, struct RTCBounds* leftBounds, struct RTCBounds* rightBounds, void* userPtr);3839/* Build flags */40enum RTCBuildFlags41{42RTC_BUILD_FLAG_NONE = 0,43RTC_BUILD_FLAG_DYNAMIC = (1 << 0),44};4546enum RTCBuildConstants47{48RTC_BUILD_MAX_PRIMITIVES_PER_LEAF = 3249};5051/* Input for builders */52struct RTCBuildArguments53{54size_t byteSize;5556enum RTCBuildQuality buildQuality;57enum RTCBuildFlags buildFlags;58unsigned int maxBranchingFactor;59unsigned int maxDepth;60unsigned int sahBlockSize;61unsigned int minLeafSize;62unsigned int maxLeafSize;63float traversalCost;64float intersectionCost;6566RTCBVH bvh;67struct RTCBuildPrimitive* primitives;68size_t primitiveCount;69size_t primitiveArrayCapacity;7071RTCCreateNodeFunction createNode;72RTCSetNodeChildrenFunction setNodeChildren;73RTCSetNodeBoundsFunction setNodeBounds;74RTCCreateLeafFunction createLeaf;75RTCSplitPrimitiveFunction splitPrimitive;76RTCProgressMonitorFunction buildProgress;77void* userPtr;78};7980/* Returns the default build settings. */81RTC_FORCEINLINE struct RTCBuildArguments rtcDefaultBuildArguments()82{83struct RTCBuildArguments args;84args.byteSize = sizeof(args);85args.buildQuality = RTC_BUILD_QUALITY_MEDIUM;86args.buildFlags = RTC_BUILD_FLAG_NONE;87args.maxBranchingFactor = 2;88args.maxDepth = 32;89args.sahBlockSize = 1;90args.minLeafSize = 1;91args.maxLeafSize = RTC_BUILD_MAX_PRIMITIVES_PER_LEAF;92args.traversalCost = 1.0f;93args.intersectionCost = 1.0f;94args.bvh = NULL;95args.primitives = NULL;96args.primitiveCount = 0;97args.primitiveArrayCapacity = 0;98args.createNode = NULL;99args.setNodeChildren = NULL;100args.setNodeBounds = NULL;101args.createLeaf = NULL;102args.splitPrimitive = NULL;103args.buildProgress = NULL;104args.userPtr = NULL;105return args;106}107108/* Creates a new BVH. */109RTC_API RTCBVH rtcNewBVH(RTCDevice device);110111/* Builds a BVH. */112RTC_API void* rtcBuildBVH(const struct RTCBuildArguments* args);113114/* Allocates memory using the thread local allocator. */115RTC_API void* rtcThreadLocalAlloc(RTCThreadLocalAllocator allocator, size_t bytes, size_t align);116117/* Retains the BVH (increments reference count). */118RTC_API void rtcRetainBVH(RTCBVH bvh);119120/* Releases the BVH (decrements reference count). */121RTC_API void rtcReleaseBVH(RTCBVH bvh);122123RTC_NAMESPACE_END124125126127