Commit: 651d8bfd98db11eb58018412cc030cfe2705c519
Author: mano-wii
Date:   Tue Jul 30 06:46:59 2019 -0300
Branches: master
https://developer.blender.org/rB651d8bfd98db11eb58018412cc030cfe2705c519

3D View: Move selection API to a Selection engine.

This commit moves the API of selecting faces, vertices and edges to a DRW 
manager engine.

Reviewers: campbellbarton, fclem

Subscribers: jbakker, brecht

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

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

M       source/blender/draw/CMakeLists.txt
M       source/blender/draw/DRW_engine.h
A       source/blender/draw/engines/select/select_engine.c
A       source/blender/draw/engines/select/select_engine.h
A       source/blender/draw/engines/select/shaders/selection_id_3D_vert.glsl
R061    source/blender/gpu/shaders/gpu_shader_selection_id_frag.glsl    
source/blender/draw/engines/select/shaders/selection_id_frag.glsl
M       source/blender/draw/intern/draw_manager.c
M       source/blender/editors/include/ED_view3d.h
M       source/blender/editors/mesh/CMakeLists.txt
M       source/blender/editors/mesh/editmesh_select.c
M       source/blender/editors/space_view3d/view3d_draw_legacy.c
M       source/blender/editors/space_view3d/view3d_select.c
M       source/blender/gpu/CMakeLists.txt
M       source/blender/gpu/GPU_shader.h
M       source/blender/gpu/intern/gpu_shader.c
D       source/blender/gpu/shaders/gpu_shader_3D_selection_id_vert.glsl

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

