13 #ifdef WITH_OPENSUBDIV
14 # include <opensubdiv/far/patchTable.h>
19 #ifdef WITH_OPENSUBDIV
25 struct PatchMapQuadNode {
27 void set_child(
int index)
29 for (
int i = 0; i < 4; i++) {
35 void set_child(
unsigned char quadrant,
int index,
bool is_leaf =
true)
44 template<
class T>
static int resolve_quadrant(
T &median,
T &u,
T &
v)
72 OpenSubdiv::Far::PatchTable *patch_table,
77 for (
int array = 0; array < table.
num_arrays; array++) {
78 Far::ConstPatchParamArray
params = patch_table->GetPatchParams(array);
80 for (
int j = 0; j < patch_table->GetNumPatches(array); j++) {
81 num_faces =
max(num_faces, (
int)
params[j].GetFaceId());
86 vector<PatchMapQuadNode> quadtree;
88 quadtree.resize(num_faces);
95 for (
int array = 0; array < table.
num_arrays; array++) {
96 Far::ConstPatchParamArray
params = patch_table->GetPatchParams(array);
98 for (
int i = 0; i < patch_table->GetNumPatches(array);
100 const Far::PatchParam ¶m =
params[i];
101 unsigned short depth = param.GetDepth();
103 PatchMapQuadNode *
node = &quadtree[
params[i].GetFaceId()];
105 if (depth == (param.NonQuadRoot() ? 1 : 0)) {
111 int u = param.GetU();
112 int v = param.GetV();
113 int pdepth = param.NonQuadRoot() ? depth - 2 : depth - 1;
114 int half = 1 << pdepth;
116 for (
int j = 0; j < depth; j++) {
117 int delta =
half >> 1;
119 int quadrant = resolve_quadrant(
half, u,
v);
120 assert(quadrant >= 0);
127 node->set_child(quadrant, handle_index +
offset,
true);
134 quadtree.push_back(PatchMapQuadNode());
136 int idx = (int)quadtree.size() - 1;
137 node->set_child(quadrant, idx * 4 +
offset,
false);
139 node = &quadtree[idx];
160 for (
int i = 0; i < quadtree.size(); i++) {
161 for (
int j = 0; j < 4; j++) {
163 *(
data++) = quadtree[i].children[j];
185 #ifdef WITH_OPENSUBDIV
186 num_arrays = patch_table->GetNumPatchArrays();
188 for (
int i = 0; i < num_arrays; i++) {
189 int patches = patch_table->GetNumPatches(i);
190 int num_control = patch_table->GetPatchArrayDescriptor(i).GetNumControlVertices();
192 num_patches += patches;
196 table.resize(total_size());
204 uint current_param = 0;
206 for (
int i = 0; i < num_arrays; i++) {
207 *(array++) = patch_table->GetPatchArrayDescriptor(i).GetType();
208 *(array++) = patch_table->GetNumPatches(i);
212 Far::ConstIndexArray
indices = patch_table->GetPatchArrayVertices(i);
214 for (
int j = 0; j <
indices.size(); j++) {
218 const Far::PatchParamTable ¶m_table = patch_table->GetPatchParamTable();
220 int num_control = patch_table->GetPatchArrayDescriptor(i).GetNumControlVertices();
221 int patches = patch_table->GetNumPatches(i);
223 for (
int j = 0; j < patches; j++, current_param++) {
224 *(param++) = param_table[current_param].field0;
225 *(param++) = param_table[current_param].field1;
229 *(handle++) = j * num_control;
233 build_patch_map(*
this, patch_table,
offset);
245 for (
int i = 0; i < num_arrays; i++) {
248 *(
dest++) = *(
src++) + doffset;
249 *(
dest++) = *(
src++) + doffset;
258 for (
int i = 0; i < num_patches; i++) {
264 for (
int i = 0; i < num_patches; i++) {
265 *(
dest++) = *(
src++) + doffset;
266 *(
dest++) = *(
src++) + doffset;
271 for (
int i = 0; i < num_nodes; i++) {
272 *(
dest++) = *(
src++) + doffset;
ATTR_WARN_UNUSED_RESULT const BMVert * v
T * resize(size_t newsize)
#define CCL_NAMESPACE_END
SyclQueue void void * src
SyclQueue void void size_t num_bytes void
ccl_gpu_kernel_postfix int ccl_global int ccl_global int * num_indices
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
ccl_gpu_kernel_postfix int ccl_global int * indices
#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)