Differential D14171 Diff 48840 source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_select_idx.cc
Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_select_idx.cc
| Show First 20 Lines • Show All 198 Lines • ▼ Show 20 Lines | |||||
| static void extract_vert_idx_init_subdiv(const DRWSubdivCache *subdiv_cache, | static void extract_vert_idx_init_subdiv(const DRWSubdivCache *subdiv_cache, | ||||
| const MeshRenderData *mr, | const MeshRenderData *mr, | ||||
| MeshBatchCache *UNUSED(cache), | MeshBatchCache *UNUSED(cache), | ||||
| void *buf, | void *buf, | ||||
| void *UNUSED(data)) | void *UNUSED(data)) | ||||
| { | { | ||||
| GPUVertBuf *vbo = static_cast<GPUVertBuf *>(buf); | GPUVertBuf *vbo = static_cast<GPUVertBuf *>(buf); | ||||
| const DRWSubdivLooseGeom &loose_geom = subdiv_cache->loose_geom; | |||||
| /* Each element points to an element in the ibo.points. */ | /* Each element points to an element in the ibo.points. */ | ||||
| draw_subdiv_init_origindex_buffer(vbo, | draw_subdiv_init_origindex_buffer(vbo, | ||||
| (int *)GPU_vertbuf_get_data(subdiv_cache->verts_orig_index), | (int *)GPU_vertbuf_get_data(subdiv_cache->verts_orig_index), | ||||
| subdiv_cache->num_subdiv_loops, | subdiv_cache->num_subdiv_loops, | ||||
| mr->loop_loose_len); | loose_geom.loop_len); | ||||
| if (!mr->v_origindex) { | if (!mr->v_origindex) { | ||||
| return; | return; | ||||
| } | } | ||||
| /* Remap the vertex indices to those pointed by the origin indices layer. At this point, the | /* Remap the vertex indices to those pointed by the origin indices layer. At this point, the | ||||
| * VBO data is a copy of #verts_orig_index which contains the coarse vertices indices, so | * VBO data is a copy of #verts_orig_index which contains the coarse vertices indices, so | ||||
| * the memory can both be accessed for lookup and immediately overwritten. */ | * the memory can both be accessed for lookup and immediately overwritten. */ | ||||
| int *vbo_data = static_cast<int *>(GPU_vertbuf_get_data(vbo)); | int *vbo_data = static_cast<int *>(GPU_vertbuf_get_data(vbo)); | ||||
| for (int i = 0; i < subdiv_cache->num_subdiv_loops; i++) { | for (int i = 0; i < subdiv_cache->num_subdiv_loops; i++) { | ||||
| if (vbo_data[i] == -1) { | if (vbo_data[i] == -1) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| vbo_data[i] = mr->v_origindex[vbo_data[i]]; | vbo_data[i] = mr->v_origindex[vbo_data[i]]; | ||||
| } | } | ||||
| } | } | ||||
| static void extract_vert_idx_loose_geom_subdiv(const DRWSubdivCache *subdiv_cache, | static void extract_vert_idx_loose_geom_subdiv(const DRWSubdivCache *subdiv_cache, | ||||
| const MeshRenderData *mr, | const MeshRenderData *mr, | ||||
| const MeshExtractLooseGeom *loose_geom, | |||||
| void *buffer, | void *buffer, | ||||
| void *UNUSED(data)) | void *UNUSED(data)) | ||||
| { | { | ||||
| const int loop_loose_len = loose_geom->edge_len + loose_geom->vert_len; | const DRWSubdivLooseGeom &loose_geom = subdiv_cache->loose_geom; | ||||
| if (loop_loose_len == 0) { | if (loose_geom.loop_len == 0) { | ||||
| return; | return; | ||||
| } | } | ||||
| GPUVertBuf *vbo = static_cast<GPUVertBuf *>(buffer); | GPUVertBuf *vbo = static_cast<GPUVertBuf *>(buffer); | ||||
| uint *vert_idx_data = (uint *)GPU_vertbuf_get_data(vbo); | uint *vert_idx_data = (uint *)GPU_vertbuf_get_data(vbo); | ||||
| uint offset = subdiv_cache->num_subdiv_loops; | uint offset = subdiv_cache->num_subdiv_loops; | ||||
| if (mr->extract_type == MR_EXTRACT_MESH) { | blender::Span<DRWSubdivLooseEdge> loose_edges = draw_subdiv_cache_get_loose_edges(subdiv_cache); | ||||
| 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; | |||||
| } | |||||
| for (int i = 0; i < loose_geom->vert_len; i++) { | for (const DRWSubdivLooseEdge &loose_edge : loose_edges) { | ||||
| vert_idx_data[offset] = loose_geom->verts[i]; | const DRWSubdivLooseVertex &v1 = loose_geom.verts[loose_edge.loose_subdiv_v1_index]; | ||||
| offset += 1; | 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; | |||||
| } | } | ||||
| 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; | |||||
| } | } | ||||
| 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; | offset += 2; | ||||
| } | } | ||||
| for (int i = 0; i < loose_geom->vert_len; i++) { | blender::Span<DRWSubdivLooseVertex> loose_verts = draw_subdiv_cache_get_loose_verts( | ||||
| const BMVert *loose_vert = BM_vert_at_index(bm, loose_geom->verts[i]); | subdiv_cache); | ||||
| vert_idx_data[offset] = BM_elem_index_get(loose_vert); | |||||
| 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; | offset += 1; | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| static void extract_edge_idx_init_subdiv(const DRWSubdivCache *subdiv_cache, | static void extract_edge_idx_init_subdiv(const DRWSubdivCache *subdiv_cache, | ||||
| const MeshRenderData *mr, | const MeshRenderData *UNUSED(mr), | ||||
| MeshBatchCache *UNUSED(cache), | MeshBatchCache *UNUSED(cache), | ||||
| void *buf, | void *buf, | ||||
| void *UNUSED(data)) | void *UNUSED(data)) | ||||
| { | { | ||||
| GPUVertBuf *vbo = static_cast<GPUVertBuf *>(buf); | GPUVertBuf *vbo = static_cast<GPUVertBuf *>(buf); | ||||
| const DRWSubdivLooseGeom &loose_geom = subdiv_cache->loose_geom; | |||||
| draw_subdiv_init_origindex_buffer( | draw_subdiv_init_origindex_buffer( | ||||
| vbo, | vbo, | ||||
| static_cast<int *>(GPU_vertbuf_get_data(subdiv_cache->edges_orig_index)), | static_cast<int *>(GPU_vertbuf_get_data(subdiv_cache->edges_orig_index)), | ||||
| subdiv_cache->num_subdiv_loops, | 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, | static void extract_edge_idx_loose_geom_subdiv(const DRWSubdivCache *subdiv_cache, | ||||
| const MeshRenderData *UNUSED(mr), | const MeshRenderData *mr, | ||||
| const MeshExtractLooseGeom *loose_geom, | |||||
| void *buffer, | void *buffer, | ||||
| void *UNUSED(data)) | void *UNUSED(data)) | ||||
| { | { | ||||
| const int loop_loose_len = loose_geom->edge_len + loose_geom->vert_len; | const DRWSubdivLooseGeom &loose_geom = subdiv_cache->loose_geom; | ||||
| if (loop_loose_len == 0) { | if (loose_geom.edge_len == 0) { | ||||
| return; | return; | ||||
| } | } | ||||
| GPUVertBuf *vbo = static_cast<GPUVertBuf *>(buffer); | GPUVertBuf *vbo = static_cast<GPUVertBuf *>(buffer); | ||||
| uint *vert_idx_data = (uint *)GPU_vertbuf_get_data(vbo); | uint *vert_idx_data = (uint *)GPU_vertbuf_get_data(vbo); | ||||
| uint offset = subdiv_cache->num_subdiv_loops; | uint offset = subdiv_cache->num_subdiv_loops; | ||||
| for (int i = 0; i < loose_geom->edge_len; i++) { | blender::Span<DRWSubdivLooseEdge> loose_edges = draw_subdiv_cache_get_loose_edges(subdiv_cache); | ||||
| vert_idx_data[offset] = loose_geom->edges[i]; | for (const DRWSubdivLooseEdge &loose_edge : loose_edges) { | ||||
| vert_idx_data[offset + 1] = loose_geom->edges[i]; | 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; | offset += 2; | ||||
| } | } | ||||
| } | } | ||||
| static void extract_poly_idx_init_subdiv(const DRWSubdivCache *subdiv_cache, | static void extract_poly_idx_init_subdiv(const DRWSubdivCache *subdiv_cache, | ||||
| const MeshRenderData *mr, | const MeshRenderData *mr, | ||||
| MeshBatchCache *UNUSED(cache), | MeshBatchCache *UNUSED(cache), | ||||
| void *buf, | void *buf, | ||||
| ▲ Show 20 Lines • Show All 121 Lines • Show Last 20 Lines | |||||