Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/blender/blenkernel/intern/pbvh.c5
-rw-r--r--source/blender/gpu/GPU_buffers.h5
-rw-r--r--source/blender/gpu/intern/gpu_buffers.c38
3 files changed, 35 insertions, 13 deletions
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 119f7b0f939..40974d7d4f8 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -1085,7 +1085,8 @@ static void pbvh_update_draw_buffers(PBVH *bvh, PBVHNode **nodes, int totnode)
bvh->bm,
node->bm_faces,
node->bm_unique_verts,
- node->bm_other_verts);
+ node->bm_other_verts,
+ bvh->show_diffuse_color);
break;
}
@@ -1673,7 +1674,7 @@ static void pbvh_node_check_diffuse_changed(PBVH *bvh, PBVHNode *node)
if (!node->draw_buffers)
return;
- if (GPU_pbvh_buffers_diffuse_changed(node->draw_buffers, bvh->show_diffuse_color))
+ if (GPU_pbvh_buffers_diffuse_changed(node->draw_buffers, node->bm_faces, bvh->show_diffuse_color))
node->flag |= PBVH_UpdateDrawBuffers;
}
diff --git a/source/blender/gpu/GPU_buffers.h b/source/blender/gpu/GPU_buffers.h
index eca74317585..0629bae26f6 100644
--- a/source/blender/gpu/GPU_buffers.h
+++ b/source/blender/gpu/GPU_buffers.h
@@ -179,7 +179,8 @@ void GPU_update_bmesh_pbvh_buffers(GPU_PBVH_Buffers *buffers,
struct BMesh *bm,
struct GHash *bm_faces,
struct GSet *bm_unique_verts,
- struct GSet *bm_other_verts);
+ struct GSet *bm_other_verts,
+ int show_diffuse_color);
void GPU_update_grid_pbvh_buffers(GPU_PBVH_Buffers *buffers, struct CCGElem **grids,
const struct DMFlagMat *grid_flag_mats,
@@ -189,7 +190,7 @@ void GPU_update_grid_pbvh_buffers(GPU_PBVH_Buffers *buffers, struct CCGElem **gr
void GPU_draw_pbvh_buffers(GPU_PBVH_Buffers *buffers, DMSetMaterial setMaterial,
bool wireframe);
-bool GPU_pbvh_buffers_diffuse_changed(GPU_PBVH_Buffers *buffers, bool show_diffuse_color);
+bool GPU_pbvh_buffers_diffuse_changed(GPU_PBVH_Buffers *buffers, struct GHash *bm_faces, bool show_diffuse_color);
void GPU_free_pbvh_buffers(GPU_PBVH_Buffers *buffers);
diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index 3d5879b22d3..7875cad289a 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -1954,14 +1954,12 @@ static void gpu_bmesh_vert_to_buffer_copy(BMVert *v,
int *v_index,
const float fno[3],
const float *fmask,
- const int cd_vert_mask_offset)
+ const int cd_vert_mask_offset,
+ const float diffuse_color[4])
{
if (!BM_elem_flag_test(v, BM_ELEM_HIDDEN)) {
VertexBufferFormat *vd = &vert_data[*v_index];
- /* TODO: should use material color */
- float diffuse_color[4] = {1.0f, 1.0f, 1.0f, 1.0f};
-
/* Set coord, normal, and mask */
copy_v3_v3(vd->co, v->co);
normal_float_to_short_v3(vd->no, fno ? fno : v->no);
@@ -2024,15 +2022,19 @@ void GPU_update_bmesh_pbvh_buffers(GPU_PBVH_Buffers *buffers,
BMesh *bm,
GHash *bm_faces,
GSet *bm_unique_verts,
- GSet *bm_other_verts)
+ GSet *bm_other_verts,
+ int show_diffuse_color)
{
VertexBufferFormat *vert_data;
void *tri_data;
int tottri, totvert, maxvert = 0;
+ float diffuse_color[4] = {1.0f, 1.0f, 1.0f, 1.0f};
/* TODO, make mask layer optional for bmesh buffer */
const int cd_vert_mask_offset = CustomData_get_offset(&bm->vdata, CD_PAINT_MASK);
+ buffers->show_diffuse_color = show_diffuse_color;
+
if (!buffers->vert_buf || (buffers->smooth && !buffers->index_buf))
return;
@@ -2059,6 +2061,15 @@ void GPU_update_bmesh_pbvh_buffers(GPU_PBVH_Buffers *buffers,
return;
}
+ if (show_diffuse_color) {
+ /* due to dynamc nature of dyntopo, only get first material */
+ GHashIterator gh_iter;
+ BMFace *f;
+ BLI_ghashIterator_init(&gh_iter, bm_faces);
+ f = BLI_ghashIterator_getKey(&gh_iter);
+ GPU_material_diffuse_get(f->mat_nr + 1, diffuse_color);
+ }
+
/* Initialize vertex buffer */
glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers->vert_buf);
glBufferDataARB(GL_ARRAY_BUFFER_ARB,
@@ -2080,13 +2091,13 @@ void GPU_update_bmesh_pbvh_buffers(GPU_PBVH_Buffers *buffers,
GSET_ITER (gs_iter, bm_unique_verts) {
gpu_bmesh_vert_to_buffer_copy(BLI_gsetIterator_getKey(&gs_iter),
vert_data, &v_index, NULL, NULL,
- cd_vert_mask_offset);
+ cd_vert_mask_offset, diffuse_color);
}
GSET_ITER (gs_iter, bm_other_verts) {
gpu_bmesh_vert_to_buffer_copy(BLI_gsetIterator_getKey(&gs_iter),
vert_data, &v_index, NULL, NULL,
- cd_vert_mask_offset);
+ cd_vert_mask_offset, diffuse_color);
}
maxvert = v_index;
@@ -2116,7 +2127,7 @@ void GPU_update_bmesh_pbvh_buffers(GPU_PBVH_Buffers *buffers,
for (i = 0; i < 3; i++) {
gpu_bmesh_vert_to_buffer_copy(v[i], vert_data,
&v_index, f->no, &fmask,
- cd_vert_mask_offset);
+ cd_vert_mask_offset, diffuse_color);
}
}
}
@@ -2203,6 +2214,7 @@ GPU_PBVH_Buffers *GPU_build_bmesh_pbvh_buffers(int smooth_shading)
glGenBuffersARB(1, &buffers->vert_buf);
buffers->use_bmesh = true;
buffers->smooth = smooth_shading;
+ buffers->show_diffuse_color = false;
return buffers;
}
@@ -2498,7 +2510,7 @@ void GPU_draw_pbvh_buffers(GPU_PBVH_Buffers *buffers, DMSetMaterial setMaterial,
}
}
-bool GPU_pbvh_buffers_diffuse_changed(GPU_PBVH_Buffers *buffers, bool show_diffuse_color)
+bool GPU_pbvh_buffers_diffuse_changed(GPU_PBVH_Buffers *buffers, GHash *bm_faces, bool show_diffuse_color)
{
float diffuse_color[4];
@@ -2513,6 +2525,14 @@ bool GPU_pbvh_buffers_diffuse_changed(GPU_PBVH_Buffers *buffers, bool show_diffu
GPU_material_diffuse_get(f->mat_nr + 1, diffuse_color);
}
+ else if (buffers->use_bmesh) {
+ /* due to dynamc nature of dyntopo, only get first material */
+ GHashIterator gh_iter;
+ BMFace *f;
+ BLI_ghashIterator_init(&gh_iter, bm_faces);
+ f = BLI_ghashIterator_getKey(&gh_iter);
+ GPU_material_diffuse_get(f->mat_nr + 1, diffuse_color);
+ }
else {
const DMFlagMat *flags = &buffers->grid_flag_mats[buffers->grid_indices[0]];