Differential D14171 Diff 48840 source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_pos_nor.cc
Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_pos_nor.cc
| Show First 20 Lines • Show All 221 Lines • ▼ Show 20 Lines | static GPUVertFormat *get_custom_normals_format() | ||||
| if (format.attr_len == 0) { | if (format.attr_len == 0) { | ||||
| GPU_vertformat_attr_add(&format, "nor", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); | GPU_vertformat_attr_add(&format, "nor", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); | ||||
| GPU_vertformat_alias_add(&format, "lnor"); | GPU_vertformat_alias_add(&format, "lnor"); | ||||
| } | } | ||||
| return &format; | return &format; | ||||
| } | } | ||||
| static void extract_pos_nor_init_subdiv(const DRWSubdivCache *subdiv_cache, | static void extract_pos_nor_init_subdiv(const DRWSubdivCache *subdiv_cache, | ||||
| const MeshRenderData *mr, | const MeshRenderData *UNUSED(mr), | ||||
| struct MeshBatchCache *UNUSED(cache), | struct MeshBatchCache *UNUSED(cache), | ||||
| void *buffer, | void *buffer, | ||||
| void *UNUSED(data)) | void *UNUSED(data)) | ||||
| { | { | ||||
| GPUVertBuf *vbo = static_cast<GPUVertBuf *>(buffer); | GPUVertBuf *vbo = static_cast<GPUVertBuf *>(buffer); | ||||
| const DRWSubdivLooseGeom &loose_geom = subdiv_cache->loose_geom; | |||||
| /* Initialize the vertex buffer, it was already allocated. */ | /* Initialize the vertex buffer, it was already allocated. */ | ||||
| GPU_vertbuf_init_build_on_device( | 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); | draw_subdiv_extract_pos_nor(subdiv_cache, vbo); | ||||
| if (subdiv_cache->use_custom_loop_normals) { | if (subdiv_cache->use_custom_loop_normals) { | ||||
| Mesh *coarse_mesh = subdiv_cache->mesh; | Mesh *coarse_mesh = subdiv_cache->mesh; | ||||
| float(*lnors)[3] = static_cast<float(*)[3]>( | float(*lnors)[3] = static_cast<float(*)[3]>( | ||||
| CustomData_get_layer(&coarse_mesh->ldata, CD_NORMAL)); | CustomData_get_layer(&coarse_mesh->ldata, CD_NORMAL)); | ||||
| BLI_assert(lnors != NULL); | BLI_assert(lnors != NULL); | ||||
| Show All 36 Lines | else { | ||||
| draw_subdiv_finalize_normals(subdiv_cache, vertex_normals, subdiv_loop_subdiv_vert_index, vbo); | draw_subdiv_finalize_normals(subdiv_cache, vertex_normals, subdiv_loop_subdiv_vert_index, vbo); | ||||
| GPU_vertbuf_discard(vertex_normals); | GPU_vertbuf_discard(vertex_normals); | ||||
| GPU_vertbuf_discard(subdiv_loop_subdiv_vert_index); | GPU_vertbuf_discard(subdiv_loop_subdiv_vert_index); | ||||
| } | } | ||||
| } | } | ||||
| static void extract_pos_nor_loose_geom_subdiv(const DRWSubdivCache *subdiv_cache, | static void extract_pos_nor_loose_geom_subdiv(const DRWSubdivCache *subdiv_cache, | ||||
| const MeshRenderData *mr, | const MeshRenderData *UNUSED(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 offset = subdiv_cache->num_subdiv_loops; | uint offset = subdiv_cache->num_subdiv_loops; | ||||
| /* TODO(kevindietrich) : replace this when compressed normals are supported. */ | /* TODO(kevindietrich) : replace this when compressed normals are supported. */ | ||||
| struct SubdivPosNorLoop { | struct SubdivPosNorLoop { | ||||
| float pos[3]; | float pos[3]; | ||||
| float nor[3]; | float nor[3]; | ||||
| float flag; | float flag; | ||||
| }; | }; | ||||
| if (mr->extract_type == MR_EXTRACT_MESH) { | /* Make sure buffer is active for sending loose data. */ | ||||
| const Mesh *coarse_mesh = subdiv_cache->mesh; | GPU_vertbuf_use(vbo); | ||||
| const MEdge *coarse_edges = coarse_mesh->medge; | |||||
| const MVert *coarse_verts = coarse_mesh->mvert; | |||||
| SubdivPosNorLoop edge_data[2]; | blender::Span<DRWSubdivLooseEdge> loose_edges = draw_subdiv_cache_get_loose_edges(subdiv_cache); | ||||
| 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]; | |||||
| copy_v3_v3(edge_data[0].pos, loose_vert1->co); | |||||
| copy_v3_v3(edge_data[1].pos, loose_vert2->co); | |||||
| GPU_vertbuf_update_sub( | |||||
| vbo, offset * sizeof(SubdivPosNorLoop), sizeof(SubdivPosNorLoop) * 2, &edge_data); | |||||
| 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(vert_data.pos, loose_vertex->co); | |||||
| GPU_vertbuf_update_sub( | |||||
| vbo, offset * sizeof(SubdivPosNorLoop), sizeof(SubdivPosNorLoop), &vert_data); | |||||
| offset += 1; | |||||
| } | |||||
| } | |||||
| else { | |||||
| BMesh *bm = subdiv_cache->bm; | |||||
| SubdivPosNorLoop edge_data[2]; | SubdivPosNorLoop edge_data[2]; | ||||
| memset(&edge_data, 0, sizeof(SubdivPosNorLoop) * 2); | memset(edge_data, 0, sizeof(SubdivPosNorLoop) * 2); | ||||
| for (int i = 0; i < loose_geom->edge_len; i++) { | for (const DRWSubdivLooseEdge &loose_edge : loose_edges) { | ||||
| const BMEdge *loose_edge = BM_edge_at_index(bm, loose_geom->edges[i]); | const DRWSubdivLooseVertex &v1 = loose_geom.verts[loose_edge.loose_subdiv_v1_index]; | ||||
| const BMVert *loose_vert1 = loose_edge->v1; | const DRWSubdivLooseVertex &v2 = loose_geom.verts[loose_edge.loose_subdiv_v2_index]; | ||||
| 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[0].pos, v1.co); | ||||
| copy_v3_v3(edge_data[1].nor, loose_vert2->no); | copy_v3_v3(edge_data[1].pos, v2.co); | ||||
| GPU_vertbuf_update_sub( | GPU_vertbuf_update_sub( | ||||
| vbo, offset * sizeof(SubdivPosNorLoop), sizeof(SubdivPosNorLoop) * 2, &edge_data); | vbo, offset * sizeof(SubdivPosNorLoop), sizeof(SubdivPosNorLoop) * 2, &edge_data); | ||||
| offset += 2; | offset += 2; | ||||
| } | } | ||||
| SubdivPosNorLoop vert_data; | SubdivPosNorLoop vert_data; | ||||
| memset(&vert_data, 0, sizeof(SubdivPosNorLoop)); | memset(&vert_data, 0, sizeof(SubdivPosNorLoop)); | ||||
| for (int i = 0; i < loose_geom->vert_len; i++) { | blender::Span<DRWSubdivLooseVertex> loose_verts = draw_subdiv_cache_get_loose_verts( | ||||
| const BMVert *loose_vertex = BM_vert_at_index(bm, loose_geom->verts[i]); | subdiv_cache); | ||||
| copy_v3_v3(vert_data.pos, loose_vertex->co); | for (const DRWSubdivLooseVertex &loose_vert : loose_verts) { | ||||
| copy_v3_v3(vert_data.nor, loose_vertex->no); | copy_v3_v3(vert_data.pos, loose_vert.co); | ||||
| GPU_vertbuf_update_sub( | GPU_vertbuf_update_sub( | ||||
| vbo, offset * sizeof(SubdivPosNorLoop), sizeof(SubdivPosNorLoop), &vert_data); | vbo, offset * sizeof(SubdivPosNorLoop), sizeof(SubdivPosNorLoop), &vert_data); | ||||
| offset += 1; | offset += 1; | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| constexpr MeshExtract create_extractor_pos_nor() | constexpr MeshExtract create_extractor_pos_nor() | ||||
| { | { | ||||
| MeshExtract extractor = {nullptr}; | MeshExtract extractor = {nullptr}; | ||||
| extractor.init = extract_pos_nor_init; | extractor.init = extract_pos_nor_init; | ||||
| extractor.iter_poly_bm = extract_pos_nor_iter_poly_bm; | extractor.iter_poly_bm = extract_pos_nor_iter_poly_bm; | ||||
| extractor.iter_poly_mesh = extract_pos_nor_iter_poly_mesh; | extractor.iter_poly_mesh = extract_pos_nor_iter_poly_mesh; | ||||
| extractor.iter_ledge_bm = extract_pos_nor_iter_ledge_bm; | extractor.iter_ledge_bm = extract_pos_nor_iter_ledge_bm; | ||||
| ▲ Show 20 Lines • Show All 214 Lines • Show Last 20 Lines | |||||