[Bf-blender-cvs] [4d320f43133] master: Edit Mesh Selection: Refactor: Redraw idmap buffer at runtime with only objects inside the rect

mano-wii noreply at git.blender.org
Thu Aug 15 15:32:03 CEST 2019


Commit: 4d320f43133b02a43212b017eecdb390476189f2
Author: mano-wii
Date:   Thu Aug 15 10:31:54 2019 -0300
Branches: master
https://developer.blender.org/rB4d320f43133b02a43212b017eecdb390476189f2

Edit Mesh Selection: Refactor: Redraw idmap buffer at runtime with only objects inside the rect

But in the future the selection code may also be used in object mode (eg for snapping).
So to avoid using too much VRAM resources, it is good to avoid drawing all objects in the viewport.

The solution was to create an array with only objects that are detected within the selection area.
If the selection operator is modal, objects already detected are not removed from the array until view3d is moved or orbited.
To detect the object, its BoundBox is tested.
Since the Select Engine does not have a dedicated depth texture, whenever a new object is "found" the depth of the objects in the array already drawn is redrawn.

Reviewers: campbellbarton, fclem

Reviewed By: fclem

Differential Revision: https://developer.blender.org/D5435

===================================================================

M	source/blender/draw/DRW_engine.h
M	source/blender/draw/DRW_select_buffer.h
M	source/blender/draw/engines/select/select_draw_utils.c
M	source/blender/draw/engines/select/select_engine.c
M	source/blender/draw/engines/select/select_private.h
M	source/blender/draw/intern/draw_manager.c
M	source/blender/draw/intern/draw_select_buffer.c
M	source/blender/editors/mesh/editmesh_select.c
M	source/blender/editors/mesh/meshtools.c
M	source/blender/editors/sculpt_paint/paint_utils.c
M	source/blender/editors/space_view3d/view3d_draw_legacy.c
M	source/blender/editors/space_view3d/view3d_select.c

===================================================================

diff --git a/source/blender/draw/DRW_engine.h b/source/blender/draw/DRW_engine.h
index 53cec599b82..6cae9ceb7d6 100644
--- a/source/blender/draw/DRW_engine.h
+++ b/source/blender/draw/DRW_engine.h
@@ -141,9 +141,7 @@ void DRW_draw_depth_object(struct ARegion *ar,
 void DRW_draw_select_id(struct Depsgraph *depsgraph,
                         struct ARegion *ar,
                         struct View3D *v3d,
-                        struct Base **bases,
-                        const uint bases_len,
-                        short select_mode);
+                        const struct rcti *rect);
 
 /* grease pencil render */
 bool DRW_render_check_grease_pencil(struct Depsgraph *depsgraph);
diff --git a/source/blender/draw/DRW_select_buffer.h b/source/blender/draw/DRW_select_buffer.h
index ff40508b1a1..4aa1c403710 100644
--- a/source/blender/draw/DRW_select_buffer.h
+++ b/source/blender/draw/DRW_select_buffer.h
@@ -33,6 +33,13 @@ struct View3D;
 struct ViewLayer;
 struct rcti;
 
