Mesh Batch Cache: Put context evaluation out of batch cache
authorClément Foucault <foucault.clem@gmail.com>
Sat, 22 Dec 2018 20:00:23 +0000 (21:00 +0100)
committerClément Foucault <foucault.clem@gmail.com>
Fri, 11 Jan 2019 15:00:23 +0000 (16:00 +0100)
This is in order to be able to call DRW_mesh_batch_cache_create_requested
outside of the draw manager

source/blender/draw/intern/draw_cache.c
source/blender/draw/intern/draw_cache_impl.h
source/blender/draw/intern/draw_cache_impl_mesh.c

index 96e263c..6fe477b 100644 (file)
@@ -3749,16 +3749,23 @@ bool DRW_vbo_requested(GPUVertBuf *vbo)
 
 void drw_batch_cache_generate_requested(Object *ob)
 {
+       const DRWContextState *draw_ctx = DRW_context_state_get();
+       const ToolSettings *ts = draw_ctx->scene->toolsettings;
+       const int mode = CTX_data_mode_enum_ex(draw_ctx->object_edit, draw_ctx->obact, draw_ctx->object_mode);
+       const bool is_paint_mode = ELEM(mode, CTX_MODE_PAINT_TEXTURE, CTX_MODE_PAINT_VERTEX, CTX_MODE_PAINT_WEIGHT);
+       const bool use_hide = (ob->type == OB_MESH) && ((is_paint_mode && (ob == draw_ctx->obact)) ||
+                                                      ((mode == CTX_MODE_EDIT_MESH) && BKE_object_is_in_editmode(ob)));
+
        struct Mesh *mesh_eval = ob->runtime.mesh_eval;
        switch (ob->type) {
                case OB_MESH:
-                       DRW_mesh_batch_cache_create_requested(ob, (Mesh *)ob->data);
+                       DRW_mesh_batch_cache_create_requested(ob, (Mesh *)ob->data, ts, is_paint_mode, use_hide);
                        break;
                case OB_CURVE:
                case OB_FONT:
                case OB_SURF:
                        if (mesh_eval) {
-                               DRW_mesh_batch_cache_create_requested(ob, mesh_eval);
+                               DRW_mesh_batch_cache_create_requested(ob, mesh_eval, ts, is_paint_mode, use_hide);
                        }
                        DRW_curve_batch_cache_create_requested(ob);
                        break;
index 64a1a72..3851470 100644 (file)
@@ -37,6 +37,7 @@ struct ModifierData;
 struct ParticleSystem;
 struct PTCacheEdit;
 struct SpaceImage;
+struct ToolSettings;
 
 struct Curve;
 struct Lattice;
@@ -97,7 +98,9 @@ struct GPUBatch *DRW_lattice_batch_cache_get_all_verts(struct Lattice *lt);
 struct GPUBatch *DRW_lattice_batch_cache_get_edit_verts(struct Lattice *lt);
 
 /* Mesh */
-void DRW_mesh_batch_cache_create_requested(struct Object *ob, struct Mesh *me);
+void DRW_mesh_batch_cache_create_requested(
+        struct Object *ob, struct Mesh *me,
+        const struct ToolSettings *ts, const bool is_paint_mode, const bool use_hide);
 
 struct GPUBatch *DRW_mesh_batch_cache_get_all_verts(struct Mesh *me);
 struct GPUBatch *DRW_mesh_batch_cache_get_all_edges(struct Mesh *me);
index fd9c444..54f42c3 100644 (file)
@@ -5277,30 +5277,17 @@ void DRW_mesh_cache_uvedit(
  * \{ */
 
 /* Can be called for any surface type. Mesh *me is the final mesh. */
-void DRW_mesh_batch_cache_create_requested(Object *ob, Mesh *me)
+void DRW_mesh_batch_cache_create_requested(
+        Object *ob, Mesh *me,
+        const ToolSettings *ts, const bool is_paint_mode, const bool use_hide)
 {
-       const DRWContextState *draw_ctx = DRW_context_state_get();
-       const int mode = CTX_data_mode_enum_ex(draw_ctx->object_edit, draw_ctx->obact, draw_ctx->object_mode);
-       const bool is_paint_mode = ELEM(mode, CTX_MODE_PAINT_TEXTURE, CTX_MODE_PAINT_VERTEX, CTX_MODE_PAINT_WEIGHT);
-       const bool use_hide = (
-               (ob->type == OB_MESH) &&
-               ((is_paint_mode && (ob == draw_ctx->obact)) ||
-                ((mode == CTX_MODE_EDIT_MESH) && BKE_object_is_in_editmode(ob))));
-       bool use_face_sel = false;
-
-       /* Tex paint face select */
-       if (is_paint_mode && (ob->type == OB_MESH) && (draw_ctx->obact == ob)) {
-               const Mesh *me_orig = DEG_get_original_object(ob)->data;
-               use_face_sel = (me_orig->editflag & ME_EDIT_PAINT_FACE_SEL) != 0;
-       }
-
        MeshBatchCache *cache = mesh_batch_cache_get(me);
 
        /* Check vertex weights. */
-       if (cache->batch.surface_weights != 0) {
+       if ((cache->batch.surface_weights != 0) && (ts != NULL)) {
                struct DRW_MeshWeightState wstate;
                BLI_assert(ob->type == OB_MESH);
-               drw_mesh_weight_state_extract(ob, me, draw_ctx->scene->toolsettings, is_paint_mode, &wstate);
+               drw_mesh_weight_state_extract(ob, me, ts, is_paint_mode, &wstate);
                mesh_batch_cache_check_vertex_group(cache, &wstate);
                drw_mesh_weight_state_copy(&cache->weight_state, &wstate);
                drw_mesh_weight_state_clear(&wstate);