diff options
Diffstat (limited to 'source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_pos_nor.cc')
-rw-r--r-- | source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_pos_nor.cc | 97 |
1 files changed, 32 insertions, 65 deletions
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; } } |