DWM: reuse position VBO for vpaint select overlay
This commit is contained in:
@@ -1460,6 +1460,7 @@ typedef struct MeshBatchCache {
|
||||
VertexBuffer *nor_in_order;
|
||||
ElementList *edges_in_order;
|
||||
ElementList *triangles_in_order;
|
||||
ElementList *overlay_triangles_vpaint;
|
||||
|
||||
Batch *all_verts;
|
||||
Batch *all_edges;
|
||||
@@ -1471,7 +1472,6 @@ typedef struct MeshBatchCache {
|
||||
VertexBuffer *tri_aligned_vert_colors;
|
||||
VertexBuffer *tri_aligned_select_id;
|
||||
VertexBuffer *edge_pos_with_select_bool;
|
||||
VertexBuffer *tri_pos_with_unselect_only;
|
||||
VertexBuffer *pos_with_select_bool;
|
||||
Batch *triangles_with_normals;
|
||||
|
||||
@@ -1515,9 +1515,9 @@ typedef struct MeshBatchCache {
|
||||
Batch *overlay_loose_verts;
|
||||
Batch *overlay_facedots;
|
||||
|
||||
Batch *overlay_paint_edges;
|
||||
Batch *overlay_weight_faces;
|
||||
Batch *overlay_weight_verts;
|
||||
Batch *overlay_paint_edges;
|
||||
|
||||
/* settings to determine if cache is invalid */
|
||||
bool is_dirty;
|
||||
@@ -1651,6 +1651,7 @@ static void mesh_batch_cache_clear(Mesh *me)
|
||||
VERTEXBUFFER_DISCARD_SAFE(cache->pos_in_order);
|
||||
ELEMENTLIST_DISCARD_SAFE(cache->edges_in_order);
|
||||
ELEMENTLIST_DISCARD_SAFE(cache->triangles_in_order);
|
||||
ELEMENTLIST_DISCARD_SAFE(cache->overlay_triangles_vpaint);
|
||||
|
||||
VERTEXBUFFER_DISCARD_SAFE(cache->ed_tri_pos);
|
||||
VERTEXBUFFER_DISCARD_SAFE(cache->ed_tri_nor);
|
||||
@@ -1669,10 +1670,10 @@ static void mesh_batch_cache_clear(Mesh *me)
|
||||
BATCH_DISCARD_SAFE(cache->overlay_loose_edges);
|
||||
BATCH_DISCARD_SAFE(cache->overlay_loose_edges_nor);
|
||||
|
||||
BATCH_DISCARD_ALL_SAFE(cache->overlay_facedots);
|
||||
BATCH_DISCARD_ALL_SAFE(cache->overlay_paint_edges);
|
||||
BATCH_DISCARD_ALL_SAFE(cache->overlay_weight_faces);
|
||||
BATCH_DISCARD_SAFE(cache->overlay_weight_faces);
|
||||
BATCH_DISCARD_ALL_SAFE(cache->overlay_weight_verts);
|
||||
BATCH_DISCARD_ALL_SAFE(cache->overlay_paint_edges);
|
||||
BATCH_DISCARD_ALL_SAFE(cache->overlay_facedots);
|
||||
|
||||
BATCH_DISCARD_SAFE(cache->triangles_with_normals);
|
||||
BATCH_DISCARD_SAFE(cache->points_with_normals);
|
||||
@@ -2681,49 +2682,30 @@ static VertexBuffer *mesh_batch_cache_get_edge_pos_with_sel(
|
||||
return cache->edge_pos_with_select_bool;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO, reuse pos VBO with elements.
|
||||
*/
|
||||
static VertexBuffer *mesh_batch_cache_get_tri_pos_with_unselect_only(
|
||||
static ElementList *mesh_batch_cache_get_tri_overlay_weight_faces(
|
||||
MeshRenderData *rdata, MeshBatchCache *cache)
|
||||
{
|
||||
BLI_assert(rdata->types & (MR_DATATYPE_VERT | MR_DATATYPE_POLY | MR_DATATYPE_LOOP | MR_DATATYPE_LOOPTRI));
|
||||
BLI_assert(rdata->edit_bmesh == NULL);
|
||||
|
||||
if (cache->tri_pos_with_unselect_only == NULL) {
|
||||
unsigned int vidx = 0;
|
||||
|
||||
static VertexFormat format = { 0 };
|
||||
static struct { uint pos; } attr_id;
|
||||
if (format.attrib_ct == 0) {
|
||||
attr_id.pos = VertexFormat_add_attrib(&format, "pos", COMP_F32, 3, KEEP_FLOAT);
|
||||
}
|
||||
BLI_assert(rdata->types & (MR_DATATYPE_VERT | MR_DATATYPE_LOOPTRI));
|
||||
|
||||
if (cache->overlay_triangles_vpaint == NULL) {
|
||||
const int vert_len = mesh_render_data_verts_len_get(rdata);
|
||||
const int tri_len = mesh_render_data_looptri_len_get(rdata);
|
||||
|
||||
VertexBuffer *vbo = cache->tri_pos_with_unselect_only = VertexBuffer_create_with_format(&format);
|
||||
ElementListBuilder elb;
|
||||
ElementListBuilder_init(&elb, PRIM_TRIANGLES, tri_len, vert_len);
|
||||
|
||||
const int vbo_len_capacity = tri_len * 3;
|
||||
int vbo_len_used = 0;
|
||||
VertexBuffer_allocate_data(vbo, vbo_len_capacity);
|
||||
|
||||
for (int i = 0; i < tri_len; i++) {
|
||||
for (int i = 0; i < tri_len; ++i) {
|
||||
const MLoopTri *mlt = &rdata->mlooptri[i];
|
||||
if (!(rdata->mpoly[mlt->poly].flag & (ME_FACE_SEL | ME_HIDE))) {
|
||||
for (uint tri_corner = 0; tri_corner < 3; tri_corner++) {
|
||||
const uint v_index = rdata->mloop[mlt->tri[tri_corner]].v;
|
||||
VertexBuffer_set_attrib(vbo, attr_id.pos, vidx++, rdata->mvert[v_index].co);
|
||||
add_generic_vertex(&elb, rdata->mloop[mlt->tri[tri_corner]].v);
|
||||
}
|
||||
}
|
||||
}
|
||||
vbo_len_used = vidx;
|
||||
|
||||
if (vbo_len_capacity != vbo_len_used) {
|
||||
VertexBuffer_resize_data(vbo, vbo_len_used);
|
||||
}
|
||||
cache->overlay_triangles_vpaint = ElementList_build(&elb);
|
||||
}
|
||||
|
||||
return cache->tri_pos_with_unselect_only;
|
||||
return cache->overlay_triangles_vpaint;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3231,7 +3213,8 @@ Batch *DRW_mesh_batch_cache_get_weight_overlay_faces(Mesh *me)
|
||||
MeshRenderData *rdata = mesh_render_data_create(me, datatype);
|
||||
|
||||
cache->overlay_weight_faces = Batch_create(
|
||||
PRIM_TRIANGLES, mesh_batch_cache_get_tri_pos_with_unselect_only(rdata, cache), NULL);
|
||||
PRIM_TRIANGLES, mesh_batch_cache_get_vert_pos_and_nor_in_order(rdata, cache),
|
||||
mesh_batch_cache_get_tri_overlay_weight_faces(rdata, cache));
|
||||
|
||||
mesh_render_data_free(rdata);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user