Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/draw_cache_impl_mesh.c
| Show First 20 Lines • Show All 1,640 Lines • ▼ Show 20 Lines | typedef struct MeshBatchCache { | ||||
| bool is_maybe_dirty; | bool is_maybe_dirty; | ||||
| bool is_dirty; /* Instantly invalidates cache, skipping mesh check */ | bool is_dirty; /* Instantly invalidates cache, skipping mesh check */ | ||||
| int edge_len; | int edge_len; | ||||
| int tri_len; | int tri_len; | ||||
| int poly_len; | int poly_len; | ||||
| int vert_len; | int vert_len; | ||||
| int mat_len; | int mat_len; | ||||
| bool is_editmode; | bool is_editmode; | ||||
| int vertex_group_index; | |||||
| /* XXX, only keep for as long as sculpt mode uses shaded drawing. */ | /* XXX, only keep for as long as sculpt mode uses shaded drawing. */ | ||||
| bool is_sculpt_points_tag; | bool is_sculpt_points_tag; | ||||
| /* Valid only if edges_adjacency is up to date. */ | /* Valid only if edges_adjacency is up to date. */ | ||||
| bool is_manifold; | bool is_manifold; | ||||
| } MeshBatchCache; | } MeshBatchCache; | ||||
| ▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | if (cache->is_editmode == false) { | ||||
| cache->poly_len = mesh_render_polys_len_get(me); | cache->poly_len = mesh_render_polys_len_get(me); | ||||
| cache->vert_len = mesh_render_verts_len_get(me); | cache->vert_len = mesh_render_verts_len_get(me); | ||||
| } | } | ||||
| cache->mat_len = mesh_render_mat_len_get(me); | cache->mat_len = mesh_render_mat_len_get(me); | ||||
| cache->is_maybe_dirty = false; | cache->is_maybe_dirty = false; | ||||
| cache->is_dirty = false; | cache->is_dirty = false; | ||||
| cache->vertex_group_index = -1; | |||||
| } | } | ||||
| static MeshBatchCache *mesh_batch_cache_get(Mesh *me) | static MeshBatchCache *mesh_batch_cache_get(Mesh *me) | ||||
| { | { | ||||
| if (!mesh_batch_cache_valid(me)) { | if (!mesh_batch_cache_valid(me)) { | ||||
| mesh_batch_cache_clear(me); | mesh_batch_cache_clear(me); | ||||
| mesh_batch_cache_init(me); | mesh_batch_cache_init(me); | ||||
| } | } | ||||
| return me->runtime.batch_cache; | return me->runtime.batch_cache; | ||||
| } | } | ||||
| static MeshBatchCache *mesh_batch_cache_get__check_vertex_group(Mesh *me, int defgroup) | |||||
| { | |||||
| MeshBatchCache *cache = mesh_batch_cache_get(me); | |||||
| if (cache->vertex_group_index != defgroup) { | |||||
| cache->is_dirty = true; | |||||
| } | |||||
| return mesh_batch_cache_get(me); | |||||
| } | |||||
| static void mesh_batch_cache_discard_shaded_tri(MeshBatchCache *cache) | static void mesh_batch_cache_discard_shaded_tri(MeshBatchCache *cache) | ||||
| { | { | ||||
| GPU_VERTBUF_DISCARD_SAFE(cache->shaded_triangles_data); | GPU_VERTBUF_DISCARD_SAFE(cache->shaded_triangles_data); | ||||
| if (cache->shaded_triangles_in_order) { | if (cache->shaded_triangles_in_order) { | ||||
| for (int i = 0; i < cache->mat_len; ++i) { | for (int i = 0; i < cache->mat_len; ++i) { | ||||
| GPU_INDEXBUF_DISCARD_SAFE(cache->shaded_triangles_in_order[i]); | GPU_INDEXBUF_DISCARD_SAFE(cache->shaded_triangles_in_order[i]); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 2,109 Lines • ▼ Show 20 Lines | if (cache->ledges_with_normals == NULL) { | ||||
| mesh_render_data_free(rdata); | mesh_render_data_free(rdata); | ||||
| } | } | ||||
| return cache->ledges_with_normals; | return cache->ledges_with_normals; | ||||
| } | } | ||||
| GPUBatch *DRW_mesh_batch_cache_get_triangles_with_normals_and_weights(Mesh *me, int defgroup) | GPUBatch *DRW_mesh_batch_cache_get_triangles_with_normals_and_weights(Mesh *me, int defgroup) | ||||
| { | { | ||||
| MeshBatchCache *cache = mesh_batch_cache_get(me); | MeshBatchCache *cache = mesh_batch_cache_get__check_vertex_group(me, defgroup); | ||||
| if (cache->triangles_with_weights == NULL) { | if (cache->triangles_with_weights == NULL) { | ||||
| const bool use_hide = (me->editflag & (ME_EDIT_PAINT_VERT_SEL | ME_EDIT_PAINT_FACE_SEL)) != 0; | const bool use_hide = (me->editflag & (ME_EDIT_PAINT_VERT_SEL | ME_EDIT_PAINT_FACE_SEL)) != 0; | ||||
| const int datatype = | const int datatype = | ||||
| MR_DATATYPE_VERT | MR_DATATYPE_LOOPTRI | MR_DATATYPE_LOOP | MR_DATATYPE_POLY | MR_DATATYPE_DVERT; | MR_DATATYPE_VERT | MR_DATATYPE_LOOPTRI | MR_DATATYPE_LOOP | MR_DATATYPE_POLY | MR_DATATYPE_DVERT; | ||||
| MeshRenderData *rdata = mesh_render_data_create(me, datatype); | MeshRenderData *rdata = mesh_render_data_create(me, datatype); | ||||
| cache->triangles_with_weights = GPU_batch_create_ex( | cache->triangles_with_weights = GPU_batch_create_ex( | ||||
| GPU_PRIM_TRIS, mesh_create_tri_weights(rdata, use_hide, defgroup), NULL, GPU_BATCH_OWNS_VBO); | GPU_PRIM_TRIS, mesh_create_tri_weights(rdata, use_hide, defgroup), NULL, GPU_BATCH_OWNS_VBO); | ||||
| cache->vertex_group_index = defgroup; | |||||
| GPUVertBuf *vbo_tris = use_hide ? | GPUVertBuf *vbo_tris = use_hide ? | ||||
| mesh_create_tri_pos_and_normals_visible_only(rdata) : | mesh_create_tri_pos_and_normals_visible_only(rdata) : | ||||
| mesh_batch_cache_get_tri_pos_and_normals(rdata, cache); | mesh_batch_cache_get_tri_pos_and_normals(rdata, cache); | ||||
| GPU_batch_vertbuf_add_ex(cache->triangles_with_weights, vbo_tris, use_hide); | GPU_batch_vertbuf_add_ex(cache->triangles_with_weights, vbo_tris, use_hide); | ||||
| mesh_render_data_free(rdata); | mesh_render_data_free(rdata); | ||||
| ▲ Show 20 Lines • Show All 594 Lines • Show Last 20 Lines | |||||