diff options
author | Luca Rood <dev@lucarood.com> | 2017-05-04 20:59:27 +0300 |
---|---|---|
committer | Luca Rood <dev@lucarood.com> | 2017-05-04 21:05:59 +0300 |
commit | 3103b819aa530da29e9853cb67e3f0b77d349d4e (patch) | |
tree | 598272bccd325ad6ec70e5b919c9cd53eee9f5ec /source/blender/draw | |
parent | b5b9b2d04db4b3cf08d219d00e5f7d1d82725ad1 (diff) |
Vertex paint with draw manager
Reviewers: fclem
Subscribers: campbellbarton, dfelinto
Differential Revision: https://developer.blender.org/D2658
Diffstat (limited to 'source/blender/draw')
-rw-r--r-- | source/blender/draw/DRW_engine.h | 1 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache.c | 12 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache.h | 3 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache_impl.h | 3 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache_impl_mesh.c | 214 | ||||
-rw-r--r-- | source/blender/draw/modes/object_mode.c | 2 | ||||
-rw-r--r-- | source/blender/draw/modes/paint_vertex_mode.c | 198 | ||||
-rw-r--r-- | source/blender/draw/modes/paint_weight_mode.c | 4 |
8 files changed, 267 insertions, 170 deletions
diff --git a/source/blender/draw/DRW_engine.h b/source/blender/draw/DRW_engine.h index 239919fd826..c5cf029febb 100644 --- a/source/blender/draw/DRW_engine.h +++ b/source/blender/draw/DRW_engine.h @@ -90,5 +90,6 @@ void OBJECT_collection_settings_create(struct IDProperty *properties); void EDIT_MESH_collection_settings_create(struct IDProperty *properties); void EDIT_ARMATURE_collection_settings_create(struct IDProperty *properties); void PAINT_WEIGHT_collection_settings_create(struct IDProperty *properties); +void PAINT_VERTEX_collection_settings_create(struct IDProperty *properties); #endif /* __DRW_ENGINE_H__ */ diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c index 9fa79c41265..7e49d998fa0 100644 --- a/source/blender/draw/intern/draw_cache.c +++ b/source/blender/draw/intern/draw_cache.c @@ -1777,6 +1777,14 @@ Batch *DRW_cache_mesh_surface_weights_get(Object *ob) return DRW_mesh_batch_cache_get_triangles_with_normals_and_weights(me, ob->actdef - 1); } +Batch *DRW_cache_mesh_surface_vert_colors_get(Object *ob) +{ + BLI_assert(ob->type == OB_MESH); + + Mesh *me = ob->data; + return DRW_mesh_batch_cache_get_triangles_with_normals_and_vert_colors(me); +} + /* Return list of batches */ Batch **DRW_cache_mesh_surface_shaded_get(Object *ob) { @@ -1810,12 +1818,12 @@ Batch *DRW_cache_mesh_verts_get(Object *ob) return DRW_mesh_batch_cache_get_all_verts(me); } -Batch *DRW_cache_mesh_edges_weight_overlay_get(Object *ob, bool use_wire, bool use_sel) +Batch *DRW_cache_mesh_edges_paint_overlay_get(Object *ob, bool use_wire, bool use_sel, bool use_theme) { BLI_assert(ob->type == OB_MESH); Mesh *me = ob->data; - return DRW_mesh_batch_cache_get_weight_overlay_edges(me, use_wire, use_sel); + return DRW_mesh_batch_cache_get_weight_overlay_edges(me, use_wire, use_sel, use_theme); } Batch *DRW_cache_mesh_faces_weight_overlay_get(Object *ob) diff --git a/source/blender/draw/intern/draw_cache.h b/source/blender/draw/intern/draw_cache.h index a725eb2c37a..160cfaf1693 100644 --- a/source/blender/draw/intern/draw_cache.h +++ b/source/blender/draw/intern/draw_cache.h @@ -95,10 +95,11 @@ struct Batch *DRW_cache_face_centers_get(struct Object *ob); struct Batch *DRW_cache_mesh_wire_outline_get(struct Object *ob); struct Batch *DRW_cache_mesh_surface_get(struct Object *ob); struct Batch *DRW_cache_mesh_surface_weights_get(struct Object *ob); +struct Batch *DRW_cache_mesh_surface_vert_colors_get(struct Object *ob); struct Batch *DRW_cache_mesh_surface_verts_get(struct Object *ob); struct Batch *DRW_cache_mesh_edges_get(struct Object *ob); struct Batch *DRW_cache_mesh_verts_get(struct Object *ob); -struct Batch *DRW_cache_mesh_edges_weight_overlay_get(struct Object *ob, bool use_wire, bool use_sel); +struct Batch *DRW_cache_mesh_edges_paint_overlay_get(struct Object *ob, bool use_wire, bool use_sel, bool use_theme); struct Batch *DRW_cache_mesh_faces_weight_overlay_get(struct Object *ob); struct Batch *DRW_cache_mesh_verts_weight_overlay_get(struct Object *ob); struct Batch **DRW_cache_mesh_surface_shaded_get(struct Object *ob); diff --git a/source/blender/draw/intern/draw_cache_impl.h b/source/blender/draw/intern/draw_cache_impl.h index adda538f761..9216e05604e 100644 --- a/source/blender/draw/intern/draw_cache_impl.h +++ b/source/blender/draw/intern/draw_cache_impl.h @@ -68,13 +68,14 @@ struct Batch *DRW_lattice_batch_cache_get_overlay_verts(struct Lattice *lt); /* Mesh */ struct Batch **DRW_mesh_batch_cache_get_surface_shaded(struct Mesh *me); -struct Batch *DRW_mesh_batch_cache_get_weight_overlay_edges(struct Mesh *me, bool use_wire, bool use_sel); +struct Batch *DRW_mesh_batch_cache_get_weight_overlay_edges(struct Mesh *me, bool use_wire, bool use_sel, bool use_theme); struct Batch *DRW_mesh_batch_cache_get_weight_overlay_faces(struct Mesh *me); struct Batch *DRW_mesh_batch_cache_get_weight_overlay_verts(struct Mesh *me); struct Batch *DRW_mesh_batch_cache_get_all_edges(struct Mesh *me); struct Batch *DRW_mesh_batch_cache_get_all_triangles(struct Mesh *me); struct Batch *DRW_mesh_batch_cache_get_triangles_with_normals(struct Mesh *me); struct Batch *DRW_mesh_batch_cache_get_triangles_with_normals_and_weights(struct Mesh *me, int defgroup); +struct Batch *DRW_mesh_batch_cache_get_triangles_with_normals_and_vert_colors(struct Mesh *me); struct Batch *DRW_mesh_batch_cache_get_points_with_normals(struct Mesh *me); struct Batch *DRW_mesh_batch_cache_get_all_verts(struct Mesh *me); struct Batch *DRW_mesh_batch_cache_get_fancy_edges(struct Mesh *me); diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c index 9d7763a2c9a..5504a94d929 100644 --- a/source/blender/draw/intern/draw_cache_impl_mesh.c +++ b/source/blender/draw/intern/draw_cache_impl_mesh.c @@ -50,6 +50,8 @@ #include "GPU_batch.h" +#include "UI_resources.h" + #include "draw_cache_impl.h" /* own include */ static void mesh_batch_cache_clear(Mesh *me); @@ -124,6 +126,7 @@ typedef struct MeshRenderData { MLoopCol **mloopcol; float (**mtangent)[4]; MDeformVert *dvert; + MLoopCol *loopcol; BMVert *eve_act; BMEdge *eed_act; @@ -156,7 +159,8 @@ typedef struct MeshRenderData { int *loose_verts; float (*poly_normals)[3]; - float (*vert_color)[3]; + float (*vert_weight_color)[3]; + char (*vert_color)[3]; short (*poly_normals_short)[3]; short (*vert_normals_short)[3]; bool *edge_selection; @@ -171,6 +175,7 @@ enum { MR_DATATYPE_OVERLAY = 1 << 5, MR_DATATYPE_SHADING = 1 << 6, MR_DATATYPE_DVERT = 1 << 7, + MR_DATATYPE_LOOPCOL = 1 << 8, }; /** @@ -313,6 +318,10 @@ static MeshRenderData *mesh_render_data_create(Mesh *me, const int types) rdata->vert_len = me->totvert; rdata->dvert = CustomData_get_layer(&me->vdata, CD_MDEFORMVERT); } + if (types & MR_DATATYPE_LOOPCOL) { + rdata->loop_len = me->totloop; + rdata->loopcol = CustomData_get_layer(&me->ldata, CD_MLOOPCOL); + } } if (types & MR_DATATYPE_SHADING) { @@ -472,8 +481,9 @@ static void mesh_render_data_free(MeshRenderData *rdata) MEM_SAFE_FREE(rdata->uv_names); MEM_SAFE_FREE(rdata->vcol_names); MEM_SAFE_FREE(rdata->tangent_names); - MEM_SAFE_FREE(rdata->vert_color); + MEM_SAFE_FREE(rdata->vert_weight_color); MEM_SAFE_FREE(rdata->edge_selection); + MEM_SAFE_FREE(rdata->vert_color); MEM_freeN(rdata); } @@ -1031,7 +1041,7 @@ static bool mesh_render_data_looptri_cos_weights_get( return false; } - float (*vweight)[3] = rdata->vert_color; + float (*vweight)[3] = rdata->vert_weight_color; short (*pnors_short)[3] = rdata->poly_normals_short; short (*vnors_short)[3] = rdata->vert_normals_short; @@ -1069,7 +1079,7 @@ static bool mesh_render_data_looptri_cos_weights_get( const int cd_dvert_offset = CustomData_get_offset(&bm->vdata, CD_MDEFORMVERT); BLI_assert(cd_dvert_offset != -1); - vweight = rdata->vert_color = MEM_mallocN(sizeof(*vweight) * rdata->vert_len, __func__); + vweight = rdata->vert_weight_color = MEM_mallocN(sizeof(*vweight) * rdata->vert_len, __func__); BM_ITER_MESH_INDEX(vert, &viter, bm, BM_VERT, i) { const MDeformVert *dvert = BM_ELEM_CD_GET_VOID_P(vert, cd_dvert_offset); float weight = defvert_find_weight(dvert, defgroup); @@ -1082,7 +1092,7 @@ static bool mesh_render_data_looptri_cos_weights_get( } } else { - vweight = rdata->vert_color = MEM_callocN(sizeof(*vweight) * rdata->vert_len, __func__); + vweight = rdata->vert_weight_color = MEM_callocN(sizeof(*vweight) * rdata->vert_len, __func__); for (int i = 0; i < rdata->vert_len; i++) { vweight[i][2] = 0.5f; @@ -1105,7 +1115,7 @@ static bool mesh_render_data_looptri_cos_weights_get( } else { const MLoopTri *mlt = &rdata->mlooptri[tri_idx]; - float (*vweight)[3] = rdata->vert_color; + float (*vweight)[3] = rdata->vert_weight_color; short (*pnors_short)[3] = rdata->poly_normals_short; if (!pnors_short) { @@ -1126,7 +1136,7 @@ static bool mesh_render_data_looptri_cos_weights_get( if (!vweight) { if (rdata->dvert) { - vweight = rdata->vert_color = MEM_mallocN(sizeof(*vweight) * rdata->vert_len, __func__); + vweight = rdata->vert_weight_color = MEM_mallocN(sizeof(*vweight) * rdata->vert_len, __func__); for (int i = 0; i < rdata->vert_len; i++) { float weight = defvert_find_weight(&rdata->dvert[i], defgroup); @@ -1139,7 +1149,7 @@ static bool mesh_render_data_looptri_cos_weights_get( } } else { - vweight = rdata->vert_color = MEM_callocN(sizeof(*vweight) * rdata->vert_len, __func__); + vweight = rdata->vert_weight_color = MEM_callocN(sizeof(*vweight) * rdata->vert_len, __func__); for (int i = 0; i < rdata->vert_len; i++) { vweight[i][2] = 0.5f; @@ -1164,10 +1174,80 @@ static bool mesh_render_data_looptri_cos_weights_get( return true; } +static bool mesh_render_data_looptri_cos_vert_colors_get( + MeshRenderData *rdata, const int tri_idx, + float *(*r_vert_cos)[3], char *(*r_vert_colors)[3], + short **r_tri_nor, short *(*r_vert_nors)[3], bool *r_is_smooth) +{ + BLI_assert( + rdata->types & + (MR_DATATYPE_VERT | MR_DATATYPE_LOOPTRI | MR_DATATYPE_LOOP | MR_DATATYPE_POLY | MR_DATATYPE_LOOPCOL)); + + if (rdata->edit_bmesh) { + return false; + } + else { + const MLoopTri *mlt = &rdata->mlooptri[tri_idx]; + char (*vcol)[3] = rdata->vert_color; + short (*pnors_short)[3] = rdata->poly_normals_short; + + if (!pnors_short) { + float (*pnors)[3] = rdata->poly_normals; + + if (!pnors) { + pnors = rdata->poly_normals = MEM_mallocN(sizeof(*pnors) * rdata->poly_len, __func__); + BKE_mesh_calc_normals_poly( + rdata->mvert, NULL, rdata->vert_len, + rdata->mloop, rdata->mpoly, rdata->loop_len, rdata->poly_len, pnors, true); + } + + pnors_short = rdata->poly_normals_short = MEM_mallocN(sizeof(*pnors_short) * rdata->poly_len, __func__); + for (int i = 0; i < rdata->poly_len; i++) { + normal_float_to_short_v3(pnors_short[i], pnors[i]); + } + } + + if (!vcol) { + if (rdata->loopcol) { + vcol = rdata->vert_color = MEM_mallocN(sizeof(*vcol) * rdata->loop_len, __func__); + + for (int i = 0; i < rdata->loop_len; i++) { + vcol[i][0] = rdata->loopcol[i].r; + vcol[i][1] = rdata->loopcol[i].g; + vcol[i][2] = rdata->loopcol[i].b; + } + } + else { + vcol = rdata->vert_color = MEM_mallocN(sizeof(*vcol) * rdata->loop_len, __func__); + + for (int i = 0; i < rdata->loop_len; i++) { + vcol[i][0] = 255; + vcol[i][1] = 255; + vcol[i][2] = 255; + } + } + } + (*r_vert_cos)[0] = rdata->mvert[rdata->mloop[mlt->tri[0]].v].co; + (*r_vert_cos)[1] = rdata->mvert[rdata->mloop[mlt->tri[1]].v].co; + (*r_vert_cos)[2] = rdata->mvert[rdata->mloop[mlt->tri[2]].v].co; + (*r_vert_colors)[0] = vcol[mlt->tri[0]]; + (*r_vert_colors)[1] = vcol[mlt->tri[1]]; + (*r_vert_colors)[2] = vcol[mlt->tri[2]]; + *r_tri_nor = pnors_short[mlt->poly]; + (*r_vert_nors)[0] = rdata->mvert[rdata->mloop[mlt->tri[0]].v].no; + (*r_vert_nors)[1] = rdata->mvert[rdata->mloop[mlt->tri[1]].v].no; + (*r_vert_nors)[2] = rdata->mvert[rdata->mloop[mlt->tri[2]].v].no; + + *r_is_smooth = (rdata->mpoly[mlt->poly].flag & ME_SMOOTH) != 0; + } + + return true; +} + static bool mesh_render_data_edge_cos_sel_get( MeshRenderData *rdata, const int edge_idx, float r_vert_cos[2][3], float r_vert_col[3], - bool use_wire, bool use_sel) + bool use_wire, bool use_sel, bool use_theme) { BLI_assert(rdata->types & (MR_DATATYPE_VERT | MR_DATATYPE_EDGE | MR_DATATYPE_POLY | MR_DATATYPE_LOOP)); @@ -1198,9 +1278,14 @@ static bool mesh_render_data_edge_cos_sel_get( } if (use_sel && rdata->edge_selection[edge_idx]) { - r_vert_col[0] = 1.0f; - r_vert_col[1] = 1.0f; - r_vert_col[2] = 1.0f; + if (use_theme) { + UI_GetThemeColorShade3fv(TH_EDGE_SELECT, -50, r_vert_col); + } + else { + r_vert_col[0] = 1.0f; + r_vert_col[1] = 1.0f; + r_vert_col[2] = 1.0f; + } } else { if (use_wire) { @@ -1463,11 +1548,13 @@ typedef struct MeshBatchCache { VertexBuffer *pos_with_normals; VertexBuffer *pos_with_weights; + VertexBuffer *pos_with_vert_colors; VertexBuffer *edge_pos_with_sel; VertexBuffer *tri_pos_with_sel; VertexBuffer *pos_with_sel; Batch *triangles_with_normals; Batch *triangles_with_weights; + Batch *triangles_with_vert_colors; Batch *points_with_normals; Batch *fancy_edges; /* owns its vertex buffer (not shared) */ @@ -1492,7 +1579,7 @@ typedef struct MeshBatchCache { /* settings to determine if cache is invalid */ bool is_dirty; - bool is_weight_dirty; + bool is_paint_dirty; int edge_len; int tri_len; int poly_len; @@ -1520,7 +1607,7 @@ static bool mesh_batch_cache_valid(Mesh *me) return false; } - if (cache->is_weight_dirty) { + if (cache->is_paint_dirty) { return false; } @@ -1567,7 +1654,7 @@ static void mesh_batch_cache_init(Mesh *me) cache->mat_len = mesh_render_mat_len_get(me); cache->is_dirty = false; - cache->is_weight_dirty = false; + cache->is_paint_dirty = false; } static MeshBatchCache *mesh_batch_cache_get(Mesh *me) @@ -1596,8 +1683,8 @@ void DRW_mesh_batch_cache_dirty(Mesh *me, int mode) BATCH_DISCARD_ALL_SAFE(cache->overlay_loose_edges); BATCH_DISCARD_ALL_SAFE(cache->overlay_facedots); break; - case BKE_MESH_BATCH_DIRTY_WEIGHT: - cache->is_weight_dirty = true; + case BKE_MESH_BATCH_DIRTY_PAINT: + cache->is_paint_dirty = true; break; default: BLI_assert(0); @@ -1631,6 +1718,7 @@ static void mesh_batch_cache_clear(Mesh *me) BATCH_DISCARD_SAFE(cache->points_with_normals); VERTEXBUFFER_DISCARD_SAFE(cache->pos_with_normals); BATCH_DISCARD_ALL_SAFE(cache->triangles_with_weights); + BATCH_DISCARD_ALL_SAFE(cache->triangles_with_vert_colors); BATCH_DISCARD_ALL_SAFE(cache->fancy_edges); @@ -1946,6 +2034,72 @@ static VertexBuffer *mesh_batch_cache_get_pos_normals_and_weights( return cache->pos_with_weights; } +static VertexBuffer *mesh_batch_cache_get_pos_normals_and_vert_colors( + MeshRenderData *rdata, MeshBatchCache *cache) +{ + BLI_assert( + rdata->types & + (MR_DATATYPE_VERT | MR_DATATYPE_LOOPTRI | MR_DATATYPE_LOOP | MR_DATATYPE_POLY | MR_DATATYPE_LOOPCOL)); + + if (cache->pos_with_vert_colors == NULL) { + unsigned int vidx = 0, cidx = 0, nidx = 0; + + static VertexFormat format = { 0 }; + static unsigned int pos_id, col_id, nor_id; + if (format.attrib_ct == 0) { + /* initialize vertex format */ + pos_id = VertexFormat_add_attrib(&format, "pos", COMP_F32, 3, KEEP_FLOAT); + nor_id = VertexFormat_add_attrib(&format, "nor", COMP_I16, 3, NORMALIZE_INT_TO_FLOAT); + col_id = VertexFormat_add_attrib(&format, "color", COMP_U8, 3, NORMALIZE_INT_TO_FLOAT); + } + + const int tri_len = mesh_render_data_looptri_len_get(rdata); + + VertexBuffer *vbo = cache->pos_with_vert_colors = VertexBuffer_create_with_format(&format); + + 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++) { + float *tri_vert_cos[3]; + char *tri_vert_colors[3]; + short *tri_nor, *tri_vert_nors[3]; + bool is_smooth; + + if (mesh_render_data_looptri_cos_vert_colors_get( + rdata, i, &tri_vert_cos, &tri_vert_colors, &tri_nor, &tri_vert_nors, &is_smooth)) + { + VertexBuffer_set_attrib(vbo, col_id, cidx++, tri_vert_colors[0]); + VertexBuffer_set_attrib(vbo, col_id, cidx++, tri_vert_colors[1]); + VertexBuffer_set_attrib(vbo, col_id, cidx++, tri_vert_colors[2]); + + VertexBuffer_set_attrib(vbo, pos_id, vidx++, tri_vert_cos[0]); + VertexBuffer_set_attrib(vbo, pos_id, vidx++, tri_vert_cos[1]); + VertexBuffer_set_attrib(vbo, pos_id, vidx++, tri_vert_cos[2]); + + if (is_smooth) { + VertexBuffer_set_attrib(vbo, nor_id, nidx++, tri_vert_nors[0]); + VertexBuffer_set_attrib(vbo, nor_id, nidx++, tri_vert_nors[1]); + VertexBuffer_set_attrib(vbo, nor_id, nidx++, tri_vert_nors[2]); + } + else { + VertexBuffer_set_attrib(vbo, nor_id, nidx++, tri_nor); + VertexBuffer_set_attrib(vbo, nor_id, nidx++, tri_nor); + VertexBuffer_set_attrib(vbo, nor_id, nidx++, tri_nor); + } + } + } + vbo_len_used = vidx; + + if (vbo_len_capacity != vbo_len_used) { + VertexBuffer_resize_data(vbo, vbo_len_used); + } + } + + return cache->pos_with_vert_colors; +} + static VertexBuffer *mesh_batch_cache_get_pos_and_nor_in_order(MeshRenderData *rdata, MeshBatchCache *cache) { BLI_assert(rdata->types & MR_DATATYPE_VERT); @@ -2065,7 +2219,7 @@ static ElementList **mesh_batch_cache_get_shaded_triangles_in_order(MeshRenderDa } static VertexBuffer *mesh_batch_cache_get_edge_pos_with_sel( - MeshRenderData *rdata, MeshBatchCache *cache, bool use_wire, bool use_sel) + MeshRenderData *rdata, MeshBatchCache *cache, bool use_wire, bool use_sel, bool use_theme) { BLI_assert(rdata->types & (MR_DATATYPE_VERT | MR_DATATYPE_EDGE | MR_DATATYPE_POLY | MR_DATATYPE_LOOP)); @@ -2092,7 +2246,7 @@ static VertexBuffer *mesh_batch_cache_get_edge_pos_with_sel( static float edge_vert_cos[2][3], edge_vert_col[3]; if (mesh_render_data_edge_cos_sel_get( - rdata, i, edge_vert_cos, edge_vert_col, use_wire, use_sel)) + rdata, i, edge_vert_cos, edge_vert_col, use_wire, use_sel, use_theme)) { VertexBuffer_set_attrib(vbo, col_id, cidx++, edge_vert_col); VertexBuffer_set_attrib(vbo, col_id, cidx++, edge_vert_col); @@ -2278,6 +2432,24 @@ Batch *DRW_mesh_batch_cache_get_triangles_with_normals_and_weights(Mesh *me, int return cache->triangles_with_weights; } +Batch *DRW_mesh_batch_cache_get_triangles_with_normals_and_vert_colors(Mesh *me) +{ + MeshBatchCache *cache = mesh_batch_cache_get(me); + + if (cache->triangles_with_vert_colors == NULL) { + const int datatype = + MR_DATATYPE_VERT | MR_DATATYPE_LOOPTRI | MR_DATATYPE_LOOP | MR_DATATYPE_POLY | MR_DATATYPE_LOOPCOL; + MeshRenderData *rdata = mesh_render_data_create(me, datatype); + + cache->triangles_with_vert_colors = Batch_create( + PRIM_TRIANGLES, mesh_batch_cache_get_pos_normals_and_vert_colors(rdata, cache), NULL); + + mesh_render_data_free(rdata); + } + + return cache->triangles_with_vert_colors; +} + Batch *DRW_mesh_batch_cache_get_points_with_normals(Mesh *me) { MeshBatchCache *cache = mesh_batch_cache_get(me); @@ -2588,7 +2760,7 @@ Batch **DRW_mesh_batch_cache_get_surface_shaded(Mesh *me) return cache->shaded_triangles; } -Batch *DRW_mesh_batch_cache_get_weight_overlay_edges(Mesh *me, bool use_wire, bool use_sel) +Batch *DRW_mesh_batch_cache_get_weight_overlay_edges(Mesh *me, bool use_wire, bool use_sel, bool use_theme) { MeshBatchCache *cache = mesh_batch_cache_get(me); @@ -2598,7 +2770,7 @@ Batch *DRW_mesh_batch_cache_get_weight_overlay_edges(Mesh *me, bool use_wire, bo MeshRenderData *rdata = mesh_render_data_create(me, datatype); cache->overlay_weight_edges = Batch_create( - PRIM_LINES, mesh_batch_cache_get_edge_pos_with_sel(rdata, cache, use_wire, use_sel), NULL); + PRIM_LINES, mesh_batch_cache_get_edge_pos_with_sel(rdata, cache, use_wire, use_sel, use_theme), NULL); mesh_render_data_free(rdata); } diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c index c99cd7f7ece..4a892cb4ce9 100644 --- a/source/blender/draw/modes/object_mode.c +++ b/source/blender/draw/modes/object_mode.c @@ -1189,7 +1189,7 @@ static void OBJECT_cache_populate(void *vedata, Object *ob) if (do_outlines) { Object *obedit = scene->obedit; - if (ob != obedit && !(sl->basact->object == ob && ob->mode & OB_MODE_WEIGHT_PAINT)) { + if (ob != obedit && !(sl->basact->object == ob && ob->mode & (OB_MODE_WEIGHT_PAINT | OB_MODE_VERTEX_PAINT))) { struct Batch *geom = DRW_cache_object_surface_get(ob); if (geom) { theme_id = DRW_object_wire_theme_get(ob, sl, NULL); diff --git a/source/blender/draw/modes/paint_vertex_mode.c b/source/blender/draw/modes/paint_vertex_mode.c index f0efe3d82fe..ce09307bc0c 100644 --- a/source/blender/draw/modes/paint_vertex_mode.c +++ b/source/blender/draw/modes/paint_vertex_mode.c @@ -33,52 +33,29 @@ #include "draw_mode_engines.h" -/* If needed, contains all global/Theme colors - * Add needed theme colors / values to DRW_globals_update() and update UBO - * Not needed for constant color. */ +#include "DNA_mesh_types.h" + extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */ extern struct GlobalsUboStorage ts; /* draw_common.c */ /* *********** LISTS *********** */ -/* All lists are per viewport specific datas. - * They are all free when viewport changes engines - * or is free itself. Use PAINT_VERTEX_engine_init() to - * initialize most of them and PAINT_VERTEX_cache_init() - * for PAINT_VERTEX_PassList */ typedef struct PAINT_VERTEX_PassList { - /* Declare all passes here and init them in - * PAINT_VERTEX_cache_init(). - * Only contains (DRWPass *) */ - struct DRWPass *pass; + struct DRWPass *vcolor_faces; + struct DRWPass *wire_overlay; } PAINT_VERTEX_PassList; typedef struct PAINT_VERTEX_FramebufferList { - /* Contains all framebuffer objects needed by this engine. - * Only contains (GPUFrameBuffer *) */ - struct GPUFrameBuffer *fb; } PAINT_VERTEX_FramebufferList; typedef struct PAINT_VERTEX_TextureList { - /* Contains all framebuffer textures / utility textures - * needed by this engine. Only viewport specific textures - * (not per object). Only contains (GPUTexture *) */ - struct GPUTexture *texture; } PAINT_VERTEX_TextureList; typedef struct PAINT_VERTEX_StorageList { - /* Contains any other memory block that the engine needs. - * Only directly MEM_(m/c)allocN'ed blocks because they are - * free with MEM_freeN() when viewport is freed. - * (not per object) */ - struct CustomStruct *block; struct PAINT_VERTEX_PrivateData *g_data; } PAINT_VERTEX_StorageList; typedef struct PAINT_VERTEX_Data { - /* Struct returned by DRW_viewport_engine_data_get. - * If you don't use one of these, just make it a (void *) */ - // void *fbl; void *engine_type; /* Required */ PAINT_VERTEX_FramebufferList *fbl; PAINT_VERTEX_TextureList *txl; @@ -89,54 +66,30 @@ typedef struct PAINT_VERTEX_Data { /* *********** STATIC *********** */ static struct { - /* Custom shaders : - * Add sources to source/blender/draw/modes/shaders - * init in PAINT_VERTEX_engine_init(); - * free in PAINT_VERTEX_engine_free(); */ - struct GPUShader *custom_shader; + struct GPUShader *vcolor_face_shader; + struct GPUShader *wire_overlay_shader; } e_data = {NULL}; /* Engine data */ typedef struct PAINT_VERTEX_PrivateData { - /* This keeps the references of the shading groups for - * easy access in PAINT_VERTEX_cache_populate() */ - DRWShadingGroup *group; + DRWShadingGroup *fvcolor_shgrp; + DRWShadingGroup *lwire_shgrp; } PAINT_VERTEX_PrivateData; /* Transient data */ /* *********** FUNCTIONS *********** */ -/* Init Textures, Framebuffers, Storage and Shaders. - * It is called for every frames. - * (Optional) */ -static void PAINT_VERTEX_engine_init(void *vedata) +static void PAINT_VERTEX_engine_init(void *UNUSED(vedata)) { - PAINT_VERTEX_TextureList *txl = ((PAINT_VERTEX_Data *)vedata)->txl; - PAINT_VERTEX_FramebufferList *fbl = ((PAINT_VERTEX_Data *)vedata)->fbl; - PAINT_VERTEX_StorageList *stl = ((PAINT_VERTEX_Data *)vedata)->stl; + if (!e_data.vcolor_face_shader) { + e_data.vcolor_face_shader = GPU_shader_get_builtin_shader(GPU_SHADER_SIMPLE_LIGHTING_SMOOTH_COLOR_ALPHA); + } - UNUSED_VARS(txl, fbl, stl); - - /* Init Framebuffers like this: order is attachment order (for color texs) */ - /* - * DRWFboTexture tex[2] = {{&txl->depth, DRW_BUF_DEPTH_24, 0}, - * {&txl->color, DRW_BUF_RGBA_8, DRW_TEX_FILTER}}; - */ - - /* DRW_framebuffer_init takes care of checking if - * the framebuffer is valid and has the right size*/ - /* - * float *viewport_size = DRW_viewport_size_get(); - * DRW_framebuffer_init(&fbl->occlude_wire_fb, - * (int)viewport_size[0], (int)viewport_size[1], - * tex, 2); - */ - - if (!e_data.custom_shader) { - e_data.custom_shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR); + if (!e_data.wire_overlay_shader) { + e_data.wire_overlay_shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_FLAT_COLOR); } } -/* Here init all passes and shading groups - * Assume that all Passes are NULL */ +static float world_light; + static void PAINT_VERTEX_cache_init(void *vedata) { PAINT_VERTEX_PassList *psl = ((PAINT_VERTEX_Data *)vedata)->psl; @@ -149,108 +102,69 @@ static void PAINT_VERTEX_cache_init(void *vedata) { /* Create a pass */ - DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND | DRW_STATE_WIRE; - psl->pass = DRW_pass_create("My Pass", state); - - /* Create a shadingGroup using a function in draw_common.c or custom one */ - /* - * stl->g_data->group = shgroup_dynlines_uniform_color(psl->pass, ts.colorWire); - * -- or -- - * stl->g_data->group = DRW_shgroup_create(e_data.custom_shader, psl->pass); - */ - stl->g_data->group = DRW_shgroup_create(e_data.custom_shader, psl->pass); - - /* Uniforms need a pointer to it's value so be sure it's accessible at - * any given time (i.e. use static vars) */ - static float color[4] = {0.2f, 0.5f, 0.3f, 1.0}; - DRW_shgroup_uniform_vec4(stl->g_data->group, "color", color, 1); + psl->vcolor_faces = DRW_pass_create("Vert Color Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS); + + stl->g_data->fvcolor_shgrp = DRW_shgroup_create(e_data.vcolor_face_shader, psl->vcolor_faces); + + static float light[3] = {-0.3f, 0.5f, 1.0f}; + static float alpha = 1.0f; + DRW_shgroup_uniform_vec3(stl->g_data->fvcolor_shgrp, "light", light, 1); + DRW_shgroup_uniform_float(stl->g_data->fvcolor_shgrp, "alpha", &alpha, 1); + DRW_shgroup_uniform_float(stl->g_data->fvcolor_shgrp, "global", &world_light, 1); } + { + psl->wire_overlay = DRW_pass_create("Wire Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS); + + stl->g_data->lwire_shgrp = DRW_shgroup_create(e_data.wire_overlay_shader, psl->wire_overlay); + } } -/* Add geometry to shadingGroups. Execute for each objects */ static void PAINT_VERTEX_cache_populate(void *vedata, Object *ob) { - PAINT_VERTEX_PassList *psl = ((PAINT_VERTEX_Data *)vedata)->psl; PAINT_VERTEX_StorageList *stl = ((PAINT_VERTEX_Data *)vedata)->stl; + const DRWContextState *draw_ctx = DRW_context_state_get(); + SceneLayer *sl = draw_ctx->sl; - UNUSED_VARS(psl, stl); + if (ob->type == OB_MESH && ob == sl->basact->object) { + IDProperty *ces_mode_pw = BKE_object_collection_engine_get(ob, COLLECTION_MODE_PAINT_VERTEX, ""); + bool use_wire = BKE_collection_engine_property_value_get_bool(ces_mode_pw, "use_wire"); + char flag = ((Mesh *)ob->data)->editflag; + struct Batch *geom; - if (ob->type == OB_MESH) { - /* Get geometry cache */ - struct Batch *geom = DRW_cache_mesh_surface_get(ob); + world_light = BKE_collection_engine_property_value_get_bool(ces_mode_pw, "use_shading") ? 0.5f : 1.0f; - /* Add geom to a shading group */ - DRW_shgroup_call_add(stl->g_data->group, geom, ob->obmat); - } -} + geom = DRW_cache_mesh_surface_vert_colors_get(ob); + DRW_shgroup_call_add(stl->g_data->fvcolor_shgrp, geom, ob->obmat); -/* Optional: Post-cache_populate callback */ -static void PAINT_VERTEX_cache_finish(void *vedata) -{ - PAINT_VERTEX_PassList *psl = ((PAINT_VERTEX_Data *)vedata)->psl; - PAINT_VERTEX_StorageList *stl = ((PAINT_VERTEX_Data *)vedata)->stl; - - /* Do something here! dependant on the objects gathered */ - UNUSED_VARS(psl, stl); + if (flag & ME_EDIT_PAINT_FACE_SEL || use_wire) { + geom = DRW_cache_mesh_edges_paint_overlay_get(ob, use_wire, flag & ME_EDIT_PAINT_FACE_SEL, true); + DRW_shgroup_call_add(stl->g_data->lwire_shgrp, geom, ob->obmat); + } + } } -/* Draw time ! Control rendering pipeline from here */ static void PAINT_VERTEX_draw_scene(void *vedata) { PAINT_VERTEX_PassList *psl = ((PAINT_VERTEX_Data *)vedata)->psl; - PAINT_VERTEX_FramebufferList *fbl = ((PAINT_VERTEX_Data *)vedata)->fbl; - - /* Default framebuffer and texture */ - DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); - DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); - - UNUSED_VARS(fbl, dfbl, dtxl); - /* Show / hide entire passes, swap framebuffers ... whatever you fancy */ - /* - * DRW_framebuffer_texture_detach(dtxl->depth); - * DRW_framebuffer_bind(fbl->custom_fb); - * DRW_draw_pass(psl->pass); - * DRW_framebuffer_texture_attach(dfbl->default_fb, dtxl->depth, 0, 0); - * DRW_framebuffer_bind(dfbl->default_fb); - */ - - /* ... or just render passes on default framebuffer. */ - DRW_draw_pass(psl->pass); - - /* If you changed framebuffer, double check you rebind - * the default one with its textures attached before finishing */ + DRW_draw_pass(psl->vcolor_faces); + DRW_draw_pass(psl->wire_overlay); } -/* Cleanup when destroying the engine. - * This is not per viewport ! only when quitting blender. - * Mostly used for freeing shaders */ static void PAINT_VERTEX_engine_free(void) { - // DRW_SHADER_FREE_SAFE(custom_shader); } -/* Create collection settings here. - * - * Be sure to add this function there : - * source/blender/draw/DRW_engine.h - * source/blender/blenkernel/intern/layer.c - * source/blenderplayer/bad_level_call_stubs/stubs.c - * - * And relevant collection settings to : - * source/blender/makesrna/intern/rna_scene.c - * source/blender/blenkernel/intern/layer.c - */ -#if 0 -void PAINT_VERTEX_collection_settings_create(CollectionEngineSettings *ces) +void PAINT_VERTEX_collection_settings_create(IDProperty *properties) { - BLI_assert(ces); - // BKE_collection_engine_property_add_int(ces, "my_bool_prop", false); - // BKE_collection_engine_property_add_int(ces, "my_int_prop", 0); - // BKE_collection_engine_property_add_float(ces, "my_float_prop", 0.0f); + BLI_assert(properties && + properties->type == IDP_GROUP && + properties->subtype == IDP_GROUP_SUB_MODE_PAINT_VERTEX); + + BKE_collection_engine_property_add_bool(properties, "use_shading", true); + BKE_collection_engine_property_add_bool(properties, "use_wire", false); } -#endif static const DrawEngineDataSize PAINT_VERTEX_data_size = DRW_VIEWPORT_DATA_SIZE(PAINT_VERTEX_Data); @@ -262,7 +176,7 @@ DrawEngineType draw_engine_paint_vertex_type = { &PAINT_VERTEX_engine_free, &PAINT_VERTEX_cache_init, &PAINT_VERTEX_cache_populate, - &PAINT_VERTEX_cache_finish, - NULL, /* draw_background but not needed by mode engines */ + NULL, + NULL, &PAINT_VERTEX_draw_scene }; diff --git a/source/blender/draw/modes/paint_weight_mode.c b/source/blender/draw/modes/paint_weight_mode.c index 971e483ae81..1eb9e3caba1 100644 --- a/source/blender/draw/modes/paint_weight_mode.c +++ b/source/blender/draw/modes/paint_weight_mode.c @@ -86,7 +86,7 @@ static void PAINT_WEIGHT_engine_init(void *UNUSED(vedata)) if (e_data.actdef != draw_ctx->sl->basact->object->actdef) { e_data.actdef = draw_ctx->sl->basact->object->actdef; - BKE_mesh_batch_cache_dirty(draw_ctx->sl->basact->object->data, BKE_MESH_BATCH_DIRTY_WEIGHT); + BKE_mesh_batch_cache_dirty(draw_ctx->sl->basact->object->data, BKE_MESH_BATCH_DIRTY_PAINT); } if (!e_data.weight_face_shader) { @@ -164,7 +164,7 @@ static void PAINT_WEIGHT_cache_populate(void *vedata, Object *ob) DRW_shgroup_call_add(stl->g_data->fweights_shgrp, geom, ob->obmat); if (flag & ME_EDIT_PAINT_FACE_SEL || use_wire) { - geom = DRW_cache_mesh_edges_weight_overlay_get(ob, use_wire, flag & ME_EDIT_PAINT_FACE_SEL); + geom = DRW_cache_mesh_edges_paint_overlay_get(ob, use_wire, flag & ME_EDIT_PAINT_FACE_SEL, false); DRW_shgroup_call_add(stl->g_data->lwire_shgrp, geom, ob->obmat); } |