diff options
Diffstat (limited to 'source/blender/draw/intern')
-rw-r--r-- | source/blender/draw/intern/draw_cache.c | 20 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache_extract.h | 12 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache_extract_mesh.cc | 7 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache_extract_mesh_render_data.c | 14 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache_impl.h | 36 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache_impl_mesh.c | 161 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache_impl_subdivision.cc | 2 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager.c | 16 | ||||
-rw-r--r-- | source/blender/draw/intern/mesh_extractors/extract_mesh.h | 3 |
9 files changed, 146 insertions, 125 deletions
diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c index 1110658e3b2..a4564ce2668 100644 --- a/source/blender/draw/intern/draw_cache.c +++ b/source/blender/draw/intern/draw_cache.c @@ -960,7 +960,7 @@ int DRW_cache_object_material_count_get(struct Object *ob) switch (type) { case OB_MESH: - return DRW_mesh_material_count_get((me != NULL) ? me : ob->data); + return DRW_mesh_material_count_get(ob, (me != NULL) ? me : ob->data); case OB_CURVE: case OB_SURF: case OB_FONT: @@ -2875,7 +2875,7 @@ GPUBatch *DRW_cache_mesh_surface_get(Object *ob) GPUBatch *DRW_cache_mesh_surface_edges_get(Object *ob) { BLI_assert(ob->type == OB_MESH); - return DRW_mesh_batch_cache_get_surface_edges(ob->data); + return DRW_mesh_batch_cache_get_surface_edges(ob, ob->data); } GPUBatch **DRW_cache_mesh_surface_shaded_get(Object *ob, @@ -2883,31 +2883,31 @@ GPUBatch **DRW_cache_mesh_surface_shaded_get(Object *ob, uint gpumat_array_len) { BLI_assert(ob->type == OB_MESH); - return DRW_mesh_batch_cache_get_surface_shaded(ob->data, gpumat_array, gpumat_array_len); + return DRW_mesh_batch_cache_get_surface_shaded(ob, ob->data, gpumat_array, gpumat_array_len); } GPUBatch **DRW_cache_mesh_surface_texpaint_get(Object *ob) { BLI_assert(ob->type == OB_MESH); - return DRW_mesh_batch_cache_get_surface_texpaint(ob->data); + return DRW_mesh_batch_cache_get_surface_texpaint(ob, ob->data); } GPUBatch *DRW_cache_mesh_surface_texpaint_single_get(Object *ob) { BLI_assert(ob->type == OB_MESH); - return DRW_mesh_batch_cache_get_surface_texpaint_single(ob->data); + return DRW_mesh_batch_cache_get_surface_texpaint_single(ob, ob->data); } GPUBatch *DRW_cache_mesh_surface_vertpaint_get(Object *ob) { BLI_assert(ob->type == OB_MESH); - return DRW_mesh_batch_cache_get_surface_vertpaint(ob->data); + return DRW_mesh_batch_cache_get_surface_vertpaint(ob, ob->data); } GPUBatch *DRW_cache_mesh_surface_sculptcolors_get(Object *ob) { BLI_assert(ob->type == OB_MESH); - return DRW_mesh_batch_cache_get_surface_sculpt(ob->data); + return DRW_mesh_batch_cache_get_surface_sculpt(ob, ob->data); } GPUBatch *DRW_cache_mesh_surface_weights_get(Object *ob) @@ -3091,7 +3091,7 @@ GPUBatch **DRW_cache_surf_surface_shaded_get(Object *ob, struct Curve *cu = ob->data; struct Mesh *mesh_eval = BKE_object_get_evaluated_mesh_no_subsurf(ob); if (mesh_eval != NULL) { - return DRW_mesh_batch_cache_get_surface_shaded(mesh_eval, gpumat_array, gpumat_array_len); + return DRW_mesh_batch_cache_get_surface_shaded(ob, mesh_eval, gpumat_array, gpumat_array_len); } return DRW_curve_batch_cache_get_surface_shaded(cu, gpumat_array, gpumat_array_len); @@ -3385,7 +3385,7 @@ void drw_batch_cache_validate(Object *ob) struct Mesh *mesh_eval = BKE_object_get_evaluated_mesh_no_subsurf(ob); switch (ob->type) { case OB_MESH: - DRW_mesh_batch_cache_validate((Mesh *)ob->data); + DRW_mesh_batch_cache_validate(ob, (Mesh *)ob->data); break; case OB_CURVE: case OB_FONT: @@ -3393,7 +3393,7 @@ void drw_batch_cache_validate(Object *ob) break; case OB_SURF: if (mesh_eval != NULL) { - DRW_mesh_batch_cache_validate(mesh_eval); + DRW_mesh_batch_cache_validate(ob, mesh_eval); } DRW_curve_batch_cache_validate((Curve *)ob->data); break; diff --git a/source/blender/draw/intern/draw_cache_extract.h b/source/blender/draw/intern/draw_cache_extract.h index bd4edaf09fb..e7f66ebacd0 100644 --- a/source/blender/draw/intern/draw_cache_extract.h +++ b/source/blender/draw/intern/draw_cache_extract.h @@ -28,6 +28,7 @@ struct TaskGraph; #include "DNA_customdata_types.h" #include "BKE_attribute.h" +#include "BKE_object.h" #include "GPU_batch.h" #include "GPU_index_buffer.h" @@ -107,11 +108,13 @@ ENUM_OPERATORS(eMRDataType, MR_DATA_POLYS_SORTED) extern "C" { #endif -BLI_INLINE int mesh_render_mat_len_get(const Mesh *me) +BLI_INLINE int mesh_render_mat_len_get(const Object *object, const Mesh *me) { - /* In edit mode, the displayed mesh is stored in the edit-mesh. */ - if (me->edit_mesh && me->edit_mesh->mesh_eval_final) { - return MAX2(1, me->edit_mesh->mesh_eval_final->totcol); + if (me->edit_mesh != NULL) { + const Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(object); + if (editmesh_eval_final != NULL) { + return MAX2(1, editmesh_eval_final->totcol); + } } return MAX2(1, me->totcol); } @@ -328,6 +331,7 @@ typedef struct MeshBatchCache { void mesh_buffer_cache_create_requested(struct TaskGraph *task_graph, MeshBatchCache *cache, MeshBufferCache *mbc, + Object *object, Mesh *me, bool is_editmode, bool is_paint_mode, diff --git a/source/blender/draw/intern/draw_cache_extract_mesh.cc b/source/blender/draw/intern/draw_cache_extract_mesh.cc index fe55778527b..987ddf3a938 100644 --- a/source/blender/draw/intern/draw_cache_extract_mesh.cc +++ b/source/blender/draw/intern/draw_cache_extract_mesh.cc @@ -570,6 +570,7 @@ static struct TaskNode *mesh_extract_render_data_node_create(struct TaskGraph *t static void mesh_buffer_cache_create_requested(struct TaskGraph *task_graph, MeshBatchCache *cache, MeshBufferCache *mbc, + Object *object, Mesh *me, const bool is_editmode, @@ -615,7 +616,7 @@ static void mesh_buffer_cache_create_requested(struct TaskGraph *task_graph, */ const bool do_hq_normals = (scene->r.perf_flag & SCE_PERF_HQ_NORMALS) != 0 || GPU_use_hq_normals_workaround(); - const bool override_single_mat = mesh_render_mat_len_get(me) <= 1; + const bool override_single_mat = mesh_render_mat_len_get(object, me) <= 1; /* Create an array containing all the extractors that needs to be executed. */ ExtractorRunDatas extractors; @@ -700,7 +701,7 @@ static void mesh_buffer_cache_create_requested(struct TaskGraph *task_graph, #endif MeshRenderData *mr = mesh_render_data_create( - me, is_editmode, is_paint_mode, is_mode_active, obmat, do_final, do_uvedit, ts); + object, me, is_editmode, is_paint_mode, is_mode_active, obmat, do_final, do_uvedit, ts); mr->use_hide = use_hide; mr->use_subsurf_fdots = use_subsurf_fdots; mr->use_final_mesh = do_final; @@ -902,6 +903,7 @@ extern "C" { void mesh_buffer_cache_create_requested(struct TaskGraph *task_graph, MeshBatchCache *cache, MeshBufferCache *mbc, + Object *object, Mesh *me, const bool is_editmode, @@ -918,6 +920,7 @@ void mesh_buffer_cache_create_requested(struct TaskGraph *task_graph, blender::draw::mesh_buffer_cache_create_requested(task_graph, cache, mbc, + object, me, is_editmode, is_paint_mode, diff --git a/source/blender/draw/intern/draw_cache_extract_mesh_render_data.c b/source/blender/draw/intern/draw_cache_extract_mesh_render_data.c index 29430c46d93..a47a124bd24 100644 --- a/source/blender/draw/intern/draw_cache_extract_mesh_render_data.c +++ b/source/blender/draw/intern/draw_cache_extract_mesh_render_data.c @@ -438,7 +438,8 @@ void mesh_render_data_update_normals(MeshRenderData *mr, const eMRDataType data_ } } -MeshRenderData *mesh_render_data_create(Mesh *me, +MeshRenderData *mesh_render_data_create(Object *object, + Mesh *me, const bool is_editmode, const bool is_paint_mode, const bool is_mode_active, @@ -449,15 +450,18 @@ MeshRenderData *mesh_render_data_create(Mesh *me, { MeshRenderData *mr = MEM_callocN(sizeof(*mr), __func__); mr->toolsettings = ts; - mr->mat_len = mesh_render_mat_len_get(me); + mr->mat_len = mesh_render_mat_len_get(object, me); copy_m4_m4(mr->obmat, obmat); if (is_editmode) { - BLI_assert(me->edit_mesh->mesh_eval_cage && me->edit_mesh->mesh_eval_final); + Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(object); + Mesh *editmesh_eval_cage = BKE_object_get_editmesh_eval_cage(object); + + BLI_assert(editmesh_eval_cage && editmesh_eval_final); mr->bm = me->edit_mesh->bm; mr->edit_bmesh = me->edit_mesh; - mr->me = (do_final) ? me->edit_mesh->mesh_eval_final : me->edit_mesh->mesh_eval_cage; + mr->me = (do_final) ? editmesh_eval_final : editmesh_eval_cage; mr->edit_data = is_mode_active ? mr->me->runtime.edit_data : NULL; if (mr->edit_data) { @@ -507,7 +511,7 @@ MeshRenderData *mesh_render_data_create(Mesh *me, /* Seems like the mesh_eval_final do not have the right origin indices. * Force not mapped in this case. */ - if (has_mdata && do_final && me->edit_mesh->mesh_eval_final != me->edit_mesh->mesh_eval_cage) { + if (has_mdata && do_final && editmesh_eval_final != editmesh_eval_cage) { // mr->edit_bmesh = NULL; mr->extract_type = MR_EXTRACT_MESH; } diff --git a/source/blender/draw/intern/draw_cache_impl.h b/source/blender/draw/intern/draw_cache_impl.h index 77b507bc2b6..6a2f4b91ad1 100644 --- a/source/blender/draw/intern/draw_cache_impl.h +++ b/source/blender/draw/intern/draw_cache_impl.h @@ -60,7 +60,7 @@ void DRW_curve_batch_cache_validate(struct Curve *cu); void DRW_curve_batch_cache_free(struct Curve *cu); void DRW_mesh_batch_cache_dirty_tag(struct Mesh *me, eMeshBatchDirtyMode mode); -void DRW_mesh_batch_cache_validate(struct Mesh *me); +void DRW_mesh_batch_cache_validate(struct Object *object, struct Mesh *me); void DRW_mesh_batch_cache_free(struct Mesh *me); void DRW_lattice_batch_cache_dirty_tag(struct Lattice *lt, int mode); @@ -236,14 +236,18 @@ struct GPUBatch *DRW_mesh_batch_cache_get_all_edges(struct Mesh *me); struct GPUBatch *DRW_mesh_batch_cache_get_loose_edges(struct Mesh *me); struct GPUBatch *DRW_mesh_batch_cache_get_edge_detection(struct Mesh *me, bool *r_is_manifold); struct GPUBatch *DRW_mesh_batch_cache_get_surface(struct Mesh *me); -struct GPUBatch *DRW_mesh_batch_cache_get_surface_edges(struct Mesh *me); -struct GPUBatch **DRW_mesh_batch_cache_get_surface_shaded(struct Mesh *me, +struct GPUBatch *DRW_mesh_batch_cache_get_surface_edges(struct Object *object, struct Mesh *me); +struct GPUBatch **DRW_mesh_batch_cache_get_surface_shaded(struct Object *object, + struct Mesh *me, struct GPUMaterial **gpumat_array, uint gpumat_array_len); -struct GPUBatch **DRW_mesh_batch_cache_get_surface_texpaint(struct Mesh *me); -struct GPUBatch *DRW_mesh_batch_cache_get_surface_texpaint_single(struct Mesh *me); -struct GPUBatch *DRW_mesh_batch_cache_get_surface_vertpaint(struct Mesh *me); -struct GPUBatch *DRW_mesh_batch_cache_get_surface_sculpt(struct Mesh *me); +struct GPUBatch **DRW_mesh_batch_cache_get_surface_texpaint(struct Object *object, + struct Mesh *me); +struct GPUBatch *DRW_mesh_batch_cache_get_surface_texpaint_single(struct Object *object, + struct Mesh *me); +struct GPUBatch *DRW_mesh_batch_cache_get_surface_vertpaint(struct Object *object, + struct Mesh *me); +struct GPUBatch *DRW_mesh_batch_cache_get_surface_sculpt(struct Object *object, struct Mesh *me); struct GPUBatch *DRW_mesh_batch_cache_get_surface_weights(struct Mesh *me); struct GPUBatch *DRW_mesh_batch_cache_get_sculpt_overlays(struct Mesh *me); @@ -293,14 +297,16 @@ struct GPUBatch *DRW_mesh_batch_cache_get_wireframes_face(struct Mesh *me); * The `cache->tot_area` and cache->tot_uv_area` update are calculation are * only valid after calling `DRW_mesh_batch_cache_create_requested`. */ -struct GPUBatch *DRW_mesh_batch_cache_get_edituv_faces_stretch_area(struct Mesh *me, +struct GPUBatch *DRW_mesh_batch_cache_get_edituv_faces_stretch_area(struct Object *object, + struct Mesh *me, float **tot_area, float **tot_uv_area); -struct GPUBatch *DRW_mesh_batch_cache_get_edituv_faces_stretch_angle(struct Mesh *me); -struct GPUBatch *DRW_mesh_batch_cache_get_edituv_faces(struct Mesh *me); -struct GPUBatch *DRW_mesh_batch_cache_get_edituv_edges(struct Mesh *me); -struct GPUBatch *DRW_mesh_batch_cache_get_edituv_verts(struct Mesh *me); -struct GPUBatch *DRW_mesh_batch_cache_get_edituv_facedots(struct Mesh *me); +struct GPUBatch *DRW_mesh_batch_cache_get_edituv_faces_stretch_angle(struct Object *object, + struct Mesh *me); +struct GPUBatch *DRW_mesh_batch_cache_get_edituv_faces(struct Object *object, struct Mesh *me); +struct GPUBatch *DRW_mesh_batch_cache_get_edituv_edges(struct Object *object, struct Mesh *me); +struct GPUBatch *DRW_mesh_batch_cache_get_edituv_verts(struct Object *object, struct Mesh *me); +struct GPUBatch *DRW_mesh_batch_cache_get_edituv_facedots(struct Object *object, struct Mesh *me); /** \} */ @@ -308,7 +314,7 @@ struct GPUBatch *DRW_mesh_batch_cache_get_edituv_facedots(struct Mesh *me); /** \name For Image UV Editor * \{ */ -struct GPUBatch *DRW_mesh_batch_cache_get_uv_edges(struct Mesh *me); +struct GPUBatch *DRW_mesh_batch_cache_get_uv_edges(struct Object *object, struct Mesh *me); struct GPUBatch *DRW_mesh_batch_cache_get_edit_mesh_analysis(struct Mesh *me); /** \} */ @@ -321,7 +327,7 @@ struct GPUVertBuf *DRW_mesh_batch_cache_pos_vertbuf_get(struct Mesh *me); struct GPUVertBuf *DRW_curve_batch_cache_pos_vertbuf_get(struct Curve *cu); struct GPUVertBuf *DRW_mball_batch_cache_pos_vertbuf_get(struct Object *ob); -int DRW_mesh_material_count_get(const struct Mesh *me); +int DRW_mesh_material_count_get(const struct Object *object, const struct Mesh *me); /* See 'common_globals_lib.glsl' for duplicate defines. */ diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c index 1e5ffc14911..f57921d058c 100644 --- a/source/blender/draw/intern/draw_cache_impl_mesh.c +++ b/source/blender/draw/intern/draw_cache_impl_mesh.c @@ -280,9 +280,16 @@ BLI_INLINE void mesh_cd_layers_type_clear(DRW_MeshCDMask *a) *((uint32_t *)a) = 0; } -BLI_INLINE const Mesh *editmesh_final_or_this(const Mesh *me) +BLI_INLINE const Mesh *editmesh_final_or_this(const Object *object, const Mesh *me) { - return (me->edit_mesh && me->edit_mesh->mesh_eval_final) ? me->edit_mesh->mesh_eval_final : me; + if (me->edit_mesh != NULL) { + Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(object); + if (editmesh_eval_final != NULL) { + return editmesh_eval_final; + } + } + + return me; } static void mesh_cd_calc_edit_uv_layer(const Mesh *UNUSED(me), DRW_MeshCDMask *cd_used) @@ -443,9 +450,11 @@ BLI_INLINE const CustomData *mesh_cd_vdata_get_from_mesh(const Mesh *me) return &me->vdata; } -static void mesh_cd_calc_active_uv_layer(const Mesh *me, DRW_MeshCDMask *cd_used) +static void mesh_cd_calc_active_uv_layer(const Object *object, + const Mesh *me, + DRW_MeshCDMask *cd_used) { - const Mesh *me_final = editmesh_final_or_this(me); + const Mesh *me_final = editmesh_final_or_this(object, me); const CustomData *cd_ldata = mesh_cd_ldata_get_from_mesh(me_final); int layer = CustomData_get_active_layer(cd_ldata, CD_MLOOPUV); if (layer != -1) { @@ -453,9 +462,11 @@ static void mesh_cd_calc_active_uv_layer(const Mesh *me, DRW_MeshCDMask *cd_used } } -static void mesh_cd_calc_active_mask_uv_layer(const Mesh *me, DRW_MeshCDMask *cd_used) +static void mesh_cd_calc_active_mask_uv_layer(const Object *object, + const Mesh *me, + DRW_MeshCDMask *cd_used) { - const Mesh *me_final = editmesh_final_or_this(me); + const Mesh *me_final = editmesh_final_or_this(object, me); const CustomData *cd_ldata = mesh_cd_ldata_get_from_mesh(me_final); int layer = CustomData_get_stencil_layer(cd_ldata, CD_MLOOPUV); if (layer != -1) { @@ -463,9 +474,11 @@ static void mesh_cd_calc_active_mask_uv_layer(const Mesh *me, DRW_MeshCDMask *cd } } -static void mesh_cd_calc_active_vcol_layer(const Mesh *me, DRW_MeshAttributes *attrs_used) +static void mesh_cd_calc_active_vcol_layer(const Object *object, + const Mesh *me, + DRW_MeshAttributes *attrs_used) { - const Mesh *me_final = editmesh_final_or_this(me); + const Mesh *me_final = editmesh_final_or_this(object, me); const CustomData *cd_vdata = mesh_cd_vdata_get_from_mesh(me_final); int layer = CustomData_get_active_layer(cd_vdata, CD_PROP_COLOR); @@ -474,9 +487,11 @@ static void mesh_cd_calc_active_vcol_layer(const Mesh *me, DRW_MeshAttributes *a } } -static void mesh_cd_calc_active_mloopcol_layer(const Mesh *me, DRW_MeshCDMask *cd_used) +static void mesh_cd_calc_active_mloopcol_layer(const Object *object, + const Mesh *me, + DRW_MeshCDMask *cd_used) { - const Mesh *me_final = editmesh_final_or_this(me); + const Mesh *me_final = editmesh_final_or_this(object, me); const CustomData *cd_ldata = mesh_cd_ldata_get_from_mesh(me_final); int layer = CustomData_get_active_layer(cd_ldata, CD_MLOOPCOL); @@ -514,12 +529,13 @@ static bool custom_data_match_attribute(const CustomData *custom_data, return false; } -static DRW_MeshCDMask mesh_cd_calc_used_gpu_layers(const Mesh *me, +static DRW_MeshCDMask mesh_cd_calc_used_gpu_layers(const Object *object, + const Mesh *me, struct GPUMaterial **gpumat_array, int gpumat_array_len, DRW_MeshAttributes *attributes) { - const Mesh *me_final = editmesh_final_or_this(me); + const Mesh *me_final = editmesh_final_or_this(object, me); const CustomData *cd_ldata = mesh_cd_ldata_get_from_mesh(me_final); const CustomData *cd_pdata = mesh_cd_pdata_get_from_mesh(me_final); const CustomData *cd_vdata = mesh_cd_vdata_get_from_mesh(me_final); @@ -793,7 +809,7 @@ BLI_INLINE void mesh_batch_cache_add_request(MeshBatchCache *cache, DRWBatchFlag /* GPUBatch cache management. */ -static bool mesh_batch_cache_valid(Mesh *me) +static bool mesh_batch_cache_valid(Object *object, Mesh *me) { MeshBatchCache *cache = me->runtime.batch_cache; @@ -809,14 +825,14 @@ static bool mesh_batch_cache_valid(Mesh *me) return false; } - if (cache->mat_len != mesh_render_mat_len_get(me)) { + if (cache->mat_len != mesh_render_mat_len_get(object, me)) { return false; } return true; } -static void mesh_batch_cache_init(Mesh *me) +static void mesh_batch_cache_init(Object *object, Mesh *me) { MeshBatchCache *cache = me->runtime.batch_cache; @@ -836,7 +852,7 @@ static void mesh_batch_cache_init(Mesh *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(object, me); cache->surface_per_mat = MEM_callocN(sizeof(*cache->surface_per_mat) * cache->mat_len, __func__); cache->tris_per_mat = MEM_callocN(sizeof(*cache->tris_per_mat) * cache->mat_len, __func__); @@ -847,11 +863,11 @@ static void mesh_batch_cache_init(Mesh *me) drw_mesh_weight_state_clear(&cache->weight_state); } -void DRW_mesh_batch_cache_validate(Mesh *me) +void DRW_mesh_batch_cache_validate(Object *object, Mesh *me) { - if (!mesh_batch_cache_valid(me)) { + if (!mesh_batch_cache_valid(object, me)) { mesh_batch_cache_clear(me); - mesh_batch_cache_init(me); + mesh_batch_cache_init(object, me); } } @@ -1095,24 +1111,24 @@ void DRW_mesh_batch_cache_free(Mesh *me) /** \name Public API * \{ */ -static void texpaint_request_active_uv(MeshBatchCache *cache, Mesh *me) +static void texpaint_request_active_uv(MeshBatchCache *cache, Object *object, Mesh *me) { DRW_MeshCDMask cd_needed; mesh_cd_layers_type_clear(&cd_needed); - mesh_cd_calc_active_uv_layer(me, &cd_needed); + mesh_cd_calc_active_uv_layer(object, me, &cd_needed); BLI_assert(cd_needed.uv != 0 && "No uv layer available in texpaint, but batches requested anyway!"); - mesh_cd_calc_active_mask_uv_layer(me, &cd_needed); + mesh_cd_calc_active_mask_uv_layer(object, me, &cd_needed); mesh_cd_layers_type_merge(&cache->cd_needed, cd_needed); } -static void texpaint_request_active_vcol(MeshBatchCache *cache, Mesh *me) +static void texpaint_request_active_vcol(MeshBatchCache *cache, Object *object, Mesh *me) { DRW_MeshCDMask cd_needed; mesh_cd_layers_type_clear(&cd_needed); - mesh_cd_calc_active_mloopcol_layer(me, &cd_needed); + mesh_cd_calc_active_mloopcol_layer(object, me, &cd_needed); BLI_assert(cd_needed.vcol != 0 && "No MLOOPCOL layer available in vertpaint, but batches requested anyway!"); @@ -1120,11 +1136,11 @@ static void texpaint_request_active_vcol(MeshBatchCache *cache, Mesh *me) mesh_cd_layers_type_merge(&cache->cd_needed, cd_needed); } -static void sculpt_request_active_vcol(MeshBatchCache *cache, Mesh *me) +static void sculpt_request_active_vcol(MeshBatchCache *cache, Object *object, Mesh *me) { DRW_MeshAttributes attrs_needed; drw_mesh_attributes_clear(&attrs_needed); - mesh_cd_calc_active_vcol_layer(me, &attrs_needed); + mesh_cd_calc_active_vcol_layer(object, me, &attrs_needed); BLI_assert(attrs_needed.num_requests != 0 && "No MPropCol layer available in Sculpt, but batches requested anyway!"); @@ -1197,7 +1213,8 @@ GPUBatch *DRW_mesh_batch_cache_get_edit_mesh_analysis(Mesh *me) return DRW_batch_request(&cache->batch.edit_mesh_analysis); } -GPUBatch **DRW_mesh_batch_cache_get_surface_shaded(Mesh *me, +GPUBatch **DRW_mesh_batch_cache_get_surface_shaded(Object *object, + Mesh *me, struct GPUMaterial **gpumat_array, uint gpumat_array_len) { @@ -1205,7 +1222,7 @@ GPUBatch **DRW_mesh_batch_cache_get_surface_shaded(Mesh *me, DRW_MeshAttributes attrs_needed; drw_mesh_attributes_clear(&attrs_needed); DRW_MeshCDMask cd_needed = mesh_cd_calc_used_gpu_layers( - me, gpumat_array, gpumat_array_len, &attrs_needed); + object, me, gpumat_array, gpumat_array_len, &attrs_needed); BLI_assert(gpumat_array_len == cache->mat_len); @@ -1216,41 +1233,41 @@ GPUBatch **DRW_mesh_batch_cache_get_surface_shaded(Mesh *me, return cache->surface_per_mat; } -GPUBatch **DRW_mesh_batch_cache_get_surface_texpaint(Mesh *me) +GPUBatch **DRW_mesh_batch_cache_get_surface_texpaint(Object *object, Mesh *me) { MeshBatchCache *cache = mesh_batch_cache_get(me); - texpaint_request_active_uv(cache, me); + texpaint_request_active_uv(cache, object, me); mesh_batch_cache_request_surface_batches(cache); return cache->surface_per_mat; } -GPUBatch *DRW_mesh_batch_cache_get_surface_texpaint_single(Mesh *me) +GPUBatch *DRW_mesh_batch_cache_get_surface_texpaint_single(Object *object, Mesh *me) { MeshBatchCache *cache = mesh_batch_cache_get(me); - texpaint_request_active_uv(cache, me); + texpaint_request_active_uv(cache, object, me); mesh_batch_cache_request_surface_batches(cache); return cache->batch.surface; } -GPUBatch *DRW_mesh_batch_cache_get_surface_vertpaint(Mesh *me) +GPUBatch *DRW_mesh_batch_cache_get_surface_vertpaint(Object *object, Mesh *me) { MeshBatchCache *cache = mesh_batch_cache_get(me); - texpaint_request_active_vcol(cache, me); + texpaint_request_active_vcol(cache, object, me); mesh_batch_cache_request_surface_batches(cache); return cache->batch.surface; } -GPUBatch *DRW_mesh_batch_cache_get_surface_sculpt(Mesh *me) +GPUBatch *DRW_mesh_batch_cache_get_surface_sculpt(Object *object, Mesh *me) { MeshBatchCache *cache = mesh_batch_cache_get(me); - sculpt_request_active_vcol(cache, me); + sculpt_request_active_vcol(cache, object, me); mesh_batch_cache_request_surface_batches(cache); return cache->batch.surface; } -int DRW_mesh_material_count_get(const Mesh *me) +int DRW_mesh_material_count_get(const Object *object, const Mesh *me) { - return mesh_render_mat_len_get(me); + return mesh_render_mat_len_get(object, me); } GPUBatch *DRW_mesh_batch_cache_get_sculpt_overlays(Mesh *me) @@ -1375,26 +1392,27 @@ GPUBatch *DRW_mesh_batch_cache_get_verts_with_select_id(Mesh *me) /** \name UV Image editor API * \{ */ -static void edituv_request_active_uv(MeshBatchCache *cache, Mesh *me) +static void edituv_request_active_uv(MeshBatchCache *cache, Object *object, Mesh *me) { DRW_MeshCDMask cd_needed; mesh_cd_layers_type_clear(&cd_needed); - mesh_cd_calc_active_uv_layer(me, &cd_needed); + mesh_cd_calc_active_uv_layer(object, me, &cd_needed); mesh_cd_calc_edit_uv_layer(me, &cd_needed); BLI_assert(cd_needed.edit_uv != 0 && "No uv layer available in edituv, but batches requested anyway!"); - mesh_cd_calc_active_mask_uv_layer(me, &cd_needed); + mesh_cd_calc_active_mask_uv_layer(object, me, &cd_needed); mesh_cd_layers_type_merge(&cache->cd_needed, cd_needed); } -GPUBatch *DRW_mesh_batch_cache_get_edituv_faces_stretch_area(Mesh *me, +GPUBatch *DRW_mesh_batch_cache_get_edituv_faces_stretch_area(Object *object, + Mesh *me, float **tot_area, float **tot_uv_area) { MeshBatchCache *cache = mesh_batch_cache_get(me); - edituv_request_active_uv(cache, me); + edituv_request_active_uv(cache, object, me); mesh_batch_cache_add_request(cache, MBC_EDITUV_FACES_STRETCH_AREA); if (tot_area != NULL) { @@ -1406,58 +1424,58 @@ GPUBatch *DRW_mesh_batch_cache_get_edituv_faces_stretch_area(Mesh *me, return DRW_batch_request(&cache->batch.edituv_faces_stretch_area); } -GPUBatch *DRW_mesh_batch_cache_get_edituv_faces_stretch_angle(Mesh *me) +GPUBatch *DRW_mesh_batch_cache_get_edituv_faces_stretch_angle(Object *object, Mesh *me) { MeshBatchCache *cache = mesh_batch_cache_get(me); - edituv_request_active_uv(cache, me); + edituv_request_active_uv(cache, object, me); mesh_batch_cache_add_request(cache, MBC_EDITUV_FACES_STRETCH_ANGLE); return DRW_batch_request(&cache->batch.edituv_faces_stretch_angle); } -GPUBatch *DRW_mesh_batch_cache_get_edituv_faces(Mesh *me) +GPUBatch *DRW_mesh_batch_cache_get_edituv_faces(Object *object, Mesh *me) { MeshBatchCache *cache = mesh_batch_cache_get(me); - edituv_request_active_uv(cache, me); + edituv_request_active_uv(cache, object, me); mesh_batch_cache_add_request(cache, MBC_EDITUV_FACES); return DRW_batch_request(&cache->batch.edituv_faces); } -GPUBatch *DRW_mesh_batch_cache_get_edituv_edges(Mesh *me) +GPUBatch *DRW_mesh_batch_cache_get_edituv_edges(Object *object, Mesh *me) { MeshBatchCache *cache = mesh_batch_cache_get(me); - edituv_request_active_uv(cache, me); + edituv_request_active_uv(cache, object, me); mesh_batch_cache_add_request(cache, MBC_EDITUV_EDGES); return DRW_batch_request(&cache->batch.edituv_edges); } -GPUBatch *DRW_mesh_batch_cache_get_edituv_verts(Mesh *me) +GPUBatch *DRW_mesh_batch_cache_get_edituv_verts(Object *object, Mesh *me) { MeshBatchCache *cache = mesh_batch_cache_get(me); - edituv_request_active_uv(cache, me); + edituv_request_active_uv(cache, object, me); mesh_batch_cache_add_request(cache, MBC_EDITUV_VERTS); return DRW_batch_request(&cache->batch.edituv_verts); } -GPUBatch *DRW_mesh_batch_cache_get_edituv_facedots(Mesh *me) +GPUBatch *DRW_mesh_batch_cache_get_edituv_facedots(Object *object, Mesh *me) { MeshBatchCache *cache = mesh_batch_cache_get(me); - edituv_request_active_uv(cache, me); + edituv_request_active_uv(cache, object, me); mesh_batch_cache_add_request(cache, MBC_EDITUV_FACEDOTS); return DRW_batch_request(&cache->batch.edituv_fdots); } -GPUBatch *DRW_mesh_batch_cache_get_uv_edges(Mesh *me) +GPUBatch *DRW_mesh_batch_cache_get_uv_edges(Object *object, Mesh *me) { MeshBatchCache *cache = mesh_batch_cache_get(me); - edituv_request_active_uv(cache, me); + edituv_request_active_uv(cache, object, me); mesh_batch_cache_add_request(cache, MBC_WIRE_LOOPS_UVS); return DRW_batch_request(&cache->batch.wire_loops_uvs); } -GPUBatch *DRW_mesh_batch_cache_get_surface_edges(Mesh *me) +GPUBatch *DRW_mesh_batch_cache_get_surface_edges(Object *object, Mesh *me) { MeshBatchCache *cache = mesh_batch_cache_get(me); - texpaint_request_active_uv(cache, me); + texpaint_request_active_uv(cache, object, me); mesh_batch_cache_add_request(cache, MBC_WIRE_LOOPS); return DRW_batch_request(&cache->batch.wire_loops); } @@ -1560,20 +1578,12 @@ void DRW_mesh_batch_cache_create_requested(struct TaskGraph *task_graph, /* Sanity check. */ if ((me->edit_mesh != NULL) && (ob->mode & OB_MODE_EDIT)) { - BLI_assert(me->edit_mesh->mesh_eval_final != NULL); + BLI_assert(BKE_object_get_editmesh_eval_final(ob) != NULL); } - /* Don't check `DRW_object_is_in_edit_mode(ob)` here because it means the same mesh - * may draw with edit-mesh data and regular mesh data. - * In this case the custom-data layers used won't always match in `me->runtime.batch_cache`. - * If we want to display regular mesh data, we should have a separate cache for the edit-mesh. - * See T77359. */ const bool is_editmode = (me->edit_mesh != NULL) && - /* In rare cases we have the edit-mode data but not the generated cache. - * This can happen when switching an objects data to a mesh which - * happens to be in edit-mode in another scene, see: T82952. */ - (me->edit_mesh->mesh_eval_final != - NULL) /* && DRW_object_is_in_edit_mode(ob) */; + (BKE_object_get_editmesh_eval_final(ob) != NULL) && + DRW_object_is_in_edit_mode(ob); /* This could be set for paint mode too, currently it's only used for edit-mode. */ const bool is_mode_active = is_editmode && DRW_object_is_in_edit_mode(ob); @@ -1599,7 +1609,7 @@ void DRW_mesh_batch_cache_create_requested(struct TaskGraph *task_graph, /* Modifiers will only generate an orco layer if the mesh is deformed. */ if (cache->cd_needed.orco != 0) { /* Orco is always extracted from final mesh. */ - Mesh *me_final = (me->edit_mesh) ? me->edit_mesh->mesh_eval_final : me; + Mesh *me_final = (me->edit_mesh) ? BKE_object_get_editmesh_eval_final(ob) : me; if (CustomData_get_layer(&me_final->vdata, CD_ORCO) == NULL) { /* Skip orco calculation */ cache->cd_needed.orco = 0; @@ -1705,10 +1715,14 @@ void DRW_mesh_batch_cache_create_requested(struct TaskGraph *task_graph, cache->batch_ready |= batch_requested; - const bool do_cage = (is_editmode && - (me->edit_mesh->mesh_eval_final != me->edit_mesh->mesh_eval_cage)); + bool do_cage = false, do_uvcage = false; + if (is_editmode) { + Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(ob); + Mesh *editmesh_eval_cage = BKE_object_get_editmesh_eval_cage(ob); - const bool do_uvcage = is_editmode && !me->edit_mesh->mesh_eval_final->runtime.is_original; + do_cage = editmesh_eval_final != editmesh_eval_cage; + do_uvcage = !editmesh_eval_final->runtime.is_original; + } const int required_mode = BKE_subsurf_modifier_eval_required_mode(DRW_state_is_scene_render(), is_editmode); @@ -2029,6 +2043,7 @@ void DRW_mesh_batch_cache_create_requested(struct TaskGraph *task_graph, mesh_buffer_cache_create_requested(task_graph, cache, &cache->uv_cage, + ob, me, is_editmode, is_paint_mode, @@ -2046,6 +2061,7 @@ void DRW_mesh_batch_cache_create_requested(struct TaskGraph *task_graph, mesh_buffer_cache_create_requested(task_graph, cache, &cache->cage, + ob, me, is_editmode, is_paint_mode, @@ -2071,6 +2087,7 @@ void DRW_mesh_batch_cache_create_requested(struct TaskGraph *task_graph, mesh_buffer_cache_create_requested(task_graph, cache, &cache->final, + ob, me, is_editmode, is_paint_mode, diff --git a/source/blender/draw/intern/draw_cache_impl_subdivision.cc b/source/blender/draw/intern/draw_cache_impl_subdivision.cc index 2f0c5cca3d6..a24a3a5a3a7 100644 --- a/source/blender/draw/intern/draw_cache_impl_subdivision.cc +++ b/source/blender/draw/intern/draw_cache_impl_subdivision.cc @@ -1828,7 +1828,7 @@ static bool draw_subdiv_create_requested_buffers(const Scene *scene, Mesh *mesh_eval = mesh; BMesh *bm = nullptr; if (mesh->edit_mesh) { - mesh_eval = mesh->edit_mesh->mesh_eval_final; + mesh_eval = BKE_object_get_editmesh_eval_final(ob); bm = mesh->edit_mesh->bm; } diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index 276a8cc3a13..45e4c2a575e 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -212,21 +212,7 @@ bool DRW_object_is_in_edit_mode(const Object *ob) if (BKE_object_is_in_editmode(ob)) { if (ob->type == OB_MESH) { if ((ob->mode & OB_MODE_EDIT) == 0) { - Mesh *me = (Mesh *)ob->data; - BMEditMesh *embm = me->edit_mesh; - /* Sanity check when rendering in multiple windows. */ - if (embm && embm->mesh_eval_final == NULL) { - return false; - } - /* Do not draw ob with edit overlay when edit data is present and is modified. */ - if (embm && embm->mesh_eval_cage && (embm->mesh_eval_cage != embm->mesh_eval_final)) { - return false; - } - /* Check if the object that we are drawing is modified. */ - if (!DEG_is_original_id(&me->id)) { - return false; - } - return true; + return false; } } return true; diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh.h b/source/blender/draw/intern/mesh_extractors/extract_mesh.h index bb55d0c5b2c..37eb4f80442 100644 --- a/source/blender/draw/intern/mesh_extractors/extract_mesh.h +++ b/source/blender/draw/intern/mesh_extractors/extract_mesh.h @@ -281,7 +281,8 @@ typedef struct MeshExtract { * \param is_mode_active: When true, use the modifiers from the edit-data, * otherwise don't use modifiers as they are not from this object. */ -MeshRenderData *mesh_render_data_create(Mesh *me, +MeshRenderData *mesh_render_data_create(Object *object, + Mesh *me, bool is_editmode, bool is_paint_mode, bool is_mode_active, |