+typedef struct SELECTID_ObjectData {
+  DrawData dd;
+
+  uint drawn_index;
+  bool is_drawn;
+} SELECTID_ObjectData;
+
 struct ObjectOffsets {
   /* For convenience only. */
   union {
@@ -54,43 +61,75 @@ struct SELECTID_Context {
   struct GPUFrameBuffer *framebuffer_select_id;
   struct GPUTexture *texture_u32;
 
-  struct ObjectOffsets *index_offsets;
+  /* All context objects */
+  struct Object **objects;
   uint objects_len;
-  uint last_object_drawn;
-  /** Total number of items `base_array_index_offsets[bases_len - 1].vert`. */
-  uint last_index_drawn;
+
+  /* Array with only drawn objects. When a new object is found within the rect,
+   * it is added to the end of the list.
+   * The list is reset to any viewport or context update. */
+  struct ObjectOffsets *index_offsets;
+  struct Object **objects_drawn;
+  uint objects_drawn_len;
+
+  /** Total number of element indices `index_offsets[object_drawn_len - 1].vert`. */
+  uint index_drawn_len;
 
   short select_mode;
+
+  /* To check for updates. */
+  float persmat[4][4];
+  bool is_dirty;
+
+  /* rect is used to check which objects whose indexes need to be drawn. */
+  rcti last_rect;
 };
 
-/* select_buffer.c */
-void DRW_select_buffer_context_create(struct Base **bases,
-                                      const uint bases_len,
-                                      short select_mode);
+/* draw_select_buffer.c */
 bool DRW_select_buffer_elem_get(const uint sel_id,
                                 uint *r_elem,
                                 uint *r_base_index,
                                 char *r_elem_type);
-uint DRW_select_buffer_context_offset_for_object_elem(const uint base_index, char elem_type);
-uint *DRW_select_buffer_read(const struct rcti *rect, uint *r_buf_len);
-void DRW_draw_select_id_object(struct Depsgraph *depsgraph,
-                               struct ViewLayer *view_layer,
-                               struct ARegion *ar,
-                               struct View3D *v3d,
-                               struct Object *ob,
-                               short select_mode);
-uint *DRW_select_buffer_bitmap_from_rect(const struct rcti *rect, uint *r_bitmap_len);
-uint *DRW_select_buffer_bitmap_from_circle(const int center[2],
+uint DRW_select_buffer_context_offset_for_object_elem(struct Depsgraph *depsgraph,
+                                                      struct Object *object,
+                                                      char elem_type);
+uint *DRW_select_buffer_read(struct Depsgraph *depsgraph,
+                             struct ARegion *ar,
+                             struct View3D *v3d,
+                             const rcti *rect,
+                             uint *r_buf_len);
+uint *DRW_select_buffer_bitmap_from_rect(struct Depsgraph *depsgraph,
+                                         struct ARegion *ar,
+                                         struct View3D *v3d,
+                                         const struct rcti *rect,
+                                         uint *r_bitmap_len);
+uint *DRW_select_buffer_bitmap_from_circle(struct Depsgraph *depsgraph,
+                                           struct ARegion *ar,
+                                           struct View3D *v3d,
+                                           const int center[2],
                                            const int radius,
                                            uint *r_bitmap_len);
-uint *DRW_select_buffer_bitmap_from_poly(const int poly[][2],
+uint *DRW_select_buffer_bitmap_from_poly(struct Depsgraph *depsgraph,
+                                         struct ARegion *ar,
+                                         struct View3D *v3d,
+                                         const int poly[][2],
                                          const int poly_len,
-                                         const struct rcti *rect);
-uint DRW_select_buffer_sample_point(const int center[2]);
-uint DRW_select_buffer_find_nearest_to_point(const int center[2],
+                                         const struct rcti *rect,
+                                         uint *r_bitmap_len);
+uint DRW_select_buffer_sample_point(struct Depsgraph *depsgraph,
+                                    struct ARegion *ar,
+                                    struct View3D *v3d,
+                                    const int center[2]);
+uint DRW_select_buffer_find_nearest_to_point(struct Depsgraph *depsgraph,
+                                             struct ARegion *ar,
+                                             struct View3D *v3d,
+                                             const int center[2],
                                              const uint id_min,
                                              const uint id_max,
                                              uint *dist);
+void DRW_select_buffer_context_create(struct Base **bases,
+                                      const uint bases_len,
+                                      short select_mode);
 
 /* select_engine.c */
 struct SELECTID_Context *DRW_select_engine_context_get(void);
diff --git a/source/blender/draw/engines/select/select_draw_utils.c b/source/blender/draw/engines/select/select_draw_utils.c
index b65a158cdcf..268cd60a8aa 100644
--- a/source/blender/draw/engines/select/select_draw_utils.c
+++ b/source/blender/draw/engines/select/select_draw_utils.c
@@ -23,6 +23,8 @@
  */
 
 #include "BKE_editmesh.h"
+#include "BKE_mesh.h"
+#include "BKE_object.h"
 
 #include "DNA_mesh_types.h"
 #include "DNA_scene_types.h"
@@ -42,7 +44,7 @@
 /** \name Draw Utilities
  * \{ */
 
-void draw_select_framebuffer_select_id_setup(struct SELECTID_Context *select_ctx)
+static void select_id_framebuffer_setup(struct SELECTID_Context *select_ctx)
 {
   DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
   int size[2];
@@ -73,6 +75,32 @@ void draw_select_framebuffer_select_id_setup(struct SELECTID_Context *select_ctx
   }
 }
 
+/* Remove all tags from drawn or culled objects. */
+void select_id_context_clear(struct SELECTID_Context *select_ctx)
+{
+  select_ctx->objects_drawn_len = 0;
+  select_ctx->index_drawn_len = 1;
+  select_id_framebuffer_setup(select_ctx);
+  GPU_framebuffer_bind(select_ctx->framebuffer_select_id);
+  GPU_framebuffer_clear_color_depth(
+      select_ctx->framebuffer_select_id, (const float[4]){0.0f}, 1.0f);
+}
+
+void select_id_object_min_max(Object *obj, float r_min[3], float r_max[3])
+{
+  BoundBox *bb;
+  BMEditMesh *em = BKE_editmesh_from_object(obj);
+  if (em) {
+    /* Use Object Texture Space. */
+    bb = BKE_mesh_texspace_get(em->mesh_eval_cage, NULL, NULL, NULL);
+  }
+  else {
+    bb = BKE_object_boundbox_get(obj);
+  }
+  copy_v3_v3(r_min, bb->vec[0]);
+  copy_v3_v3(r_max, bb->vec[6]);
+}
+
 short select_id_get_object_select_mode(Scene *scene, Object *ob)
 {
   short r_select_mode = 0;
@@ -132,7 +160,7 @@ static void draw_select_id_edit_mesh(SELECTID_StorageList *stl,
 
     if (draw_facedot) {
       struct GPUBatch *geom_facedots = DRW_mesh_batch_cache_get_facedots_with_select_id(me);
-      DRW_shgroup_call(face_shgrp, geom_facedots, ob);
+      DRW_shgroup_call_no_cull(face_shgrp, geom_facedots, ob);
     }
     *r_face_offset = initial_offset + em->bm->totface;
   }
@@ -141,14 +169,14 @@ static void draw_select_id_edit_mesh(SELECTID_StorageList *stl,
     face_shgrp = stl->g_data->shgrp_face_unif;
     *r_face_offset = initial_offset;
   }
-  DRW_shgroup_call(face_shgrp, geom_faces, ob);
+  DRW_shgroup_call_no_cull(face_shgrp, geom_faces, ob);
 
   /* Unlike faces, only draw edges if edge select mode. */
   if (select_mode & SCE_SELECT_EDGE) {
     struct GPUBatch *geom_edges = DRW_mesh_batch_cache_get_edges_with_select_id(me);
     DRWShadingGroup *edge_shgrp = DRW_shgroup_create_sub(stl->g_data->shgrp_edge);
     DRW_shgroup_uniform_int_copy(edge_shgrp, "offset", *(int *)r_face_offset);
-    DRW_shgroup_call(edge_shgrp, geom_edges, ob);
+    DRW_shgroup_call_no_cull(edge_shgrp, geom_edges, ob);
     *r_edge_offset = *r_face_offset + em->bm->totedge;
   }
   else {
@@ -162,7 +190,7 @@ static void draw_select_id_edit_mesh(SELECTID_StorageList *stl,
     struct GPUBatch *geom_verts = DRW_mesh_batch_cache_get_verts_with_select_id(me);
     DRWShadingGroup *vert_shgrp = DRW_shgroup_create_sub(stl->g_data->shgrp_vert);
     DRW_shgroup_uniform_int_copy(vert_shgrp, "offset", *(int *)r_edge_offset);
-    DRW_shgroup_call(vert_shgrp, geom_verts, ob);
+    DRW_shgroup_call_no_cull(vert_shgrp, geom_verts, ob);
     *r_vert_offset = *r_edge_offset + em->bm->totvert;
   }
   else {
@@ -192,13 +220,13 @@ static void draw_select_id_mesh(SELECTID_StorageList *stl,
     face_shgrp = stl->g_data->shgrp_face_unif;
     *r_face_offset = initial_offset;
   }
-  DRW_shgroup_call(face_shgrp, geom_faces, ob);
+  DRW_shgroup_call_no_cull(face_shgrp, geom_faces, ob);
 
   if (select_mode & SCE_SELECT_EDGE) {
     struct GPUBatch *geom_edges = DRW_mesh_batch_cache_get_edges_with_select_id(me);
     DRWShadingGroup *edge_shgrp = DRW_shgroup_create_sub(stl->g_data->shgrp_edge);
     DRW_shgroup_uniform_int_copy(edge_shgrp, "offset", *(int *)r_face_offset);
-    DRW_shgroup_call(edge_shgrp, geom_edge

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list