Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/draw_cache_impl_mesh.c
| Show First 20 Lines • Show All 1,905 Lines • ▼ Show 20 Lines | typedef struct MeshBatchCache { | ||||
| * might differ. */ | * might differ. */ | ||||
| struct { | struct { | ||||
| /* TODO(fclem): Reuse ordered.loop_pos_nor and maybe even | /* TODO(fclem): Reuse ordered.loop_pos_nor and maybe even | ||||
| * ordered.loop_uv_tan when cage match final mesh. */ | * ordered.loop_uv_tan when cage match final mesh. */ | ||||
| GPUVertBuf *loop_pos_nor; | GPUVertBuf *loop_pos_nor; | ||||
| GPUVertBuf *loop_data; | GPUVertBuf *loop_data; | ||||
| GPUVertBuf *loop_lnor; | GPUVertBuf *loop_lnor; | ||||
| GPUVertBuf *facedots_pos_nor_data; | GPUVertBuf *facedots_pos_nor_data; | ||||
| GPUVertBuf *loop_mesh_analysis; | |||||
fclem: If data is per loop use loop_ prefix | |||||
| /* UV data without modifier applied. | /* UV data without modifier applied. | ||||
| * Vertex count is always the one of the cage. */ | * Vertex count is always the one of the cage. */ | ||||
| GPUVertBuf *loop_uv; | GPUVertBuf *loop_uv; | ||||
| GPUVertBuf *loop_uv_data; | GPUVertBuf *loop_uv_data; | ||||
| GPUVertBuf *loop_stretch_angle; | GPUVertBuf *loop_stretch_angle; | ||||
| GPUVertBuf *loop_stretch_area; | GPUVertBuf *loop_stretch_area; | ||||
| GPUVertBuf *facedots_uv; | GPUVertBuf *facedots_uv; | ||||
| GPUVertBuf *facedots_uv_data; | GPUVertBuf *facedots_uv_data; | ||||
| Show All 31 Lines | struct { | ||||
| GPUBatch *surface; | GPUBatch *surface; | ||||
| GPUBatch *surface_weights; | GPUBatch *surface_weights; | ||||
| /* Edit mode */ | /* Edit mode */ | ||||
| GPUBatch *edit_triangles; | GPUBatch *edit_triangles; | ||||
| GPUBatch *edit_vertices; | GPUBatch *edit_vertices; | ||||
| GPUBatch *edit_edges; | GPUBatch *edit_edges; | ||||
| GPUBatch *edit_lnor; | GPUBatch *edit_lnor; | ||||
| GPUBatch *edit_facedots; | GPUBatch *edit_facedots; | ||||
| GPUBatch *edit_mesh_analysis; | |||||
Done Inline ActionsUse edit_mesh_analysis instead fclem: Use edit_mesh_analysis instead | |||||
| /* Edit UVs */ | /* Edit UVs */ | ||||
| GPUBatch *edituv_faces_strech_area; | GPUBatch *edituv_faces_strech_area; | ||||
| GPUBatch *edituv_faces_strech_angle; | GPUBatch *edituv_faces_strech_angle; | ||||
| GPUBatch *edituv_faces; | GPUBatch *edituv_faces; | ||||
| GPUBatch *edituv_edges; | GPUBatch *edituv_edges; | ||||
| GPUBatch *edituv_verts; | GPUBatch *edituv_verts; | ||||
| GPUBatch *edituv_facedots; | GPUBatch *edituv_facedots; | ||||
| /* Edit selection */ | /* Edit selection */ | ||||
| ▲ Show 20 Lines • Show All 195 Lines • ▼ Show 20 Lines | case BKE_MESH_BATCH_DIRTY_MAYBE_ALL: | ||||
| break; | break; | ||||
| case BKE_MESH_BATCH_DIRTY_SELECT: | case BKE_MESH_BATCH_DIRTY_SELECT: | ||||
| GPU_VERTBUF_DISCARD_SAFE(cache->edit.loop_data); | GPU_VERTBUF_DISCARD_SAFE(cache->edit.loop_data); | ||||
| GPU_VERTBUF_DISCARD_SAFE(cache->edit.facedots_pos_nor_data); | GPU_VERTBUF_DISCARD_SAFE(cache->edit.facedots_pos_nor_data); | ||||
| GPU_BATCH_DISCARD_SAFE(cache->batch.edit_triangles); | GPU_BATCH_DISCARD_SAFE(cache->batch.edit_triangles); | ||||
| GPU_BATCH_DISCARD_SAFE(cache->batch.edit_vertices); | GPU_BATCH_DISCARD_SAFE(cache->batch.edit_vertices); | ||||
| GPU_BATCH_DISCARD_SAFE(cache->batch.edit_edges); | GPU_BATCH_DISCARD_SAFE(cache->batch.edit_edges); | ||||
| GPU_BATCH_DISCARD_SAFE(cache->batch.edit_facedots); | GPU_BATCH_DISCARD_SAFE(cache->batch.edit_facedots); | ||||
| GPU_BATCH_DISCARD_SAFE(cache->batch.edit_mesh_analysis); | |||||
| /* Paint mode selection */ | /* Paint mode selection */ | ||||
| /* TODO only do that in paint mode. */ | /* TODO only do that in paint mode. */ | ||||
| GPU_VERTBUF_DISCARD_SAFE(cache->ordered.loop_pos_nor); | GPU_VERTBUF_DISCARD_SAFE(cache->ordered.loop_pos_nor); | ||||
| GPU_BATCH_DISCARD_SAFE(cache->batch.surface); | GPU_BATCH_DISCARD_SAFE(cache->batch.surface); | ||||
| GPU_BATCH_DISCARD_SAFE(cache->batch.wire_loops); | GPU_BATCH_DISCARD_SAFE(cache->batch.wire_loops); | ||||
| if (cache->surf_per_mat) { | if (cache->surf_per_mat) { | ||||
| for (int i = 0; i < cache->mat_len; i++) { | for (int i = 0; i < cache->mat_len; i++) { | ||||
| GPU_BATCH_DISCARD_SAFE(cache->surf_per_mat[i]); | GPU_BATCH_DISCARD_SAFE(cache->surf_per_mat[i]); | ||||
| ▲ Show 20 Lines • Show All 1,198 Lines • ▼ Show 20 Lines | #endif | ||||
| /* Resize & Finish */ | /* Resize & Finish */ | ||||
| if (facedot_len_used != verts_facedot_len) { | if (facedot_len_used != verts_facedot_len) { | ||||
| if (vbo_facedots_pos_nor_data != NULL) { | if (vbo_facedots_pos_nor_data != NULL) { | ||||
| GPU_vertbuf_data_resize(vbo_facedots_pos_nor_data, facedot_len_used); | GPU_vertbuf_data_resize(vbo_facedots_pos_nor_data, facedot_len_used); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void mesh_create_edit_mesh_analysis(MeshRenderData *rdata, | |||||
| GPUVertBuf *vbo_mesh_analysis) | |||||
| { | |||||
| const MeshStatVis *mesh_stat_vis = &rdata->toolsettings->statvis; | |||||
| int mesh_analysis_len_used = 0; | |||||
| const uint loops_len = mesh_render_data_loops_len_get(rdata); | |||||
| BMesh *bm = rdata->edit_bmesh->bm; | |||||
| BMIter iter_efa, iter_loop; | |||||
| BMFace *efa; | |||||
| BMLoop *loop; | |||||
| static struct { | |||||
| uint weight; | |||||
| } attr_id; | |||||
| static GPUVertFormat mesh_analysis_format = {0}; | |||||
| if (mesh_analysis_format.attr_len == 0) { | |||||
| attr_id.weight = GPU_vertformat_attr_add( | |||||
| &mesh_analysis_format, "weight_color", GPU_COMP_U8, 4, GPU_FETCH_INT_TO_FLOAT_UNIT); | |||||
| } | |||||
| /* TODO(jbakker): Maybe move data generation to mesh_render_data_create() */ | |||||
| BKE_editmesh_statvis_calc(rdata->edit_bmesh, rdata->edit_data, mesh_stat_vis); | |||||
| if (DRW_TEST_ASSIGN_VBO(vbo_mesh_analysis)) { | |||||
| GPU_vertbuf_init_with_format(vbo_mesh_analysis, &mesh_analysis_format); | |||||
| GPU_vertbuf_data_alloc(vbo_mesh_analysis, loops_len); | |||||
| } | |||||
| const bool is_vertex_data = mesh_stat_vis->type == SCE_STATVIS_SHARP; | |||||
| if (is_vertex_data) { | |||||
| BM_ITER_MESH (efa, &iter_efa, bm, BM_FACES_OF_MESH) { | |||||
| BM_ITER_ELEM (loop, &iter_loop, efa, BM_LOOPS_OF_FACE) { | |||||
| uint vertex_index = BM_elem_index_get(loop->v); | |||||
| GPU_vertbuf_attr_set(vbo_mesh_analysis, | |||||
| attr_id.weight, | |||||
| mesh_analysis_len_used, | |||||
| &rdata->edit_bmesh->derivedVertColor[vertex_index]); | |||||
| mesh_analysis_len_used += 1; | |||||
| } | |||||
| } | |||||
| } | |||||
| else { | |||||
| uint face_index; | |||||
| BM_ITER_MESH_INDEX (efa, &iter_efa, bm, BM_FACES_OF_MESH, face_index) { | |||||
| BM_ITER_ELEM (loop, &iter_loop, efa, BM_LOOPS_OF_FACE) { | |||||
| GPU_vertbuf_attr_set(vbo_mesh_analysis, | |||||
| attr_id.weight, | |||||
| mesh_analysis_len_used, | |||||
| &rdata->edit_bmesh->derivedFaceColor[face_index]); | |||||
| mesh_analysis_len_used += 1; | |||||
| } | |||||
| } | |||||
| } | |||||
| // Free temp data in edit bmesh | |||||
| BKE_editmesh_color_free(rdata->edit_bmesh); | |||||
| /* Resize & Finish */ | |||||
| if (mesh_analysis_len_used != loops_len) { | |||||
| if (vbo_mesh_analysis != NULL) { | |||||
| GPU_vertbuf_data_resize(vbo_mesh_analysis, mesh_analysis_len_used); | |||||
| } | |||||
| } | |||||
| } | |||||
| /* Indices */ | /* Indices */ | ||||
| #define NO_EDGE INT_MAX | #define NO_EDGE INT_MAX | ||||
| static void mesh_create_edges_adjacency_lines(MeshRenderData *rdata, | static void mesh_create_edges_adjacency_lines(MeshRenderData *rdata, | ||||
| GPUIndexBuf *ibo, | GPUIndexBuf *ibo, | ||||
| bool *r_is_manifold, | bool *r_is_manifold, | ||||
| const bool use_hide) | const bool use_hide) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 796 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| GPUBatch *DRW_mesh_batch_cache_get_wireframes_face(Mesh *me) | GPUBatch *DRW_mesh_batch_cache_get_wireframes_face(Mesh *me) | ||||
| { | { | ||||
| MeshBatchCache *cache = mesh_batch_cache_get(me); | MeshBatchCache *cache = mesh_batch_cache_get(me); | ||||
| return DRW_batch_request(&cache->batch.wire_edges); | return DRW_batch_request(&cache->batch.wire_edges); | ||||
| } | } | ||||
| GPUBatch *DRW_mesh_batch_cache_get_edit_mesh_analysis(Mesh *me) | |||||
| { | |||||
| MeshBatchCache *cache = mesh_batch_cache_get(me); | |||||
| return DRW_batch_request(&cache->batch.edit_mesh_analysis); | |||||
| } | |||||
| GPUBatch **DRW_mesh_batch_cache_get_surface_shaded(Mesh *me, | GPUBatch **DRW_mesh_batch_cache_get_surface_shaded(Mesh *me, | ||||
| struct GPUMaterial **gpumat_array, | struct GPUMaterial **gpumat_array, | ||||
| uint gpumat_array_len, | uint gpumat_array_len, | ||||
| char **auto_layer_names, | char **auto_layer_names, | ||||
| int **auto_layer_is_srgb, | int **auto_layer_is_srgb, | ||||
| int *auto_layer_count) | int *auto_layer_count) | ||||
| { | { | ||||
| MeshBatchCache *cache = mesh_batch_cache_get(me); | MeshBatchCache *cache = mesh_batch_cache_get(me); | ||||
| ▲ Show 20 Lines • Show All 687 Lines • ▼ Show 20 Lines | if (DRW_batch_requested(cache->batch.edit_lnor, GPU_PRIM_POINTS)) { | ||||
| DRW_ibo_request(cache->batch.edit_lnor, &cache->ibo.edit_loops_tris); | DRW_ibo_request(cache->batch.edit_lnor, &cache->ibo.edit_loops_tris); | ||||
| DRW_vbo_request(cache->batch.edit_lnor, &cache->edit.loop_pos_nor); | DRW_vbo_request(cache->batch.edit_lnor, &cache->edit.loop_pos_nor); | ||||
| DRW_vbo_request(cache->batch.edit_lnor, &cache->edit.loop_lnor); | DRW_vbo_request(cache->batch.edit_lnor, &cache->edit.loop_lnor); | ||||
| } | } | ||||
| if (DRW_batch_requested(cache->batch.edit_facedots, GPU_PRIM_POINTS)) { | if (DRW_batch_requested(cache->batch.edit_facedots, GPU_PRIM_POINTS)) { | ||||
| DRW_vbo_request(cache->batch.edit_facedots, &cache->edit.facedots_pos_nor_data); | DRW_vbo_request(cache->batch.edit_facedots, &cache->edit.facedots_pos_nor_data); | ||||
| } | } | ||||
| /* Mesh Analysis */ | |||||
| if (DRW_batch_requested(cache->batch.edit_mesh_analysis, GPU_PRIM_TRIS)) { | |||||
| DRW_ibo_request(cache->batch.edit_mesh_analysis, &cache->ibo.edit_loops_tris); | |||||
| DRW_vbo_request(cache->batch.edit_mesh_analysis, &cache->edit.loop_pos_nor); | |||||
| DRW_vbo_request(cache->batch.edit_mesh_analysis, &cache->edit.loop_mesh_analysis); | |||||
| } | |||||
| /* Edit UV */ | /* Edit UV */ | ||||
| if (DRW_batch_requested(cache->batch.edituv_faces, GPU_PRIM_TRI_FAN)) { | if (DRW_batch_requested(cache->batch.edituv_faces, GPU_PRIM_TRI_FAN)) { | ||||
| DRW_ibo_request(cache->batch.edituv_faces, &cache->ibo.edituv_loops_tri_fans); | DRW_ibo_request(cache->batch.edituv_faces, &cache->ibo.edituv_loops_tri_fans); | ||||
| DRW_vbo_request(cache->batch.edituv_faces, &cache->edit.loop_uv); | DRW_vbo_request(cache->batch.edituv_faces, &cache->edit.loop_uv); | ||||
| DRW_vbo_request(cache->batch.edituv_faces, &cache->edit.loop_uv_data); | DRW_vbo_request(cache->batch.edituv_faces, &cache->edit.loop_uv_data); | ||||
| } | } | ||||
| if (DRW_batch_requested(cache->batch.edituv_faces_strech_area, GPU_PRIM_TRI_FAN)) { | if (DRW_batch_requested(cache->batch.edituv_faces_strech_area, GPU_PRIM_TRI_FAN)) { | ||||
| DRW_ibo_request(cache->batch.edituv_faces_strech_area, &cache->ibo.edituv_loops_tri_fans); | DRW_ibo_request(cache->batch.edituv_faces_strech_area, &cache->ibo.edituv_loops_tri_fans); | ||||
| ▲ Show 20 Lines • Show All 136 Lines • ▼ Show 20 Lines | DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_edit_flag, | ||||
| cache->edit.loop_face_idx, | cache->edit.loop_face_idx, | ||||
| MR_DATATYPE_VERT | MR_DATATYPE_EDGE | MR_DATATYPE_LOOSE_VERT | | MR_DATATYPE_VERT | MR_DATATYPE_EDGE | MR_DATATYPE_LOOSE_VERT | | ||||
| MR_DATATYPE_LOOSE_EDGE | MR_DATATYPE_POLY | MR_DATATYPE_LOOP); | MR_DATATYPE_LOOSE_EDGE | MR_DATATYPE_POLY | MR_DATATYPE_LOOP); | ||||
| DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_edit_flag, cache->edit.facedots_idx, MR_DATATYPE_POLY); | DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_edit_flag, cache->edit.facedots_idx, MR_DATATYPE_POLY); | ||||
| DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_edit_flag, | DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_edit_flag, | ||||
| cache->edit.facedots_pos_nor_data, | cache->edit.facedots_pos_nor_data, | ||||
| MR_DATATYPE_VERT | MR_DATATYPE_LOOP | MR_DATATYPE_POLY | | MR_DATATYPE_VERT | MR_DATATYPE_LOOP | MR_DATATYPE_POLY | | ||||
| MR_DATATYPE_OVERLAY); | MR_DATATYPE_OVERLAY); | ||||
| DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_edit_flag, | |||||
| cache->edit.loop_mesh_analysis, | |||||
| MR_DATATYPE_VERT | MR_DATATYPE_LOOP | MR_DATATYPE_POLY); | |||||
| DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_edit_flag, cache->edit.loop_stretch_angle, combined_edit_flag); | DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_edit_flag, cache->edit.loop_stretch_angle, combined_edit_flag); | ||||
| DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_edit_flag, cache->edit.loop_stretch_area, combined_edit_flag); | DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_edit_flag, cache->edit.loop_stretch_area, combined_edit_flag); | ||||
| DRW_ADD_FLAG_FROM_VBO_REQUEST( | DRW_ADD_FLAG_FROM_VBO_REQUEST( | ||||
| mr_edit_flag, cache->edit.facedots_uv, combined_edit_flag | MR_DATATYPE_LOOPUV); | mr_edit_flag, cache->edit.facedots_uv, combined_edit_flag | MR_DATATYPE_LOOPUV); | ||||
| DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_edit_flag, cache->edit.facedots_uv_data, combined_edit_flag); | DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_edit_flag, cache->edit.facedots_uv_data, combined_edit_flag); | ||||
| DRW_ADD_FLAG_FROM_IBO_REQUEST(mr_edit_flag, cache->ibo.edituv_loops_points, combined_edit_flag); | DRW_ADD_FLAG_FROM_IBO_REQUEST(mr_edit_flag, cache->ibo.edituv_loops_points, combined_edit_flag); | ||||
| DRW_ADD_FLAG_FROM_IBO_REQUEST( | DRW_ADD_FLAG_FROM_IBO_REQUEST( | ||||
| mr_edit_flag, cache->ibo.edituv_loops_line_strips, combined_edit_flag); | mr_edit_flag, cache->ibo.edituv_loops_line_strips, combined_edit_flag); | ||||
| ▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | void DRW_mesh_batch_cache_create_requested( | ||||
| if (DRW_ibo_requested(cache->ibo.edit_loops_points) || | if (DRW_ibo_requested(cache->ibo.edit_loops_points) || | ||||
| DRW_ibo_requested(cache->ibo.edit_loops_lines)) { | DRW_ibo_requested(cache->ibo.edit_loops_lines)) { | ||||
| mesh_create_edit_loops_points_lines( | mesh_create_edit_loops_points_lines( | ||||
| rdata, cache->ibo.edit_loops_points, cache->ibo.edit_loops_lines); | rdata, cache->ibo.edit_loops_points, cache->ibo.edit_loops_lines); | ||||
| } | } | ||||
| if (DRW_ibo_requested(cache->ibo.edit_loops_tris)) { | if (DRW_ibo_requested(cache->ibo.edit_loops_tris)) { | ||||
| mesh_create_edit_loops_tris(rdata, cache->ibo.edit_loops_tris); | mesh_create_edit_loops_tris(rdata, cache->ibo.edit_loops_tris); | ||||
| } | } | ||||
| if (DRW_vbo_requested(cache->edit.loop_mesh_analysis)) { | |||||
Done Inline ActionsSeems like a copy paste error. will remove jbakker: Seems like a copy paste error. will remove | |||||
| mesh_create_edit_mesh_analysis(rdata, cache->edit.loop_mesh_analysis); | |||||
| } | |||||
| /* UV editor */ | /* UV editor */ | ||||
| /** | /** | ||||
| * TODO: The code and data structure is ready to support modified UV display | * TODO: The code and data structure is ready to support modified UV display | ||||
| * but the selection code for UVs needs to support it first. So for now, only | * but the selection code for UVs needs to support it first. So for now, only | ||||
| * display the cage in all cases. | * display the cage in all cases. | ||||
| */ | */ | ||||
| if (rdata && rdata->mapped.supported) { | if (rdata && rdata->mapped.supported) { | ||||
| Show All 37 Lines | |||||
If data is per loop use loop_ prefix