[Bf-blender-cvs] [2f2fb4453f9] eevee-motionblur-object: DRW: Batch Cache: Expose position vertex buffer to engine

Clément Foucault noreply at git.blender.org
Tue Apr 14 19:09:14 CEST 2020


Commit: 2f2fb4453f9e89fc38c9e7d5772332d477bca4c5
Author: Clément Foucault
Date:   Mon Apr 6 17:32:27 2020 +0200
Branches: eevee-motionblur-object
https://developer.blender.org/rB2f2fb4453f9e89fc38c9e7d5772332d477bca4c5

DRW: Batch Cache: Expose position vertex buffer to engine

This is in order to compute position deltas for motion blur. The engine
is responsible to handle the data. However it is not the owner of the data.
So a copy must be performed if the data needs to be kept accross frame.

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

M	source/blender/draw/intern/draw_cache.c
M	source/blender/draw/intern/draw_cache.h
M	source/blender/draw/intern/draw_cache_impl.h
M	source/blender/draw/intern/draw_cache_impl_curve.c
M	source/blender/draw/intern/draw_cache_impl_mesh.c
M	source/blender/draw/intern/draw_cache_impl_metaball.c
M	source/blender/draw/intern/draw_cache_inline.h

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

diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c
index ffd3be9280f..9edb5473a46 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -888,6 +888,32 @@ GPUBatch *DRW_cache_object_surface_get(Object *ob)
   }
 }
 
