diff options
Diffstat (limited to 'source/blender/draw/intern/mesh_extractors')
7 files changed, 182 insertions, 144 deletions
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh.h b/source/blender/draw/intern/mesh_extractors/extract_mesh.h index 37eb4f80442..a250bc52ea8 100644 --- a/source/blender/draw/intern/mesh_extractors/extract_mesh.h +++ b/source/blender/draw/intern/mesh_extractors/extract_mesh.h @@ -206,7 +206,6 @@ typedef void(ExtractLVertMeshFn)(const MeshRenderData *mr, void *data); typedef void(ExtractLooseGeomSubdivFn)(const struct DRWSubdivCache *subdiv_cache, const MeshRenderData *mr, - const MeshExtractLooseGeom *loose_geom, void *buffer, void *data); typedef void(ExtractInitFn)(const MeshRenderData *mr, diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines.cc index 3d9729dea56..247d4c399e8 100644 --- a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines.cc +++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines.cc @@ -158,30 +158,35 @@ static void extract_lines_finish(const MeshRenderData *UNUSED(mr), } static void extract_lines_init_subdiv(const DRWSubdivCache *subdiv_cache, - const MeshRenderData *mr, + const MeshRenderData *UNUSED(mr), struct MeshBatchCache *UNUSED(cache), void *buffer, void *UNUSED(data)) { + const DRWSubdivLooseGeom &loose_geom = subdiv_cache->loose_geom; GPUIndexBuf *ibo = static_cast<GPUIndexBuf *>(buffer); GPU_indexbuf_init_build_on_device(ibo, - subdiv_cache->num_subdiv_loops * 2 + mr->edge_loose_len * 2); + subdiv_cache->num_subdiv_loops * 2 + loose_geom.edge_len * 2); + + if (subdiv_cache->num_subdiv_loops == 0) { + return; + } draw_subdiv_build_lines_buffer(subdiv_cache, ibo); } static void extract_lines_loose_geom_subdiv(const DRWSubdivCache *subdiv_cache, const MeshRenderData *UNUSED(mr), - const MeshExtractLooseGeom *loose_geom, void *buffer, void *UNUSED(data)) { - if (loose_geom->edge_len == 0) { + const DRWSubdivLooseGeom &loose_geom = subdiv_cache->loose_geom; + if (loose_geom.edge_len == 0) { return; } GPUIndexBuf *ibo = static_cast<GPUIndexBuf *>(buffer); - draw_subdiv_build_lines_loose_buffer(subdiv_cache, ibo, static_cast<uint>(loose_geom->edge_len)); + draw_subdiv_build_lines_loose_buffer(subdiv_cache, ibo, static_cast<uint>(loose_geom.edge_len)); } constexpr MeshExtract create_extractor_lines() @@ -231,6 +236,20 @@ static void extract_lines_with_lines_loose_finish(const MeshRenderData *mr, extract_lines_loose_subbuffer(mr, cache); } +static void extract_lines_with_lines_loose_finish_subdiv(const struct DRWSubdivCache *subdiv_cache, + const MeshRenderData *UNUSED(mr), + struct MeshBatchCache *cache, + void *UNUSED(buf), + void *UNUSED(_data)) +{ + /* Multiply by 2 because these are edges indices. */ + const int start = subdiv_cache->num_subdiv_loops * 2; + const int len = subdiv_cache->loose_geom.edge_len * 2; + GPU_indexbuf_create_subrange_in_place( + cache->final.buff.ibo.lines_loose, cache->final.buff.ibo.lines, start, len); + cache->no_loose_wire = (len == 0); +} + constexpr MeshExtract create_extractor_lines_with_lines_loose() { MeshExtract extractor = {nullptr}; @@ -241,6 +260,9 @@ constexpr MeshExtract create_extractor_lines_with_lines_loose() extractor.iter_ledge_mesh = extract_lines_iter_ledge_mesh; extractor.task_reduce = extract_lines_task_reduce; extractor.finish = extract_lines_with_lines_loose_finish; + extractor.init_subdiv = extract_lines_init_subdiv; + extractor.iter_loose_geom_subdiv = extract_lines_loose_geom_subdiv; + extractor.finish_subdiv = extract_lines_with_lines_loose_finish_subdiv; extractor.data_type = MR_DATA_NONE; extractor.data_size = sizeof(GPUIndexBufBuilder); extractor.use_threading = true; @@ -264,10 +286,22 @@ static void extract_lines_loose_only_init(const MeshRenderData *mr, extract_lines_loose_subbuffer(mr, cache); } +static void extract_lines_loose_only_init_subdiv(const DRWSubdivCache *UNUSED(subdiv_cache), + const MeshRenderData *mr, + struct MeshBatchCache *cache, + void *buffer, + void *UNUSED(data)) +{ + BLI_assert(buffer == cache->final.buff.ibo.lines_loose); + UNUSED_VARS_NDEBUG(buffer); + extract_lines_loose_subbuffer(mr, cache); +} + constexpr MeshExtract create_extractor_lines_loose_only() { MeshExtract extractor = {nullptr}; extractor.init = extract_lines_loose_only_init; + extractor.init_subdiv = extract_lines_loose_only_init_subdiv; extractor.data_type = MR_DATA_LOOSE_GEOM; extractor.data_size = 0; extractor.use_threading = false; diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_points.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_points.cc index 2bb4cc0fb47..c5669f79a13 100644 --- a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_points.cc +++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_points.cc @@ -163,8 +163,10 @@ static void extract_points_init_subdiv(const DRWSubdivCache *subdiv_cache, void *data) { GPUIndexBufBuilder *elb = static_cast<GPUIndexBufBuilder *>(data); - GPU_indexbuf_init( - elb, GPU_PRIM_POINTS, mr->vert_len, subdiv_cache->num_subdiv_loops + mr->loop_loose_len); + GPU_indexbuf_init(elb, + GPU_PRIM_POINTS, + mr->vert_len, + subdiv_cache->num_subdiv_loops + subdiv_cache->loose_geom.loop_len); } static void extract_points_iter_subdiv_common(GPUIndexBufBuilder *elb, @@ -212,46 +214,70 @@ static void extract_points_iter_subdiv_mesh(const DRWSubdivCache *subdiv_cache, static void extract_points_loose_geom_subdiv(const DRWSubdivCache *subdiv_cache, const MeshRenderData *mr, - const MeshExtractLooseGeom *loose_geom, void *UNUSED(buffer), void *data) { - const int loop_loose_len = loose_geom->edge_len + loose_geom->vert_len; + const DRWSubdivLooseGeom &loose_geom = subdiv_cache->loose_geom; + const int loop_loose_len = loose_geom.loop_len; if (loop_loose_len == 0) { return; } GPUIndexBufBuilder *elb = static_cast<GPUIndexBufBuilder *>(data); + uint offset = subdiv_cache->num_subdiv_loops; - if (mr->extract_type == MR_EXTRACT_MESH) { - const Mesh *coarse_mesh = subdiv_cache->mesh; - const MEdge *coarse_edges = coarse_mesh->medge; + if (mr->extract_type != MR_EXTRACT_BMESH) { + blender::Span<DRWSubdivLooseEdge> loose_edges = draw_subdiv_cache_get_loose_edges( + subdiv_cache); + + for (const DRWSubdivLooseEdge &loose_edge : loose_edges) { + const DRWSubdivLooseVertex &v1 = loose_geom.verts[loose_edge.loose_subdiv_v1_index]; + const DRWSubdivLooseVertex &v2 = loose_geom.verts[loose_edge.loose_subdiv_v2_index]; + if (v1.coarse_vertex_index != -1u) { + vert_set_mesh(elb, mr, v1.coarse_vertex_index, offset); + } + if (v2.coarse_vertex_index != -1u) { + vert_set_mesh(elb, mr, v2.coarse_vertex_index, offset + 1); + } - for (int i = 0; i < loose_geom->edge_len; i++) { - const MEdge *loose_edge = &coarse_edges[loose_geom->edges[i]]; - vert_set_mesh(elb, mr, loose_edge->v1, offset); - vert_set_mesh(elb, mr, loose_edge->v2, offset + 1); offset += 2; } + blender::Span<DRWSubdivLooseVertex> loose_verts = draw_subdiv_cache_get_loose_verts( + subdiv_cache); - for (int i = 0; i < loose_geom->vert_len; i++) { - vert_set_mesh(elb, mr, loose_geom->verts[i], offset); + for (const DRWSubdivLooseVertex &loose_vert : loose_verts) { + vert_set_mesh(elb, mr, loose_vert.coarse_vertex_index, offset); offset += 1; } } else { - BMesh *bm = mr->bm; - for (int i = 0; i < loose_geom->edge_len; i++) { - const BMEdge *loose_edge = BM_edge_at_index(bm, loose_geom->edges[i]); - vert_set_bm(elb, loose_edge->v1, offset); - vert_set_bm(elb, loose_edge->v2, offset + 1); + blender::Span<DRWSubdivLooseEdge> loose_edges = draw_subdiv_cache_get_loose_edges( + subdiv_cache); + + for (const DRWSubdivLooseEdge &loose_edge : loose_edges) { + const DRWSubdivLooseVertex &v1 = loose_geom.verts[loose_edge.loose_subdiv_v1_index]; + const DRWSubdivLooseVertex &v2 = loose_geom.verts[loose_edge.loose_subdiv_v2_index]; + if (v1.coarse_vertex_index != -1u) { + BMVert *eve = mr->v_origindex ? bm_original_vert_get(mr, v1.coarse_vertex_index) : + BM_vert_at_index(mr->bm, v1.coarse_vertex_index); + vert_set_bm(elb, eve, offset); + } + if (v2.coarse_vertex_index != -1u) { + BMVert *eve = mr->v_origindex ? bm_original_vert_get(mr, v2.coarse_vertex_index) : + BM_vert_at_index(mr->bm, v2.coarse_vertex_index); + vert_set_bm(elb, eve, offset + 1); + } + offset += 2; } + blender::Span<DRWSubdivLooseVertex> loose_verts = draw_subdiv_cache_get_loose_verts( + subdiv_cache); - for (int i = 0; i < loose_geom->vert_len; i++) { - const BMVert *loose_vert = BM_vert_at_index(bm, loose_geom->verts[i]); - vert_set_bm(elb, loose_vert, offset); + for (const DRWSubdivLooseVertex &loose_vert : loose_verts) { + BMVert *eve = mr->v_origindex ? bm_original_vert_get(mr, loose_vert.coarse_vertex_index) : + BM_vert_at_index(mr->bm, loose_vert.coarse_vertex_index); + vert_set_bm(elb, eve, offset); offset += 1; } } diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edge_fac.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edge_fac.cc index 8470a71059f..2d4e0a8e246 100644 --- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edge_fac.cc +++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edge_fac.cc @@ -233,16 +233,17 @@ static GPUVertFormat *get_subdiv_edge_fac_format() } static void extract_edge_fac_init_subdiv(const DRWSubdivCache *subdiv_cache, - const MeshRenderData *mr, + const MeshRenderData *UNUSED(mr), struct MeshBatchCache *cache, void *buffer, void *UNUSED(data)) { + const DRWSubdivLooseGeom &loose_geom = subdiv_cache->loose_geom; GPUVertBuf *edge_idx = cache->final.buff.vbo.edge_idx; GPUVertBuf *pos_nor = cache->final.buff.vbo.pos_nor; GPUVertBuf *vbo = static_cast<GPUVertBuf *>(buffer); GPU_vertbuf_init_build_on_device( - vbo, get_subdiv_edge_fac_format(), subdiv_cache->num_subdiv_loops + mr->loop_loose_len); + vbo, get_subdiv_edge_fac_format(), subdiv_cache->num_subdiv_loops + loose_geom.loop_len); /* Create a temporary buffer for the edge original indices if it was not requested. */ const bool has_edge_idx = edge_idx != nullptr; @@ -268,11 +269,11 @@ static void extract_edge_fac_init_subdiv(const DRWSubdivCache *subdiv_cache, static void extract_edge_fac_loose_geom_subdiv(const DRWSubdivCache *subdiv_cache, const MeshRenderData *UNUSED(mr), - const MeshExtractLooseGeom *loose_geom, void *buffer, void *UNUSED(data)) { - if (loose_geom->edge_len == 0) { + const DRWSubdivLooseGeom &loose_geom = subdiv_cache->loose_geom; + if (loose_geom.edge_len == 0) { return; } @@ -282,7 +283,7 @@ static void extract_edge_fac_loose_geom_subdiv(const DRWSubdivCache *subdiv_cach GPU_vertbuf_use(vbo); uint offset = subdiv_cache->num_subdiv_loops; - for (int i = 0; i < loose_geom->edge_len; i++) { + for (int i = 0; i < loose_geom.edge_len; i++) { if (GPU_crappy_amd_driver()) { float loose_edge_fac[2] = {1.0f, 1.0f}; GPU_vertbuf_update_sub(vbo, offset * sizeof(float), sizeof(loose_edge_fac), loose_edge_fac); diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edit_data.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edit_data.cc index 046e4b9e4bb..d13d5e98132 100644 --- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edit_data.cc +++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edit_data.cc @@ -256,14 +256,15 @@ static void extract_edit_data_iter_lvert_mesh(const MeshRenderData *mr, } static void extract_edit_data_init_subdiv(const DRWSubdivCache *subdiv_cache, - const MeshRenderData *mr, + const MeshRenderData *UNUSED(mr), MeshBatchCache *UNUSED(cache), void *buf, void *data) { + const DRWSubdivLooseGeom &loose_geom = subdiv_cache->loose_geom; GPUVertBuf *vbo = static_cast<GPUVertBuf *>(buf); GPU_vertbuf_init_with_format(vbo, get_edit_data_format()); - GPU_vertbuf_data_alloc(vbo, subdiv_cache->num_subdiv_loops + mr->loop_loose_len); + GPU_vertbuf_data_alloc(vbo, subdiv_cache->num_subdiv_loops + loose_geom.loop_len); EditLoopData *vbo_data = (EditLoopData *)GPU_vertbuf_get_data(vbo); *(EditLoopData **)data = vbo_data; } @@ -322,27 +323,38 @@ static void extract_edit_data_iter_subdiv_mesh(const DRWSubdivCache *subdiv_cach static void extract_edit_data_loose_geom_subdiv(const DRWSubdivCache *subdiv_cache, const MeshRenderData *mr, - const MeshExtractLooseGeom *loose_geom, void *UNUSED(buffer), void *_data) { - if (loose_geom->edge_len == 0) { + const DRWSubdivLooseGeom &loose_geom = subdiv_cache->loose_geom; + if (loose_geom.edge_len == 0) { return; } + blender::Span<DRWSubdivLooseEdge> loose_edges = draw_subdiv_cache_get_loose_edges(subdiv_cache); + EditLoopData *vbo_data = *(EditLoopData **)_data; + int ledge_index = 0; - for (int ledge_index = 0; ledge_index < loose_geom->edge_len; ledge_index++) { - const int offset = subdiv_cache->num_subdiv_loops + ledge_index * 2; + for (const DRWSubdivLooseEdge &loose_edge : loose_edges) { + const int offset = subdiv_cache->num_subdiv_loops + ledge_index++ * 2; EditLoopData *data = &vbo_data[offset]; memset(data, 0, sizeof(EditLoopData)); - const int edge_index = loose_geom->edges[ledge_index]; + const int edge_index = loose_edge.coarse_edge_index; BMEdge *eed = mr->e_origindex ? bm_original_edge_get(mr, edge_index) : BM_edge_at_index(mr->bm, edge_index); mesh_render_data_edge_flag(mr, eed, &data[0]); data[1] = data[0]; - mesh_render_data_vert_flag(mr, eed->v1, &data[0]); - mesh_render_data_vert_flag(mr, eed->v2, &data[1]); + + const DRWSubdivLooseVertex &v1 = loose_geom.verts[loose_edge.loose_subdiv_v1_index]; + const DRWSubdivLooseVertex &v2 = loose_geom.verts[loose_edge.loose_subdiv_v2_index]; + + if (v1.coarse_vertex_index != -1u) { + mesh_render_data_vert_flag(mr, eed->v1, &data[0]); + } + if (v2.coarse_vertex_index != -1u) { + mesh_render_data_vert_flag(mr, eed->v2, &data[1]); + } } } diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_pos_nor.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_pos_nor.cc index a844a116a87..12cff6408b6 100644 --- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_pos_nor.cc +++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_pos_nor.cc @@ -227,16 +227,21 @@ static GPUVertFormat *get_custom_normals_format() } static void extract_pos_nor_init_subdiv(const DRWSubdivCache *subdiv_cache, - const MeshRenderData *mr, + const MeshRenderData *UNUSED(mr), struct MeshBatchCache *UNUSED(cache), void *buffer, void *UNUSED(data)) { GPUVertBuf *vbo = static_cast<GPUVertBuf *>(buffer); + const DRWSubdivLooseGeom &loose_geom = subdiv_cache->loose_geom; /* Initialize the vertex buffer, it was already allocated. */ GPU_vertbuf_init_build_on_device( - vbo, get_pos_nor_format(), subdiv_cache->num_subdiv_loops + mr->loop_loose_len); + vbo, get_pos_nor_format(), subdiv_cache->num_subdiv_loops + loose_geom.loop_len); + + if (subdiv_cache->num_subdiv_loops == 0) { + return; + } draw_subdiv_extract_pos_nor(subdiv_cache, vbo); @@ -289,13 +294,12 @@ static void extract_pos_nor_init_subdiv(const DRWSubdivCache *subdiv_cache, } static void extract_pos_nor_loose_geom_subdiv(const DRWSubdivCache *subdiv_cache, - const MeshRenderData *mr, - const MeshExtractLooseGeom *loose_geom, + const MeshRenderData *UNUSED(mr), void *buffer, void *UNUSED(data)) { - const int loop_loose_len = loose_geom->edge_len + loose_geom->vert_len; - if (loop_loose_len == 0) { + const DRWSubdivLooseGeom &loose_geom = subdiv_cache->loose_geom; + if (loose_geom.loop_len == 0) { return; } @@ -309,75 +313,38 @@ static void extract_pos_nor_loose_geom_subdiv(const DRWSubdivCache *subdiv_cache float flag; }; - if (mr->extract_type == MR_EXTRACT_MESH) { - const Mesh *coarse_mesh = subdiv_cache->mesh; - const MEdge *coarse_edges = coarse_mesh->medge; - const MVert *coarse_verts = coarse_mesh->mvert; - - SubdivPosNorLoop edge_data[2]; - memset(&edge_data, 0, sizeof(SubdivPosNorLoop) * 2); - for (int i = 0; i < loose_geom->edge_len; i++) { - const MEdge *loose_edge = &coarse_edges[loose_geom->edges[i]]; - const MVert *loose_vert1 = &coarse_verts[loose_edge->v1]; - const MVert *loose_vert2 = &coarse_verts[loose_edge->v2]; + /* Make sure buffer is active for sending loose data. */ + GPU_vertbuf_use(vbo); - copy_v3_v3(edge_data[0].pos, loose_vert1->co); - copy_v3_v3(edge_data[1].pos, loose_vert2->co); + blender::Span<DRWSubdivLooseEdge> loose_edges = draw_subdiv_cache_get_loose_edges(subdiv_cache); - GPU_vertbuf_update_sub( - vbo, offset * sizeof(SubdivPosNorLoop), sizeof(SubdivPosNorLoop) * 2, &edge_data); + SubdivPosNorLoop edge_data[2]; + memset(edge_data, 0, sizeof(SubdivPosNorLoop) * 2); + for (const DRWSubdivLooseEdge &loose_edge : loose_edges) { + const DRWSubdivLooseVertex &v1 = loose_geom.verts[loose_edge.loose_subdiv_v1_index]; + const DRWSubdivLooseVertex &v2 = loose_geom.verts[loose_edge.loose_subdiv_v2_index]; - offset += 2; - } - - SubdivPosNorLoop vert_data; - memset(&vert_data, 0, sizeof(SubdivPosNorLoop)); - for (int i = 0; i < loose_geom->vert_len; i++) { - const MVert *loose_vertex = &coarse_verts[loose_geom->verts[i]]; + copy_v3_v3(edge_data[0].pos, v1.co); + copy_v3_v3(edge_data[1].pos, v2.co); - copy_v3_v3(vert_data.pos, loose_vertex->co); + GPU_vertbuf_update_sub( + vbo, offset * sizeof(SubdivPosNorLoop), sizeof(SubdivPosNorLoop) * 2, &edge_data); - GPU_vertbuf_update_sub( - vbo, offset * sizeof(SubdivPosNorLoop), sizeof(SubdivPosNorLoop), &vert_data); - - offset += 1; - } + offset += 2; } - else { - BMesh *bm = subdiv_cache->bm; - - SubdivPosNorLoop edge_data[2]; - memset(&edge_data, 0, sizeof(SubdivPosNorLoop) * 2); - for (int i = 0; i < loose_geom->edge_len; i++) { - const BMEdge *loose_edge = BM_edge_at_index(bm, loose_geom->edges[i]); - const BMVert *loose_vert1 = loose_edge->v1; - const BMVert *loose_vert2 = loose_edge->v2; - - copy_v3_v3(edge_data[0].pos, loose_vert1->co); - copy_v3_v3(edge_data[0].nor, loose_vert1->no); - - copy_v3_v3(edge_data[1].pos, loose_vert2->co); - copy_v3_v3(edge_data[1].nor, loose_vert2->no); - GPU_vertbuf_update_sub( - vbo, offset * sizeof(SubdivPosNorLoop), sizeof(SubdivPosNorLoop) * 2, &edge_data); + SubdivPosNorLoop vert_data; + memset(&vert_data, 0, sizeof(SubdivPosNorLoop)); + blender::Span<DRWSubdivLooseVertex> loose_verts = draw_subdiv_cache_get_loose_verts( + subdiv_cache); - offset += 2; - } - - SubdivPosNorLoop vert_data; - memset(&vert_data, 0, sizeof(SubdivPosNorLoop)); - for (int i = 0; i < loose_geom->vert_len; i++) { - const BMVert *loose_vertex = BM_vert_at_index(bm, loose_geom->verts[i]); + for (const DRWSubdivLooseVertex &loose_vert : loose_verts) { + copy_v3_v3(vert_data.pos, loose_vert.co); - copy_v3_v3(vert_data.pos, loose_vertex->co); - copy_v3_v3(vert_data.nor, loose_vertex->no); + GPU_vertbuf_update_sub( + vbo, offset * sizeof(SubdivPosNorLoop), sizeof(SubdivPosNorLoop), &vert_data); - GPU_vertbuf_update_sub( - vbo, offset * sizeof(SubdivPosNorLoop), sizeof(SubdivPosNorLoop), &vert_data); - - offset += 1; - } + offset += 1; } } diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_select_idx.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_select_idx.cc index 8d3df75b782..f570a26ae67 100644 --- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_select_idx.cc +++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_select_idx.cc @@ -204,12 +204,12 @@ static void extract_vert_idx_init_subdiv(const DRWSubdivCache *subdiv_cache, void *UNUSED(data)) { GPUVertBuf *vbo = static_cast<GPUVertBuf *>(buf); + const DRWSubdivLooseGeom &loose_geom = subdiv_cache->loose_geom; /* Each element points to an element in the ibo.points. */ draw_subdiv_init_origindex_buffer(vbo, (int *)GPU_vertbuf_get_data(subdiv_cache->verts_orig_index), subdiv_cache->num_subdiv_loops, - mr->loop_loose_len); - + loose_geom.loop_len); if (!mr->v_origindex) { return; } @@ -228,12 +228,11 @@ static void extract_vert_idx_init_subdiv(const DRWSubdivCache *subdiv_cache, static void extract_vert_idx_loose_geom_subdiv(const DRWSubdivCache *subdiv_cache, const MeshRenderData *mr, - const MeshExtractLooseGeom *loose_geom, void *buffer, void *UNUSED(data)) { - const int loop_loose_len = loose_geom->edge_len + loose_geom->vert_len; - if (loop_loose_len == 0) { + const DRWSubdivLooseGeom &loose_geom = subdiv_cache->loose_geom; + if (loose_geom.loop_len == 0) { return; } @@ -241,60 +240,57 @@ static void extract_vert_idx_loose_geom_subdiv(const DRWSubdivCache *subdiv_cach uint *vert_idx_data = (uint *)GPU_vertbuf_get_data(vbo); uint offset = subdiv_cache->num_subdiv_loops; - if (mr->extract_type == MR_EXTRACT_MESH) { - const Mesh *coarse_mesh = subdiv_cache->mesh; - const MEdge *coarse_edges = coarse_mesh->medge; - for (int i = 0; i < loose_geom->edge_len; i++) { - const MEdge *loose_edge = &coarse_edges[loose_geom->edges[i]]; - vert_idx_data[offset] = loose_edge->v1; - vert_idx_data[offset + 1] = loose_edge->v2; - offset += 2; + blender::Span<DRWSubdivLooseEdge> loose_edges = draw_subdiv_cache_get_loose_edges(subdiv_cache); + + for (const DRWSubdivLooseEdge &loose_edge : loose_edges) { + const DRWSubdivLooseVertex &v1 = loose_geom.verts[loose_edge.loose_subdiv_v1_index]; + const DRWSubdivLooseVertex &v2 = loose_geom.verts[loose_edge.loose_subdiv_v2_index]; + + if (v1.coarse_vertex_index != -1u) { + vert_idx_data[offset] = mr->v_origindex ? mr->v_origindex[v1.coarse_vertex_index] : + v1.coarse_vertex_index; } - for (int i = 0; i < loose_geom->vert_len; i++) { - vert_idx_data[offset] = loose_geom->verts[i]; - offset += 1; + if (v2.coarse_vertex_index != -1u) { + vert_idx_data[offset + 1] = mr->v_origindex ? mr->v_origindex[v2.coarse_vertex_index] : + v2.coarse_vertex_index; } + + offset += 2; } - else { - BMesh *bm = mr->bm; - for (int i = 0; i < loose_geom->edge_len; i++) { - const BMEdge *loose_edge = BM_edge_at_index(bm, loose_geom->edges[i]); - vert_idx_data[offset] = BM_elem_index_get(loose_edge->v1); - vert_idx_data[offset + 1] = BM_elem_index_get(loose_edge->v2); - offset += 2; - } - for (int i = 0; i < loose_geom->vert_len; i++) { - const BMVert *loose_vert = BM_vert_at_index(bm, loose_geom->verts[i]); - vert_idx_data[offset] = BM_elem_index_get(loose_vert); - offset += 1; - } + blender::Span<DRWSubdivLooseVertex> loose_verts = draw_subdiv_cache_get_loose_verts( + subdiv_cache); + + for (const DRWSubdivLooseVertex &loose_vert : loose_verts) { + vert_idx_data[offset] = mr->v_origindex ? mr->v_origindex[loose_vert.coarse_vertex_index] : + loose_vert.coarse_vertex_index; + offset += 1; } } static void extract_edge_idx_init_subdiv(const DRWSubdivCache *subdiv_cache, - const MeshRenderData *mr, + const MeshRenderData *UNUSED(mr), MeshBatchCache *UNUSED(cache), void *buf, void *UNUSED(data)) { GPUVertBuf *vbo = static_cast<GPUVertBuf *>(buf); + const DRWSubdivLooseGeom &loose_geom = subdiv_cache->loose_geom; draw_subdiv_init_origindex_buffer( vbo, static_cast<int *>(GPU_vertbuf_get_data(subdiv_cache->edges_orig_index)), subdiv_cache->num_subdiv_loops, - mr->edge_loose_len * 2); + loose_geom.edge_len * 2); } static void extract_edge_idx_loose_geom_subdiv(const DRWSubdivCache *subdiv_cache, - const MeshRenderData *UNUSED(mr), - const MeshExtractLooseGeom *loose_geom, + const MeshRenderData *mr, void *buffer, void *UNUSED(data)) { - const int loop_loose_len = loose_geom->edge_len + loose_geom->vert_len; - if (loop_loose_len == 0) { + const DRWSubdivLooseGeom &loose_geom = subdiv_cache->loose_geom; + if (loose_geom.edge_len == 0) { return; } @@ -302,9 +298,12 @@ static void extract_edge_idx_loose_geom_subdiv(const DRWSubdivCache *subdiv_cach uint *vert_idx_data = (uint *)GPU_vertbuf_get_data(vbo); uint offset = subdiv_cache->num_subdiv_loops; - for (int i = 0; i < loose_geom->edge_len; i++) { - vert_idx_data[offset] = loose_geom->edges[i]; - vert_idx_data[offset + 1] = loose_geom->edges[i]; + blender::Span<DRWSubdivLooseEdge> loose_edges = draw_subdiv_cache_get_loose_edges(subdiv_cache); + for (const DRWSubdivLooseEdge &loose_edge : loose_edges) { + const int coarse_edge_index = mr->e_origindex ? mr->e_origindex[loose_edge.coarse_edge_index] : + loose_edge.coarse_edge_index; + vert_idx_data[offset] = coarse_edge_index; + vert_idx_data[offset + 1] = coarse_edge_index; offset += 2; } } |