Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/draw_cache_extract_mesh.c
| Show First 20 Lines • Show All 628 Lines • ▼ Show 20 Lines | static void extract_lines_ledge_mesh(const MeshRenderData *mr, | ||||
| } | } | ||||
| else { | else { | ||||
| GPU_indexbuf_set_line_restart(elb, ledge_idx); | GPU_indexbuf_set_line_restart(elb, ledge_idx); | ||||
| } | } | ||||
| /* Don't render the edge twice. */ | /* Don't render the edge twice. */ | ||||
| GPU_indexbuf_set_line_restart(elb, edge_idx); | GPU_indexbuf_set_line_restart(elb, edge_idx); | ||||
| } | } | ||||
| static void extract_lines_finish(const MeshRenderData *mr, void *ibo, void *elb) | static void extract_lines_finish(const MeshRenderData *UNUSED(mr), void *ibo, void *elb) | ||||
| { | { | ||||
| GPU_indexbuf_build_in_place(elb, ibo); | GPU_indexbuf_build_in_place(elb, ibo); | ||||
| MEM_freeN(elb); | MEM_freeN(elb); | ||||
| /* HACK Create ibo subranges and assign them to GPUBatch. */ | |||||
| if (mr->use_final_mesh && mr->cache->batch.loose_edges) { | |||||
| BLI_assert(mr->cache->batch.loose_edges->elem == ibo); | |||||
| /* Multiply by 2 because these are edges indices. */ | |||||
| int start = mr->edge_len * 2; | |||||
| int len = mr->edge_loose_len * 2; | |||||
| GPUIndexBuf *sub_ibo = GPU_indexbuf_create_subrange(ibo, start, len); | |||||
| /* WARNING: We modify the GPUBatch here! */ | |||||
| GPU_batch_elembuf_set(mr->cache->batch.loose_edges, sub_ibo, true); | |||||
| mr->cache->no_loose_wire = (len == 0); | |||||
| } | |||||
| } | } | ||||
| static const MeshExtract extract_lines = { | static const MeshExtract extract_lines = { | ||||
| extract_lines_init, | extract_lines_init, | ||||
| NULL, | NULL, | ||||
| NULL, | NULL, | ||||
| extract_lines_loop_bmesh, | extract_lines_loop_bmesh, | ||||
| extract_lines_loop_mesh, | extract_lines_loop_mesh, | ||||
| extract_lines_ledge_bmesh, | extract_lines_ledge_bmesh, | ||||
| extract_lines_ledge_mesh, | extract_lines_ledge_mesh, | ||||
| NULL, | NULL, | ||||
| NULL, | NULL, | ||||
| extract_lines_finish, | extract_lines_finish, | ||||
| 0, | 0, | ||||
| false, | false, | ||||
| }; | }; | ||||
| /** \} */ | /** \} */ | ||||
| /* ---------------------------------------------------------------------- */ | /* ---------------------------------------------------------------------- */ | ||||
| /** \name Extract Loose Edges Indices | |||||
| * \{ */ | |||||
| static void *extract_lines_loose_init(const MeshRenderData *UNUSED(mr), void *UNUSED(buf)) | |||||
| { | |||||
| return NULL; | |||||
| } | |||||
| static void extract_lines_loose_ledge_mesh(const MeshRenderData *UNUSED(mr), | |||||
| int UNUSED(e), | |||||
| const MEdge *UNUSED(medge), | |||||
| void *UNUSED(elb)) | |||||
| { | |||||
| /* This function is intentionally empty. The existence of this functions ensures that | |||||
| * `iter_type` `MR_ITER_LVERT` is set when initializing the `MeshRenderData` (See | |||||
| * `mesh_extract_iter_type`). This flag ensures that `mr->edge_loose_len` field is filled. This | |||||
| * field we use in the `extract_lines_loose_finish` function to create a subrange from the | |||||
| * `ibo.lines`. */ | |||||
| } | |||||
| static void extract_lines_loose_finish(const MeshRenderData *mr, | |||||
| void *UNUSED(ibo), | |||||
| void *UNUSED(elb)) | |||||
| { | |||||
| /* Multiply by 2 because these are edges indices. */ | |||||
| const int start = mr->edge_len * 2; | |||||
| const int len = mr->edge_loose_len * 2; | |||||
| GPU_indexbuf_create_subrange_in_place( | |||||
| mr->cache->final.ibo.lines_loose, mr->cache->final.ibo.lines, start, len); | |||||
| mr->cache->no_loose_wire = (len == 0); | |||||
| } | |||||
| static const MeshExtract extract_lines_loose = { | |||||
| extract_lines_loose_init, | |||||
| NULL, | |||||
| NULL, | |||||
| NULL, | |||||
| NULL, | |||||
| NULL, | |||||
| extract_lines_loose_ledge_mesh, | |||||
| NULL, | |||||
| NULL, | |||||
| extract_lines_loose_finish, | |||||
| 0, | |||||
| false, | |||||
| }; | |||||
| /** \} */ | |||||
| /* ---------------------------------------------------------------------- */ | |||||
| /** \name Extract Point Indices | /** \name Extract Point Indices | ||||
| * \{ */ | * \{ */ | ||||
| static void *extract_points_init(const MeshRenderData *mr, void *UNUSED(buf)) | static void *extract_points_init(const MeshRenderData *mr, void *UNUSED(buf)) | ||||
| { | { | ||||
| GPUIndexBufBuilder *elb = MEM_mallocN(sizeof(*elb), __func__); | GPUIndexBufBuilder *elb = MEM_mallocN(sizeof(*elb), __func__); | ||||
| GPU_indexbuf_init(elb, GPU_PRIM_POINTS, mr->vert_len, mr->loop_len + mr->loop_loose_len); | GPU_indexbuf_init(elb, GPU_PRIM_POINTS, mr->vert_len, mr->loop_len + mr->loop_loose_len); | ||||
| return elb; | return elb; | ||||
| ▲ Show 20 Lines • Show All 3,685 Lines • ▼ Show 20 Lines | #define TEST_ASSIGN(type, type_lowercase, name) \ | ||||
| TEST_ASSIGN(VBO, vbo, skin_roots); | TEST_ASSIGN(VBO, vbo, skin_roots); | ||||
| TEST_ASSIGN(IBO, ibo, tris); | TEST_ASSIGN(IBO, ibo, tris); | ||||
| TEST_ASSIGN(IBO, ibo, lines); | TEST_ASSIGN(IBO, ibo, lines); | ||||
| TEST_ASSIGN(IBO, ibo, points); | TEST_ASSIGN(IBO, ibo, points); | ||||
| TEST_ASSIGN(IBO, ibo, fdots); | TEST_ASSIGN(IBO, ibo, fdots); | ||||
| TEST_ASSIGN(IBO, ibo, lines_paint_mask); | TEST_ASSIGN(IBO, ibo, lines_paint_mask); | ||||
| TEST_ASSIGN(IBO, ibo, lines_adjacency); | TEST_ASSIGN(IBO, ibo, lines_adjacency); | ||||
| TEST_ASSIGN(IBO, ibo, lines_loose); | |||||
| TEST_ASSIGN(IBO, ibo, edituv_tris); | TEST_ASSIGN(IBO, ibo, edituv_tris); | ||||
| TEST_ASSIGN(IBO, ibo, edituv_lines); | TEST_ASSIGN(IBO, ibo, edituv_lines); | ||||
| TEST_ASSIGN(IBO, ibo, edituv_points); | TEST_ASSIGN(IBO, ibo, edituv_points); | ||||
| TEST_ASSIGN(IBO, ibo, edituv_fdots); | TEST_ASSIGN(IBO, ibo, edituv_fdots); | ||||
| #undef TEST_ASSIGN | #undef TEST_ASSIGN | ||||
| #ifdef DEBUG_TIME | #ifdef DEBUG_TIME | ||||
| ▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | |||||
| #undef EXTRACT | #undef EXTRACT | ||||
| /* TODO(fclem) Ideally, we should have one global pool for all | /* TODO(fclem) Ideally, we should have one global pool for all | ||||
| * objects and wait for finish only before drawing when buffers | * objects and wait for finish only before drawing when buffers | ||||
| * need to be ready. */ | * need to be ready. */ | ||||
| BLI_task_pool_work_and_wait(task_pool); | BLI_task_pool_work_and_wait(task_pool); | ||||
| BLI_task_pool_free(task_pool); | BLI_task_pool_free(task_pool); | ||||
| /* The `lines_loose` is a sub buffer from `ibo.lines`. | |||||
| * We don't use the extract mechanism due to potential synchronization issues.*/ | |||||
| if (mbc.ibo.lines_loose) { | |||||
| extract_task_create(NULL, mr, &extract_lines_loose, mbc.ibo.lines_loose, task_counters); | |||||
| } | |||||
| MEM_freeN(task_counters); | MEM_freeN(task_counters); | ||||
| mesh_render_data_free(mr); | mesh_render_data_free(mr); | ||||
| #ifdef DEBUG_TIME | #ifdef DEBUG_TIME | ||||
| double end = PIL_check_seconds_timer(); | double end = PIL_check_seconds_timer(); | ||||
| static double avg = 0; | static double avg = 0; | ||||
| Show All 20 Lines | |||||