15# include <opensubdiv/far/patchTable.h>
26struct PatchMapQuadNode {
28 void set_child(
int index)
30 for (
int i = 0; i < 4; i++) {
36 void set_child(
unsigned char quadrant,
int index,
bool is_leaf =
true)
45template<
class T>
static int resolve_quadrant(T &median, T &u, T &
v)
73 OpenSubdiv::Far::PatchTable *patch_table,
79 Far::ConstPatchParamArray
params = patch_table->GetPatchParams(
array);
81 for (
int j = 0; j < patch_table->GetNumPatches(
array); j++) {
82 num_faces =
max(num_faces, (
int)
params[j].GetFaceId());
89 quadtree.resize(num_faces);
97 Far::ConstPatchParamArray
params = patch_table->GetPatchParams(
array);
101 const Far::PatchParam ¶m =
params[i];
102 unsigned short depth = param.GetDepth();
104 PatchMapQuadNode *node = &quadtree[
params[i].GetFaceId()];
106 if (depth == (param.NonQuadRoot() ? 1 : 0)) {
108 node->set_child(handle_index + offset);
112 int u = param.GetU();
113 int v = param.GetV();
114 int pdepth = param.NonQuadRoot() ? depth - 2 : depth - 1;
115 int half = 1 << pdepth;
117 for (
int j = 0; j < depth; j++) {
118 int delta =
half >> 1;
120 int quadrant = resolve_quadrant(
half, u,
v);
121 assert(quadrant >= 0);
128 node->set_child(quadrant, handle_index + offset,
true);
135 quadtree.push_back(PatchMapQuadNode());
137 int idx = (
int)quadtree.size() - 1;
138 node->set_child(quadrant, idx * 4 + offset,
false);
140 node = &quadtree[idx];
145 node = &(quadtree[(idx - offset) / 4]);
161 for (
int i = 0; i < quadtree.size(); i++) {
162 for (
int j = 0; j < 4; j++) {
164 *(data++) = quadtree[i].children[j];
186#ifdef WITH_OPENSUBDIV
187 num_arrays = patch_table->GetNumPatchArrays();
190 int patches = patch_table->GetNumPatches(i);
191 int num_control = patch_table->GetPatchArrayDescriptor(i).GetNumControlVertices();
205 uint current_param = 0;
208 *(
array++) = patch_table->GetPatchArrayDescriptor(i).GetType();
209 *(
array++) = patch_table->GetNumPatches(i);
210 *(
array++) = (index - data) + offset;
211 *(
array++) = (param - data) + offset;
213 Far::ConstIndexArray indices = patch_table->GetPatchArrayVertices(i);
215 for (
int j = 0; j < indices.size(); j++) {
216 *(index++) = indices[j];
219 const Far::PatchParamTable ¶m_table = patch_table->GetPatchParamTable();
221 int num_control = patch_table->GetPatchArrayDescriptor(i).GetNumControlVertices();
222 int patches = patch_table->GetNumPatches(i);
224 for (
int j = 0; j < patches; j++, current_param++) {
225 *(param++) = param_table[current_param].field0;
226 *(param++) = param_table[current_param].field1;
230 *(handle++) = j * num_control;
234 build_patch_map(*
this, patch_table, offset);
247 *(dest++) = *(src++);
248 *(dest++) = *(src++);
249 *(dest++) = *(src++) + doffset;
250 *(dest++) = *(src++) + doffset;
255 *(dest++) = *(src++);
260 *(dest++) = *(src++);
261 *(dest++) = *(src++);
266 *(dest++) = *(src++) + doffset;
267 *(dest++) = *(src++) + doffset;
268 *(dest++) = *(src++);
273 *(dest++) = *(src++) + doffset;
ATTR_WARN_UNUSED_RESULT const BMVert * v
T * resize(size_t newsize)
#define CCL_NAMESPACE_END
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
#define PATCH_MAP_NODE_IS_SET
#define PATCH_MAP_NODE_IS_LEAF
#define PATCH_MAP_NODE_INDEX_MASK
#define PATCH_HANDLE_SIZE
void pack(Far::PatchTable *patch_table, int offset=0)
void copy_adjusting_offsets(uint *dest, int doffset)
ccl_device_inline bool is_leaf(const ccl_global KernelLightTreeNode *knode)