diff options
Diffstat (limited to 'intern/opensubdiv/opensubdiv_gpu_capi.cc')
-rw-r--r-- | intern/opensubdiv/opensubdiv_gpu_capi.cc | 76 |
1 files changed, 32 insertions, 44 deletions
diff --git a/intern/opensubdiv/opensubdiv_gpu_capi.cc b/intern/opensubdiv/opensubdiv_gpu_capi.cc index 9498f936b6b..803265dbe28 100644 --- a/intern/opensubdiv/opensubdiv_gpu_capi.cc +++ b/intern/opensubdiv/opensubdiv_gpu_capi.cc @@ -575,46 +575,41 @@ static void finish_patchDraw(bool fill_quads) } } -#if 0 static void draw_partition_patches_range(PartitionedGLMeshInterface *mesh, GLuint program, - int start_partition, - int num_partitions) + int start_patch, + int num_patches) { - /* Glue patches from all partitions in the range together. */ - int patch_index = -1, start_element = -1, num_elements = 0; - for (int partition = start_partition; - partition < start_partition + num_partitions; - ++partition) - { - OsdDrawContext::PatchArrayVector const &patches = - mesh->GetPatchArrays(partition); - for (int i = 0; i < (int)patches.size(); ++i) { - OsdDrawContext::PatchArray const &patch = patches[i]; - OsdDrawContext::PatchDescriptor desc = patch.GetDescriptor(); - OpenSubdiv::FarPatchTables::Type patchType = desc.GetType(); - if (patchType == OpenSubdiv::FarPatchTables::QUADS) { - if (start_element == -1) { - patch_index = patch.GetPatchIndex(); - start_element = patch.GetVertIndex(); - } + int traversed_patches = 0, num_remained_patches = num_patches; + const OpenSubdiv::Osd::PatchArrayVector& patches = + mesh->GetPatchTable()->GetPatchArrays(); + for (int i = 0; i < (int)patches.size(); ++i) { + const OpenSubdiv::Osd::PatchArray& patch = patches[i]; + OpenSubdiv::Far::PatchDescriptor desc = patch.GetDescriptor(); + OpenSubdiv::Far::PatchDescriptor::Type patchType = desc.GetType(); - assert(patch.GetVertIndex() == start_element + num_elements); - num_elements += patch.GetNumIndices(); + if (patchType == OpenSubdiv::Far::PatchDescriptor::QUADS) { + const int num_block_patches = patch.GetNumPatches(); + if (start_patch >= traversed_patches && + start_patch < traversed_patches + num_block_patches) + { + const int num_control_verts = desc.GetNumControlVertices(); + const int start_draw_patch = start_patch - traversed_patches; + const int num_draw_patches = std::min(num_remained_patches, + num_block_patches - start_draw_patch); + perform_drawElements(program, + i, + num_draw_patches * num_control_verts, + patch.GetIndexBase() + start_draw_patch * num_control_verts); + num_remained_patches -= num_draw_patches; } - else { - assert(!"Discontinuitied are not supported yet."); + if (num_remained_patches == 0) { + break; } + traversed_patches += num_block_patches; } - } - - /* Perform actual draw. */ - perform_drawElements(program, - patch_index, - num_elements, - start_element); + } } -#endif static void draw_all_patches(PartitionedGLMeshInterface *mesh, GLuint program) @@ -637,8 +632,8 @@ static void draw_all_patches(PartitionedGLMeshInterface *mesh, void openSubdiv_osdGLMeshDisplay(OpenSubdiv_GLMesh *gl_mesh, int fill_quads, - int start_partition, - int num_partitions) + int start_patch, + int num_patches) { PartitionedGLMeshInterface *mesh = (PartitionedGLMeshInterface *)(gl_mesh->descriptor); @@ -649,18 +644,11 @@ void openSubdiv_osdGLMeshDisplay(OpenSubdiv_GLMesh *gl_mesh, /* Setup GLSL/OpenGL to draw patches in current context. */ GLuint program = preapre_patchDraw(mesh, fill_quads != 0); - if (start_partition != -1) { -#if 0 + if (start_patch != -1) { draw_partition_patches_range(mesh, program, - start_partition, - num_partitions); -#else - (void)num_partitions; - if(start_partition == 0) { - draw_all_patches(mesh, program); - } -#endif + start_patch, + num_patches); } else { draw_all_patches(mesh, program); |