rtcore_builder.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // ======================================================================== //
  2. // Copyright 2009-2018 Intel Corporation //
  3. // //
  4. // Licensed under the Apache License, Version 2.0 (the "License"); //
  5. // you may not use this file except in compliance with the License. //
  6. // You may obtain a copy of the License at //
  7. // //
  8. // http://www.apache.org/licenses/LICENSE-2.0 //
  9. // //
  10. // Unless required by applicable law or agreed to in writing, software //
  11. // distributed under the License is distributed on an "AS IS" BASIS, //
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
  13. // See the License for the specific language governing permissions and //
  14. // limitations under the License. //
  15. // ======================================================================== //
  16. #pragma once
  17. #include "rtcore_scene.h"
  18. RTC_NAMESPACE_BEGIN
  19. /* Opaque BVH type */
  20. typedef struct RTCBVHTy* RTCBVH;
  21. /* Input build primitives for the builder */
  22. struct RTC_ALIGN(32) RTCBuildPrimitive
  23. {
  24. float lower_x, lower_y, lower_z;
  25. unsigned int geomID;
  26. float upper_x, upper_y, upper_z;
  27. unsigned int primID;
  28. };
  29. /* Opaque thread local allocator type */
  30. typedef struct RTCThreadLocalAllocatorTy* RTCThreadLocalAllocator;
  31. /* Callback to create a node */
  32. typedef void* (*RTCCreateNodeFunction) (RTCThreadLocalAllocator allocator, unsigned int childCount, void* userPtr);
  33. /* Callback to set the pointer to all children */
  34. typedef void (*RTCSetNodeChildrenFunction) (void* nodePtr, void** children, unsigned int childCount, void* userPtr);
  35. /* Callback to set the bounds of all children */
  36. typedef void (*RTCSetNodeBoundsFunction) (void* nodePtr, const struct RTCBounds** bounds, unsigned int childCount, void* userPtr);
  37. /* Callback to create a leaf node */
  38. typedef void* (*RTCCreateLeafFunction) (RTCThreadLocalAllocator allocator, const struct RTCBuildPrimitive* primitives, size_t primitiveCount, void* userPtr);
  39. /* Callback to split a build primitive */
  40. typedef void (*RTCSplitPrimitiveFunction) (const struct RTCBuildPrimitive* primitive, unsigned int dimension, float position, struct RTCBounds* leftBounds, struct RTCBounds* rightBounds, void* userPtr);
  41. /* Build flags */
  42. enum RTCBuildFlags
  43. {
  44. RTC_BUILD_FLAG_NONE = 0,
  45. RTC_BUILD_FLAG_DYNAMIC = (1 << 0),
  46. };
  47. /* Input for builders */
  48. struct RTCBuildArguments
  49. {
  50. size_t byteSize;
  51. enum RTCBuildQuality buildQuality;
  52. enum RTCBuildFlags buildFlags;
  53. unsigned int maxBranchingFactor;
  54. unsigned int maxDepth;
  55. unsigned int sahBlockSize;
  56. unsigned int minLeafSize;
  57. unsigned int maxLeafSize;
  58. float traversalCost;
  59. float intersectionCost;
  60. RTCBVH bvh;
  61. struct RTCBuildPrimitive* primitives;
  62. size_t primitiveCount;
  63. size_t primitiveArrayCapacity;
  64. RTCCreateNodeFunction createNode;
  65. RTCSetNodeChildrenFunction setNodeChildren;
  66. RTCSetNodeBoundsFunction setNodeBounds;
  67. RTCCreateLeafFunction createLeaf;
  68. RTCSplitPrimitiveFunction splitPrimitive;
  69. RTCProgressMonitorFunction buildProgress;
  70. void* userPtr;
  71. };
  72. /* Returns the default build settings. */
  73. RTC_FORCEINLINE struct RTCBuildArguments rtcDefaultBuildArguments()
  74. {
  75. struct RTCBuildArguments args;
  76. args.byteSize = sizeof(args);
  77. args.buildQuality = RTC_BUILD_QUALITY_MEDIUM;
  78. args.buildFlags = RTC_BUILD_FLAG_NONE;
  79. args.maxBranchingFactor = 2;
  80. args.maxDepth = 32;
  81. args.sahBlockSize = 1;
  82. args.minLeafSize = 1;
  83. args.maxLeafSize = 32;
  84. args.traversalCost = 1.0f;
  85. args.intersectionCost = 1.0f;
  86. args.bvh = NULL;
  87. args.primitives = NULL;
  88. args.primitiveCount = 0;
  89. args.primitiveArrayCapacity = 0;
  90. args.createNode = NULL;
  91. args.setNodeChildren = NULL;
  92. args.setNodeBounds = NULL;
  93. args.createLeaf = NULL;
  94. args.splitPrimitive = NULL;
  95. args.buildProgress = NULL;
  96. args.userPtr = NULL;
  97. return args;
  98. }
  99. /* Creates a new BVH. */
  100. RTC_API RTCBVH rtcNewBVH(RTCDevice device);
  101. /* Builds a BVH. */
  102. RTC_API void* rtcBuildBVH(const struct RTCBuildArguments* args);
  103. /* Allocates memory using the thread local allocator. */
  104. RTC_API void* rtcThreadLocalAlloc(RTCThreadLocalAllocator allocator, size_t bytes, size_t align);
  105. /* Retains the BVH (increments reference count). */
  106. RTC_API void rtcRetainBVH(RTCBVH bvh);
  107. /* Releases the BVH (decrements reference count). */
  108. RTC_API void rtcReleaseBVH(RTCBVH bvh);
  109. RTC_NAMESPACE_END