diff --git a/source/blender/draw/CMakeLists.txt 
b/source/blender/draw/CMakeLists.txt
index 8631a9f556b..664484d9a57 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -126,6 +126,7 @@ set(SRC
   engines/gpencil/gpencil_engine.h
   engines/gpencil/gpencil_render.c
   engines/gpencil/gpencil_shader_fx.c
+  engines/select/select_engine.c
 
   DRW_engine.h
   intern/DRW_render.h
@@ -150,6 +151,7 @@ set(SRC
   engines/external/external_engine.h
   engines/workbench/workbench_engine.h
   engines/workbench/workbench_private.h
+  engines/select/select_engine.h
 )
 
 set(LIB
@@ -363,6 +365,9 @@ 
data_to_c_simple(engines/gpencil/shaders/fx/gpencil_fx_shadow_resolve_frag.glsl
 data_to_c_simple(engines/gpencil/shaders/fx/gpencil_fx_swirl_frag.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/fx/gpencil_fx_wave_frag.glsl SRC)
 
+data_to_c_simple(engines/select/shaders/selection_id_3D_vert.glsl SRC)
+data_to_c_simple(engines/select/shaders/selection_id_frag.glsl SRC)
+
 
 list(APPEND INC
 )
diff --git a/source/blender/draw/DRW_engine.h b/source/blender/draw/DRW_engine.h
index 5919e100ddd..64a02f3931b 100644
--- a/source/blender/draw/DRW_engine.h
+++ b/source/blender/draw/DRW_engine.h
@@ -26,6 +26,7 @@
 #include "BLI_sys_types.h" /* for bool */
 
 struct ARegion;
+struct Base;
 struct DRWInstanceDataList;
 struct DRWPass;
 struct Depsgraph;
@@ -136,19 +137,12 @@ void DRW_draw_depth_loop_gpencil(struct Depsgraph 
*depsgraph,
 void DRW_draw_depth_object(struct ARegion *ar,
                            struct GPUViewport *viewport,
                            struct Object *object);
-void DRW_draw_select_id_object(struct Scene *scene,
-                               struct RegionView3D *rv3d,
-                               struct Object *ob,
-                               short select_mode,
-                               bool draw_facedot,
-                               uint initial_offset,
-                               uint *r_vert_offset,
-                               uint *r_edge_offset,
-                               uint *r_face_offset);
-
-void DRW_framebuffer_select_id_setup(struct ARegion *ar, const bool clear);
-void DRW_framebuffer_select_id_release(struct ARegion *ar);
-void DRW_framebuffer_select_id_read(const struct rcti *rect, uint *r_buf);
+void DRW_draw_select_id(struct Depsgraph *depsgraph,
+                        struct ARegion *ar,
+                        struct View3D *v3d,
+                        struct Base **bases,
+                        const uint bases_len,
+                        short select_mode);
 
 /* grease pencil render */
 bool DRW_render_check_grease_pencil(struct Depsgraph *depsgraph);
@@ -181,4 +175,20 @@ void DRW_deferred_shader_remove(struct GPUMaterial *mat);
 struct DrawDataList *DRW_drawdatalist_from_id(struct ID *id);
 void DRW_drawdata_free(struct ID *id);
 
+/* select_engine.c */
+void DRW_select_context_create(struct Depsgraph *depsgraph,
+                               struct Base **bases,
+                               const uint bases_len,
+                               short select_mode);
+bool DRW_select_elem_get(const uint sel_id, uint *r_elem, uint *r_base_index, 
char *r_elem_type);
+uint DRW_select_context_offset_for_object_elem(const uint base_index, char 
elem_type);
+uint DRW_select_context_elem_len(void);
+void DRW_framebuffer_select_id_read(const struct rcti *rect, uint *r_buf);
+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);
+
 #endif /* __DRW_ENGINE_H__ */
diff --git a/source/blender/draw/engines/select/select_engine.c 
b/source/blender/draw/engines/select/select_engine.c
new file mode 100644
index 00000000000..f1fc9cbc0d6
--- /dev/null
+++ b/source/blender/draw/engines/select/select_engine.c
@@ -0,0 +1,647 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Copyright 2019, Blender Foundation.
+ */
+
+/** \file
+ * \ingroup draw_engine
+ *
+ * Engine for drawing a selection map where the pixels indicate the selection 
indices.
+ */
+
+#include "BLI_rect.h"
+
+#include "BKE_editmesh.h"
+
+#include "DNA_mesh_types.h"
+#include "DNA_screen_types.h"
+
+#include "ED_view3d.h"
+
+#include "GPU_shader.h"
+#include "GPU_select.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
+#include "UI_resources.h"
+
+#include "DRW_engine.h"
+#include "DRW_render.h"
+
+#include "draw_cache_impl.h"
+
+#include "select_engine.h"
+/* Shaders */
+
+#define SELECT_ENGINE "SELECT_ENGINE"
+
+/* *********** LISTS *********** */
+
+/* GPUViewport.storage
+ * Is freed everytime the viewport engine changes */
+typedef struct SELECTID_StorageList {
+  struct SELECTID_PrivateData *g_data;
+} SELECTID_StorageList;
+
+typedef struct SELECTID_PassList {
+  struct DRWPass *select_id_face_pass;
+  struct DRWPass *select_id_edge_pass;
+  struct DRWPass *select_id_vert_pass;
+} SELECTID_PassList;
+
+typedef struct SELECTID_Data {
+  void *engine_type;
+  DRWViewportEmptyList *fbl;
+  DRWViewportEmptyList *txl;
+  SELECTID_PassList *psl;
+  SELECTID_StorageList *stl;
+} SELECTID_Data;
+
+typedef struct SELECTID_Shaders {
+  /* Depth Pre Pass */
+  struct GPUShader *select_id_flat;
+  struct GPUShader *select_id_uniform;
+} SELECTID_Shaders;
+
+/* *********** STATIC *********** */
+
+static struct {
+  SELECTID_Shaders sh_data[GPU_SHADER_CFG_LEN];
+
+  struct GPUFrameBuffer *framebuffer_select_id;
+  struct GPUTexture *texture_u32;
+
+  struct {
+    struct BaseOffset *base_array_index_offsets;
+    uint bases_len;
+    uint last_base_drawn;
+    /** Total number of items `base_array_index_offsets[bases_len - 1].vert`. 
*/
+    uint last_index_drawn;
+
+    struct Depsgraph *depsgraph;
+    short select_mode;
+  } context;
+} e_data = {{{NULL}}}; /* Engine data */
+
+typedef struct SELECTID_PrivateData {
+  DRWShadingGroup *shgrp_face_unif;
+  DRWShadingGroup *shgrp_face_flat;
+  DRWShadingGroup *shgrp_edge;
+  DRWShadingGroup *shgrp_vert;
+
+  DRWView *view_faces;
+  DRWView *view_edges;
+  DRWView *view_verts;
+} SELECTID_PrivateData; /* Transient data */
+
+struct BaseOffset {
+  /* For convenience only. */
+  union {
+    uint offset;
+    uint face_start;
+  };
+  union {
+    uint face;
+    uint edge_start;
+  };
+  union {
+    uint edge;
+    uint vert_start;
+  };
+  uint vert;
+};
+
+/* Shaders */
+extern char datatoc_common_view_lib_glsl[];
+extern char datatoc_selection_id_3D_vert_glsl[];
+extern char datatoc_selection_id_frag_glsl[];
+
+/* -------------------------------------------------------------------- */
+/** \name Selection Utilities
+ * \{ */
+
+static void draw_select_framebuffer_select_id_setup(void)
+{
+  DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+  int size[2];
+  size[0] = GPU_texture_width(dtxl->depth);
+  size[1] = GPU_texture_height(dtxl->depth);
+
+  if (e_data.framebuffer_select_id == NULL) {
+    e_data.framebuffer_select_id = GPU_framebuffer_create();
+  }
+
+  if ((e_data.texture_u32 != NULL) && ((GPU_texture_width(e_data.texture_u32) 
!= size[0]) ||
+                                       (GPU_texture_height(e_data.texture_u32) 
!= size[1]))) {
+
+    GPU_texture_free(e_data.texture_u32);
+    e_data.texture_u32 = NULL;
+  }
+
+  if (e_data.texture_u32 == NULL) {
+    e_data.texture_u32 = GPU_texture_create_2d(size[0], size[1], GPU_R32UI, 
NULL, NULL);
+
+    GPU_framebuffer_texture_attach(e_data.framebuffer_select_id, dtxl->depth, 
0, 0);
+    GPU_framebuffer_texture_attach(e_data.framebuffer_select_id, 
e_data.texture_u32, 0, 0);
+    GPU_framebuffer_check_valid(e_data.framebuffer_select_id, NULL);
+  }
+}
+
+static void draw_select_id_object(void *vedata,
+                                  Object *ob,
+                                  short select_mode,
+                                  bool draw_facedot,
+                                  uint initial_offset,
+                                  uint *r_vert_offset,
+                                  uint *r_edge_offset,
+                                  uint *r_face_offset)
+{
+  SELECTID_StorageList *stl = ((SELECTID_Data *)vedata)->stl;
+
+  BLI_assert(initial_offset > 0);
+
+  switch (ob->type) {
+    case OB_MESH:
+      if (ob->mode & OB_MODE_EDIT) {
+        Mesh *me = ob->data;
+        BMEditMesh *em = me->edit_mesh;
+        const bool use_faceselect = (select_mode & SCE_SELECT_FACE) != 0;
+
+        DRW_mesh_batch_cache_validate(me);
+
+        BM_mesh_elem_table_ensure(em->bm, BM_VERT | BM_EDGE | BM_FACE);
+
+        struct GPUBatch *geom_faces, *geom_edges, *geom_verts, *geom_facedots;
+        geom_faces = DRW_mesh_batch_cache_get_triangles_with_select_id(me);
+        if (select_mode & SCE_SELECT_EDGE) {
+          geom_edges = DRW_mesh_batch_cache_get_edges_with_select_id(me);
+        }
+        if (select_mode & SCE_SELECT_VERTEX) {
+          geom_verts = DRW_mesh_batch_cache_get_verts_with_select_id(me);
+        }
+        if (use_faceselect && draw_facedot) {
+          geom_facedots = DRW_mesh_batch_cache_get_facedots_with_select_id(me);
+        }
+        DRW_mesh_batch_cache_create_requested(ob, me, NULL, false, true);
+
+        DRWShadingGroup *face_shgrp;
+        if (use_faceselect) {
+          face_shgrp = DRW_shgroup_create_sub(stl->g_data->shgrp_face_flat);
+          DRW_shgroup_u

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to