GPUBuffers: Save / expose material index per buffers
This commit is contained in:
@@ -88,6 +88,8 @@ void GPU_pbvh_grid_buffers_update(GPU_PBVH_Buffers *buffers,
|
||||
/* draw */
|
||||
struct GPUBatch *GPU_pbvh_buffers_batch_get(GPU_PBVH_Buffers *buffers, bool fast, bool wires);
|
||||
|
||||
short GPU_pbvh_buffers_material_index_get(GPU_PBVH_Buffers *buffers);
|
||||
|
||||
bool GPU_pbvh_buffers_has_mask(GPU_PBVH_Buffers *buffers);
|
||||
|
||||
/* debug PBVH draw */
|
||||
|
||||
@@ -83,6 +83,8 @@ struct GPU_PBVH_Buffers {
|
||||
|
||||
uint tot_tri, tot_quad;
|
||||
|
||||
short material_index;
|
||||
|
||||
/* The PBVH ensures that either all faces in the node are
|
||||
* smooth-shaded or all faces are flat-shaded */
|
||||
bool smooth;
|
||||
@@ -289,6 +291,11 @@ void GPU_pbvh_mesh_buffers_update(GPU_PBVH_Buffers *buffers,
|
||||
}
|
||||
}
|
||||
|
||||
/* Get material index from the first face of this buffer. */
|
||||
const MLoopTri *lt = &buffers->looptri[buffers->face_indices[0]];
|
||||
const MPoly *mp = &buffers->mpoly[lt->poly];
|
||||
buffers->material_index = mp->mat_nr;
|
||||
|
||||
buffers->show_mask = !empty_mask;
|
||||
buffers->mvert = mvert;
|
||||
}
|
||||
@@ -538,7 +545,6 @@ void GPU_pbvh_grid_buffers_update(GPU_PBVH_Buffers *buffers,
|
||||
int i, j, k, x, y;
|
||||
|
||||
const bool smooth = grid_flag_mats[grid_indices[0]].flag & ME_SMOOTH;
|
||||
static char vcol[4] = {255, 255, 255, 255};
|
||||
|
||||
/* Build VBO */
|
||||
const int has_mask = key->has_mask;
|
||||
@@ -603,6 +609,7 @@ void GPU_pbvh_grid_buffers_update(GPU_PBVH_Buffers *buffers,
|
||||
}
|
||||
|
||||
if (show_vcol) {
|
||||
char vcol[4] = {255, 255, 255, 255};
|
||||
GPU_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.col, vbo_index, &vcol);
|
||||
}
|
||||
|
||||
@@ -652,6 +659,8 @@ void GPU_pbvh_grid_buffers_update(GPU_PBVH_Buffers *buffers,
|
||||
GPU_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.msk, vbo_index + 3, &fmask);
|
||||
empty_mask = empty_mask && (fmask == 0.0f);
|
||||
}
|
||||
|
||||
char vcol[4] = {255, 255, 255, 255};
|
||||
GPU_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.col, vbo_index + 0, &vcol);
|
||||
GPU_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.col, vbo_index + 1, &vcol);
|
||||
GPU_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.col, vbo_index + 2, &vcol);
|
||||
@@ -666,14 +675,15 @@ void GPU_pbvh_grid_buffers_update(GPU_PBVH_Buffers *buffers,
|
||||
gpu_pbvh_batch_init(buffers, GPU_PRIM_TRIS);
|
||||
}
|
||||
|
||||
/* Get material index from the first face of this buffer. */
|
||||
buffers->material_index = grid_flag_mats[grid_indices[0]].mat_nr;
|
||||
|
||||
buffers->grids = grids;
|
||||
buffers->grid_indices = grid_indices;
|
||||
buffers->totgrid = totgrid;
|
||||
buffers->grid_flag_mats = grid_flag_mats;
|
||||
buffers->gridkey = *key;
|
||||
buffers->show_mask = !empty_mask;
|
||||
|
||||
// printf("node updated %p\n", buffers);
|
||||
}
|
||||
|
||||
GPU_PBVH_Buffers *GPU_pbvh_grid_buffers_build(int totgrid, BLI_bitmap **grid_hidden)
|
||||
@@ -793,6 +803,7 @@ void GPU_pbvh_bmesh_buffers_update(GPU_PBVH_Buffers *buffers,
|
||||
const bool show_vcol = (update_flags & GPU_PBVH_BUFFERS_SHOW_VCOL) != 0;
|
||||
int tottri, totvert, maxvert = 0;
|
||||
bool empty_mask = true;
|
||||
BMFace *f;
|
||||
|
||||
/* TODO, make mask layer optional for bmesh buffer */
|
||||
const int cd_vert_mask_offset = CustomData_get_offset(&bm->vdata, CD_PAINT_MASK);
|
||||
@@ -864,7 +875,7 @@ void GPU_pbvh_bmesh_buffers_update(GPU_PBVH_Buffers *buffers,
|
||||
GPU_indexbuf_init(&elb_lines, GPU_PRIM_LINES, tottri * 3, totvert);
|
||||
|
||||
GSET_ITER (gs_iter, bm_faces) {
|
||||
BMFace *f = BLI_gsetIterator_getKey(&gs_iter);
|
||||
f = BLI_gsetIterator_getKey(&gs_iter);
|
||||
|
||||
BLI_assert(f->len == 3);
|
||||
|
||||
@@ -922,7 +933,7 @@ void GPU_pbvh_bmesh_buffers_update(GPU_PBVH_Buffers *buffers,
|
||||
GSetIterator gs_iter;
|
||||
|
||||
GSET_ITER (gs_iter, bm_faces) {
|
||||
BMFace *f = BLI_gsetIterator_getKey(&gs_iter);
|
||||
f = BLI_gsetIterator_getKey(&gs_iter);
|
||||
|
||||
if (!BM_elem_flag_test(f, BM_ELEM_HIDDEN)) {
|
||||
BMVert *v[3];
|
||||
@@ -952,6 +963,9 @@ void GPU_pbvh_bmesh_buffers_update(GPU_PBVH_Buffers *buffers,
|
||||
}
|
||||
}
|
||||
|
||||
/* Get material index from the last face we iterated on. */
|
||||
buffers->material_index = f->mat_nr;
|
||||
|
||||
buffers->show_mask = !empty_mask;
|
||||
|
||||
gpu_pbvh_batch_init(buffers, GPU_PRIM_TRIS);
|
||||
@@ -990,6 +1004,11 @@ bool GPU_pbvh_buffers_has_mask(GPU_PBVH_Buffers *buffers)
|
||||
return buffers->show_mask;
|
||||
}
|
||||
|
||||
short GPU_pbvh_buffers_material_index_get(GPU_PBVH_Buffers *buffers)
|
||||
{
|
||||
return buffers->material_index;
|
||||
}
|
||||
|
||||
void GPU_pbvh_buffers_free(GPU_PBVH_Buffers *buffers)
|
||||
{
|
||||
if (buffers) {
|
||||
|
||||
Reference in New Issue
Block a user