+/* Returns the vertbuf used by shaded surface batch. */
+GPUVertBuf *DRW_cache_object_pos_vertbuf_get(Object *ob)
+{
+  Mesh *me = BKE_object_get_evaluated_mesh(ob);
+  short type = (me != NULL) ? OB_MESH : ob->type;
+
+  switch (type) {
+    case OB_MESH:
+      return DRW_mesh_batch_cache_pos_vertbuf_get((me != NULL) ? me : ob->data);
+    case OB_CURVE:
+    case OB_SURF:
+    case OB_FONT:
+      return DRW_curve_batch_cache_pos_vertbuf_get(ob->data);
+    case OB_MBALL:
+      return DRW_mball_batch_cache_pos_vertbuf_get(ob);
+    case OB_HAIR:
+      return NULL;
+    case OB_POINTCLOUD:
+      return NULL;
+    case OB_VOLUME:
+      return NULL;
+    default:
+      return NULL;
+  }
+}
+
 int DRW_cache_object_material_count_get(struct Object *ob)
 {
   Mesh *me = BKE_object_get_evaluated_mesh(ob);
diff --git a/source/blender/draw/intern/draw_cache.h b/source/blender/draw/intern/draw_cache.h
index 77c7b6b9307..4cbb0abbf4a 100644
--- a/source/blender/draw/intern/draw_cache.h
+++ b/source/blender/draw/intern/draw_cache.h
@@ -63,6 +63,8 @@ struct GPUBatch **DRW_cache_object_surface_material_get(struct Object *ob,
 struct GPUBatch *DRW_cache_object_face_wireframe_get(struct Object *ob);
 int DRW_cache_object_material_count_get(struct Object *ob);
 
+struct GPUVertBuf *DRW_cache_object_pos_vertbuf_get(struct Object *ob);
+
 /* Empties */
 struct GPUBatch *DRW_cache_plain_axes_get(void);
 struct GPUBatch *DRW_cache_single_arrow_get(void);
diff --git a/source/blender/draw/intern/draw_cache_impl.h b/source/blender/draw/intern/draw_cache_impl.h
index 3ce8a7d4e43..b87ffdf1c23 100644
--- a/source/blender/draw/intern/draw_cache_impl.h
+++ b/source/blender/draw/intern/draw_cache_impl.h
@@ -197,6 +197,11 @@ struct GPUBatch *DRW_mesh_batch_cache_get_edituv_facedots(struct Mesh *me);
 struct GPUBatch *DRW_mesh_batch_cache_get_uv_edges(struct Mesh *me);
 struct GPUBatch *DRW_mesh_batch_cache_get_edit_mesh_analysis(struct Mesh *me);
 
+/* For direct data access. */
+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(struct Mesh *me);
 
 /* Edit mesh bitflags (is this the right place?) */
diff --git a/source/blender/draw/intern/draw_cache_impl_curve.c b/source/blender/draw/intern/draw_cache_impl_curve.c
index 331f8073ed5..d77b593a049 100644
--- a/source/blender/draw/intern/draw_cache_impl_curve.c
+++ b/source/blender/draw/intern/draw_cache_impl_curve.c
@@ -891,6 +891,16 @@ GPUBatch **DRW_curve_batch_cache_get_surface_shaded(struct Curve *cu,
   return cache->surf_per_mat;
 }
 
+GPUVertBuf *DRW_curve_batch_cache_pos_vertbuf_get(struct Curve *cu)
+{
+  CurveBatchCache *cache = curve_batch_cache_get(cu);
+  /* Request surface to trigger the vbo filling. Otherwise it may do nothing. */
+  DRW_batch_request(&cache->batch.surfaces);
+
+  DRW_vbo_request(NULL, &cache->ordered.loop_pos_nor);
+  return cache->ordered.loop_pos_nor;
+}
+
 GPUBatch *DRW_curve_batch_cache_get_wireframes_face(Curve *cu)
 {
   CurveBatchCache *cache = curve_batch_cache_get(cu);
diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c
index fb0423a87a6..9dee062a7a5 100644
--- a/source/blender/draw/intern/draw_cache_impl_mesh.c
+++ b/source/blender/draw/intern/draw_cache_impl_mesh.c
@@ -792,6 +792,23 @@ int DRW_mesh_material_count_get(Mesh *me)
 
 /** \} */
 
+/* ---------------------------------------------------------------------- */
+/** \name Edit Mode API
+ * \{ */
+
+GPUVertBuf *DRW_mesh_batch_cache_pos_vertbuf_get(Mesh *me)
+{
+  MeshBatchCache *cache = mesh_batch_cache_get(me);
+  /* Request surface to trigger the vbo filling. Otherwise it may do nothing. */
+  mesh_batch_cache_add_request(cache, MBC_SURFACE);
+  DRW_batch_request(&cache->batch.surface);
+
+  DRW_vbo_request(NULL, &cache->final.vbo.pos_nor);
+  return cache->final.vbo.pos_nor;
+}
+
+/** \} */
+
 /* ---------------------------------------------------------------------- */
 /** \name Edit Mode API
  * \{ */
diff --git a/source/blender/draw/intern/draw_cache_impl_metaball.c b/source/blender/draw/intern/draw_cache_impl_metaball.c
index c14e66c2b47..076d32ffe1f 100644
--- a/source/blender/draw/intern/draw_cache_impl_metaball.c
+++ b/source/blender/draw/intern/draw_cache_impl_metaball.c
@@ -274,6 +274,18 @@ struct GPUBatch *DRW_metaball_batch_cache_get_edge_detection(struct Object *ob,
   return cache->edge_detection;
 }
 
+struct GPUVertBuf *DRW_mball_batch_cache_pos_vertbuf_get(Object *ob)
+{
+  if (!BKE_mball_is_basis(ob)) {
+    return NULL;
+  }
+
+  MetaBall *mb = ob->data;
+  MetaBallBatchCache *cache = metaball_batch_cache_get(mb);
+
+  return mball_batch_cache_get_pos_and_normals(ob, cache);
+}
+
 int DRW_metaball_material_count_get(MetaBall *mb)
 {
   return max_ii(1, mb->totcol);
diff --git a/source/blender/draw/intern/draw_cache_inline.h b/source/blender/draw/intern/draw_cache_inline.h
index a067434f3bb..67f44b5fb0c 100644
--- a/source/blender/draw/intern/draw_cache_inline.h
+++ b/source/blender/draw/intern/draw_cache_inline.h
@@ -90,17 +90,19 @@ BLI_INLINE void DRW_vbo_request(GPUBatch *batch, GPUVertBuf **vbo)
   if (*vbo == NULL) {
     *vbo = MEM_callocN(sizeof(GPUVertBuf), "GPUVertBuf");
   }
-  /* HACK set first vbo if not init. */
-  if (batch->verts[0] == NULL) {
-    GPU_batch_vao_cache_clear(batch);
-    batch->verts[0] = *vbo;
-  }
-  else {
-    /* HACK: bypass assert */
-    int vbo_vert_len = (*vbo)->vertex_len;
-    (*vbo)->vertex_len = batch->verts[0]->vertex_len;
-    GPU_batch_vertbuf_add(batch, *vbo);
-    (*vbo)->vertex_len = vbo_vert_len;
+  if (batch != NULL) {
+    /* HACK set first vbo if not init. */
+    if (batch->verts[0] == NULL) {
+      GPU_batch_vao_cache_clear(batch);
+      batch->verts[0] = *vbo;
+    }
+    else {
+      /* HACK: bypass assert */
+      int vbo_vert_len = (*vbo)->vertex_len;
+      (*vbo)->vertex_len = batch->verts[0]->vertex_len;
+      GPU_batch_vertbuf_add(batch, *vbo);
+      (*vbo)->vertex_len = vbo_vert_len;
+    }
   }
 }



More information about the Bf-blender-cvs mailing list