Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/embree/include/embree4/rtcore_builder.h
9905 views
1
// Copyright 2009-2021 Intel Corporation
2
// SPDX-License-Identifier: Apache-2.0
3
4
#pragma once
5
6
#include "rtcore_scene.h"
7
8
RTC_NAMESPACE_BEGIN
9
10
/* Opaque BVH type */
11
typedef struct RTCBVHTy* RTCBVH;
12
13
/* Input build primitives for the builder */
14
struct RTC_ALIGN(32) RTCBuildPrimitive
15
{
16
float lower_x, lower_y, lower_z;
17
unsigned int geomID;
18
float upper_x, upper_y, upper_z;
19
unsigned int primID;
20
};
21
22
/* Opaque thread local allocator type */
23
typedef struct RTCThreadLocalAllocatorTy* RTCThreadLocalAllocator;
24
25
/* Callback to create a node */
26
typedef void* (*RTCCreateNodeFunction) (RTCThreadLocalAllocator allocator, unsigned int childCount, void* userPtr);
27
28
/* Callback to set the pointer to all children */
29
typedef void (*RTCSetNodeChildrenFunction) (void* nodePtr, void** children, unsigned int childCount, void* userPtr);
30
31
/* Callback to set the bounds of all children */
32
typedef void (*RTCSetNodeBoundsFunction) (void* nodePtr, const struct RTCBounds** bounds, unsigned int childCount, void* userPtr);
33
34
/* Callback to create a leaf node */
35
typedef void* (*RTCCreateLeafFunction) (RTCThreadLocalAllocator allocator, const struct RTCBuildPrimitive* primitives, size_t primitiveCount, void* userPtr);
36
37
/* Callback to split a build primitive */
38
typedef void (*RTCSplitPrimitiveFunction) (const struct RTCBuildPrimitive* primitive, unsigned int dimension, float position, struct RTCBounds* leftBounds, struct RTCBounds* rightBounds, void* userPtr);
39
40
/* Build flags */
41
enum RTCBuildFlags
42
{
43
RTC_BUILD_FLAG_NONE = 0,
44
RTC_BUILD_FLAG_DYNAMIC = (1 << 0),
45
};
46
47
enum RTCBuildConstants
48
{
49
RTC_BUILD_MAX_PRIMITIVES_PER_LEAF = 32
50
};
51
52
/* Input for builders */
53
struct RTCBuildArguments
54
{
55
size_t byteSize;
56
57
enum RTCBuildQuality buildQuality;
58
enum RTCBuildFlags buildFlags;
59
unsigned int maxBranchingFactor;
60
unsigned int maxDepth;
61
unsigned int sahBlockSize;
62
unsigned int minLeafSize;
63
unsigned int maxLeafSize;
64
float traversalCost;
65
float intersectionCost;
66
67
RTCBVH bvh;
68
struct RTCBuildPrimitive* primitives;
69
size_t primitiveCount;
70
size_t primitiveArrayCapacity;
71
72
RTCCreateNodeFunction createNode;
73
RTCSetNodeChildrenFunction setNodeChildren;
74
RTCSetNodeBoundsFunction setNodeBounds;
75
RTCCreateLeafFunction createLeaf;
76
RTCSplitPrimitiveFunction splitPrimitive;
77
RTCProgressMonitorFunction buildProgress;
78
void* userPtr;
79
};
80
81
/* Returns the default build settings. */
82
RTC_FORCEINLINE struct RTCBuildArguments rtcDefaultBuildArguments()
83
{
84
struct RTCBuildArguments args;
85
args.byteSize = sizeof(args);
86
args.buildQuality = RTC_BUILD_QUALITY_MEDIUM;
87
args.buildFlags = RTC_BUILD_FLAG_NONE;
88
args.maxBranchingFactor = 2;
89
args.maxDepth = 32;
90
args.sahBlockSize = 1;
91
args.minLeafSize = 1;
92
args.maxLeafSize = RTC_BUILD_MAX_PRIMITIVES_PER_LEAF;
93
args.traversalCost = 1.0f;
94
args.intersectionCost = 1.0f;
95
args.bvh = NULL;
96
args.primitives = NULL;
97
args.primitiveCount = 0;
98
args.primitiveArrayCapacity = 0;
99
args.createNode = NULL;
100
args.setNodeChildren = NULL;
101
args.setNodeBounds = NULL;
102
args.createLeaf = NULL;
103
args.splitPrimitive = NULL;
104
args.buildProgress = NULL;
105
args.userPtr = NULL;
106
return args;
107
}
108
109
/* Creates a new BVH. */
110
RTC_API RTCBVH rtcNewBVH(RTCDevice device);
111
112
/* Builds a BVH. */
113
RTC_API void* rtcBuildBVH(const struct RTCBuildArguments* args);
114
115
/* Allocates memory using the thread local allocator. */
116
RTC_API void* rtcThreadLocalAlloc(RTCThreadLocalAllocator allocator, size_t bytes, size_t align);
117
118
/* Retains the BVH (increments reference count). */
119
RTC_API void rtcRetainBVH(RTCBVH bvh);
120
121
/* Releases the BVH (decrements reference count). */
122
RTC_API void rtcReleaseBVH(RTCBVH bvh);
123
124
RTC_NAMESPACE_END
125
126
127