[Bf-blender-cvs] [b318024e7d1] greasepencil-object: Merge branch 'master' into greasepencil-object

2020-01-03 Thread Antonio Vazquez
Commit: b318024e7d13b8f8f3d3cf61029f4d1473cd1185
Author: Antonio Vazquez
Date:   Sat Jan 4 08:46:03 2020 +0100
Branches: greasepencil-object
https://developer.blender.org/rBb318024e7d13b8f8f3d3cf61029f4d1473cd1185

Merge branch 'master' into greasepencil-object

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [7fd76c2645f] greasepencil-refactor: Merge branch 'greasepencil-object' into greasepencil-refactor

2020-01-03 Thread Antonio Vazquez
Commit: 7fd76c2645f7b655342b179d35e841e4e8991478
Author: Antonio Vazquez
Date:   Sat Jan 4 08:46:49 2020 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rB7fd76c2645f7b655342b179d35e841e4e8991478

Merge branch 'greasepencil-object' into greasepencil-refactor

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [aad09525fb5] master: BLI_bvhtree_overlap: Fix wrong count of child nodes

2020-01-03 Thread mano-wii
Commit: aad09525fb554ed023419d1c4fd12a5b8da72660
Author: mano-wii
Date:   Sat Jan 4 00:34:47 2020 -0300
Branches: master
https://developer.blender.org/rBaad09525fb554ed023419d1c4fd12a5b8da72660

BLI_bvhtree_overlap: Fix wrong count of child nodes

As you can see, here is testing the "children" of `node1`.
So bvhtree is `tree1`.

This problem has never been observed because usually `tree_type`
of `tree1` equals `tree_type` of `tree2`.

===

M   source/blender/blenlib/intern/BLI_kdopbvh.c

===

diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c 
b/source/blender/blenlib/intern/BLI_kdopbvh.c
index 2674e6c61dc..7ac4a362cf4 100644
--- a/source/blender/blenlib/intern/BLI_kdopbvh.c
+++ b/source/blender/blenlib/intern/BLI_kdopbvh.c
@@ -1129,7 +1129,7 @@ static void tree_overlap_traverse(BVHOverlapData_Thread 
*data_thread,
   }
 }
 else {
-  for (j = 0; j < data->tree2->tree_type; j++) {
+  for (j = 0; j < data->tree1->tree_type; j++) {
 if (node1->children[j]) {
   tree_overlap_traverse(data_thread, node1->children[j], node2);
 }
@@ -1176,7 +1176,7 @@ static void 
tree_overlap_traverse_cb(BVHOverlapData_Thread *data_thread,
   }
 }
 else {
-  for (j = 0; j < data->tree2->tree_type; j++) {
+  for (j = 0; j < data->tree1->tree_type; j++) {
 if (node1->children[j]) {
   tree_overlap_traverse_cb(data_thread, node1->children[j], node2);
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [025d13045ab] master: BLI_bvhtree_overlap: Make sure the number of nodes matches the number of threads

2020-01-03 Thread mano-wii
Commit: 025d13045abec142528f44576bfdcce9ef0da90a
Author: mano-wii
Date:   Fri Jan 3 23:06:07 2020 -0300
Branches: master
https://developer.blender.org/rB025d13045abec142528f44576bfdcce9ef0da90a

BLI_bvhtree_overlap: Make sure the number of nodes matches the number of threads

===

M   source/blender/blenlib/intern/BLI_kdopbvh.c

===

diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c 
b/source/blender/blenlib/intern/BLI_kdopbvh.c
index 994fd510ac8..2674e6c61dc 100644
--- a/source/blender/blenlib/intern/BLI_kdopbvh.c
+++ b/source/blender/blenlib/intern/BLI_kdopbvh.c
@@ -1302,7 +1302,8 @@ BVHTreeOverlap *BLI_bvhtree_overlap_ex(
   /* `RETURN_PAIRS` was not implemented without `max_interations`. */
   BLI_assert(overlap_pairs || max_interactions);
 
-  const int thread_num = use_threading ? BLI_bvhtree_overlap_thread_num(tree1) 
: 1;
+  const int root_node_len = BLI_bvhtree_overlap_thread_num(tree1);
+  const int thread_num = use_threading ? root_node_len : 1;
   int j;
   size_t total = 0;
   BVHTreeOverlap *overlap = NULL, *to = NULL;
@@ -1352,7 +1353,7 @@ BVHTreeOverlap *BLI_bvhtree_overlap_ex(
   BLI_parallel_range_settings_defaults();
   settings.use_threading = use_threading;
   BLI_task_parallel_range(0,
-  root1->totnode,
+  root_node_len,
   data,
   max_interactions ? bvhtree_overlap_num_task_cb : 
bvhtree_overlap_task_cb,
   );

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [ad6c66fa3e1] master: Edit Mesh: Multithread support for Auto Merge & Split

2020-01-03 Thread mano-wii
Commit: ad6c66fa3e1c21eebf68291ec1b8c9c1b7c5cf0c
Author: mano-wii
Date:   Fri Jan 3 22:54:15 2020 -0300
Branches: master
https://developer.blender.org/rBad6c66fa3e1c21eebf68291ec1b8c9c1b7c5cf0c

Edit Mesh: Multithread support for Auto Merge & Split

Also collapsed edges are no longer used in the overlap test.
This greatly improves peformanse for cases where the distance tested is
relatively large.

===

M   source/blender/bmesh/tools/bmesh_intersect_edges.c

===

diff --git a/source/blender/bmesh/tools/bmesh_intersect_edges.c 
b/source/blender/bmesh/tools/bmesh_intersect_edges.c
index 27102694e88..721f820b103 100644
--- a/source/blender/bmesh/tools/bmesh_intersect_edges.c
+++ b/source/blender/bmesh/tools/bmesh_intersect_edges.c
@@ -33,6 +33,7 @@
 
 #include "bmesh_intersect_edges.h" /* own include */
 
+#define KDOP_TREE_TYPE 4
 #define KDOP_AXIS_LEN 14
 
 /*  */
@@ -239,7 +240,7 @@ struct EDBMSplitElem {
 
 struct EDBMSplitData {
   BMesh *bm;
-  BLI_Stack *pair_stack;
+  BLI_Stack **pair_stack;
   int cut_edges_len;
   float dist_sq;
   float dist_sq_sq;
@@ -318,17 +319,14 @@ static bool bm_edgexvert_isect_impl(BMVert *v,
 
 /* Vertex x Vertex Callback */
 
-static bool bm_vertxvert_isect_cb(void *userdata, int index_a, int index_b, 
int UNUSED(thread))
+static bool bm_vertxvert_isect_cb(void *userdata, int index_a, int index_b, 
int thread)
 {
   struct EDBMSplitData *data = userdata;
   BMVert *v_a = BM_vert_at_index(data->bm, index_a);
   BMVert *v_b = BM_vert_at_index(data->bm, index_b);
 
-  struct EDBMSplitElem *pair = BLI_stack_push_r(data->pair_stack);
+  struct EDBMSplitElem *pair = BLI_stack_push_r(data->pair_stack[thread]);
 
-  BLI_assert(v_a->head.index == -1);
-
-  /* Set index -2 for sure that it will not repeat keys in `targetmap`. */
   bm_vert_pair_elem_setup_ex(v_a, [0]);
   bm_vert_pair_elem_setup_ex(v_b, [1]);
 
@@ -345,7 +343,7 @@ static bool bm_vertxvert_self_isect_cb(void *userdata, int 
index_a, int index_b,
 
 /* Vertex x Edge and Edge x Vertex Callbacks */
 
-static bool bm_edgexvert_isect_cb(void *userdata, int index_a, int index_b, 
int UNUSED(thread))
+static bool bm_edgexvert_isect_cb(void *userdata, int index_a, int index_b, 
int thread)
 {
   struct EDBMSplitData *data = userdata;
   BMEdge *e = BM_edge_at_index(data->bm, index_a);
@@ -359,7 +357,7 @@ static bool bm_edgexvert_isect_cb(void *userdata, int 
index_a, int index_b, int
   struct EDBMSplitElem pair_tmp[2];
   if (bm_edgexvert_isect_impl(
   v, e, co, dir, lambda, data->dist_sq, >cut_edges_len, 
pair_tmp)) {
-struct EDBMSplitElem *pair = BLI_stack_push_r(data->pair_stack);
+struct EDBMSplitElem *pair = BLI_stack_push_r(data->pair_stack[thread]);
 pair[0] = pair_tmp[0];
 pair[1] = pair_tmp[1];
   }
@@ -370,7 +368,7 @@ static bool bm_edgexvert_isect_cb(void *userdata, int 
index_a, int index_b, int
 
 /* Edge x Edge Callbacks */
 
-static void bm_edgexedge_isect_impl(struct EDBMSplitData *data,
+static bool bm_edgexedge_isect_impl(struct EDBMSplitData *data,
 BMEdge *e_a,
 BMEdge *e_b,
 const float co_a[3],
@@ -378,7 +376,8 @@ static void bm_edgexedge_isect_impl(struct EDBMSplitData 
*data,
 const float co_b[3],
 const float dir_b[3],
 float lambda_a,
-float lambda_b)
+float lambda_b,
+struct EDBMSplitElem r_pair[2])
 {
   float dist_sq_va_factor, dist_sq_vb_factor;
   BMVert *e_a_v, *e_b_v;
@@ -403,7 +402,7 @@ static void bm_edgexedge_isect_impl(struct EDBMSplitData 
*data,
   if (e_a_v != e_b_v) {
 if (!IN_RANGE_INCL(lambda_a, 0.0f, 1.0f) || !IN_RANGE_INCL(lambda_b, 0.0f, 
1.0f)) {
   /* Vert x Edge is already handled elsewhere. */
-  return;
+  return false;
 }
 
 float dist_sq_va = SQUARE(dist_sq_va_factor) * len_squared_v3(dir_a);
@@ -411,7 +410,7 @@ static void bm_edgexedge_isect_impl(struct EDBMSplitData 
*data,
 
 if (dist_sq_va < data->dist_sq || dist_sq_vb < data->dist_sq) {
   /* Vert x Edge is already handled elsewhere. */
-  return;
+  return false;
 }
 
 float near_a[3], near_b[3];
@@ -420,19 +419,15 @@ static void bm_edgexedge_isect_impl(struct EDBMSplitData 
*data,
 
 float dist_sq = len_squared_v3v3(near_a, near_b);
 if (dist_sq < data->dist_sq) {
-  struct EDBMSplitElem pair_tmp[2];
-
-  bm_edge_pair_elem_setup(e_a, lambda_a, >cut_edges_len, 
_tmp[0]);
-  bm_edge_pair_elem_setup(e_b, lambda_b, >cut_edges_len, 
_tmp[1]);
-
-  struct EDBMSplitElem *pair = 

[Bf-blender-cvs] [5659c8e0bf4] master: BLI_bvhtree_overlap: Improve non-multithreaded usage

2020-01-03 Thread mano-wii
Commit: 5659c8e0bf4393fe8e0eab5a4845aa09d35738ac
Author: mano-wii
Date:   Fri Jan 3 22:48:12 2020 -0300
Branches: master
https://developer.blender.org/rB5659c8e0bf4393fe8e0eab5a4845aa09d35738ac

BLI_bvhtree_overlap: Improve non-multithreaded usage

Although not using multithreading, the `thread` parameter in the
`BVHTree_OverlapCallback` callback always returned a value between the
"number of threads".

This parameter should always be 0 in such cases.

Also a `BLI_Stack` was created for each "thread" and used.
This small overhead is no longer seen.

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

===

M   source/blender/blenlib/intern/BLI_kdopbvh.c

===

diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c 
b/source/blender/blenlib/intern/BLI_kdopbvh.c
index 71f276bc68f..994fd510ac8 100644
--- a/source/blender/blenlib/intern/BLI_kdopbvh.c
+++ b/source/blender/blenlib/intern/BLI_kdopbvh.c
@@ -113,6 +113,7 @@ BLI_STATIC_ASSERT((sizeof(void *) == 8 && sizeof(BVHTree) 
<= 48) ||
 typedef struct BVHOverlapData_Shared {
   const BVHTree *tree1, *tree2;
   axis_t start_axis, stop_axis;
+  bool use_threading;
 
   /* use for callbacks */
   BVHTree_OverlapCallback callback;
@@ -1251,8 +1252,11 @@ static void bvhtree_overlap_task_cb(void *__restrict 
userdata,
 const int j,
 const TaskParallelTLS *__restrict 
UNUSED(tls))
 {
-  BVHOverlapData_Thread *data = &((BVHOverlapData_Thread *)userdata)[j];
+  BVHOverlapData_Thread *data = (BVHOverlapData_Thread *)userdata;
   BVHOverlapData_Shared *data_shared = data->shared;
+  if (data_shared->use_threading) {
+data += j;
+  }
 
   if (data_shared->callback) {
 tree_overlap_traverse_cb(data,
@@ -1270,8 +1274,11 @@ static void bvhtree_overlap_num_task_cb(void *__restrict 
userdata,
 const int j,
 const TaskParallelTLS *__restrict 
UNUSED(tls))
 {
-  BVHOverlapData_Thread *data = &((BVHOverlapData_Thread *)userdata)[j];
+  BVHOverlapData_Thread *data = (BVHOverlapData_Thread *)userdata;
   BVHOverlapData_Shared *data_shared = data->shared;
+  if (data_shared->use_threading) {
+data += j;
+  }
 
   tree_overlap_num_recursive(data,
  
data_shared->tree1->nodes[data_shared->tree1->totleaf]->children[j],
@@ -1288,13 +1295,14 @@ BVHTreeOverlap *BLI_bvhtree_overlap_ex(
 const uint max_interactions,
 const int flag)
 {
-  bool use_threading = (flag & BVH_OVERLAP_USE_THREADING) != 0;
   bool overlap_pairs = (flag & BVH_OVERLAP_RETURN_PAIRS) != 0;
+  bool use_threading = (flag & BVH_OVERLAP_USE_THREADING) != 0 &&
+   (tree1->totleaf > KDOPBVH_THREAD_LEAF_THRESHOLD);
 
   /* `RETURN_PAIRS` was not implemented without `max_interations`. */
   BLI_assert(overlap_pairs || max_interactions);
 
-  const int thread_num = BLI_bvhtree_overlap_thread_num(tree1);
+  const int thread_num = use_threading ? BLI_bvhtree_overlap_thread_num(tree1) 
: 1;
   int j;
   size_t total = 0;
   BVHTreeOverlap *overlap = NULL, *to = NULL;
@@ -1309,12 +1317,14 @@ BVHTreeOverlap *BLI_bvhtree_overlap_ex(
 return NULL;
   }
 
+  const BVHNode *root1 = tree1->nodes[tree1->totleaf];
+  const BVHNode *root2 = tree2->nodes[tree2->totleaf];
+
   start_axis = min_axis(tree1->start_axis, tree2->start_axis);
   stop_axis = min_axis(tree1->stop_axis, tree2->stop_axis);
 
   /* fast check root nodes for collision before doing big splitting + 
traversal */
-  if (!tree_overlap_test(
-  tree1->nodes[tree1->totleaf], tree2->nodes[tree2->totleaf], 
start_axis, stop_axis)) {
+  if (!tree_overlap_test(root1, root2, start_axis, stop_axis)) {
 return NULL;
   }
 
@@ -1322,6 +1332,7 @@ BVHTreeOverlap *BLI_bvhtree_overlap_ex(
   data_shared.tree2 = tree2;
   data_shared.start_axis = start_axis;
   data_shared.stop_axis = stop_axis;
+  data_shared.use_threading = use_threading;
 
   /* can be NULL */
   data_shared.callback = callback;
@@ -1339,9 +1350,9 @@ BVHTreeOverlap *BLI_bvhtree_overlap_ex(
 
   TaskParallelSettings settings;
   BLI_parallel_range_settings_defaults();
-  settings.use_threading = use_threading && (tree1->totleaf > 
KDOPBVH_THREAD_LEAF_THRESHOLD);
+  settings.use_threading = use_threading;
   BLI_task_parallel_range(0,
-  thread_num,
+  root1->totnode,
   data,
   max_interactions ? bvhtree_overlap_num_task_cb : 
bvhtree_overlap_task_cb,
   );

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [f0ba75639a9] greasepencil-refactor: GPencil: Refactor: Fix frame drawn without color when in onion skin + loop

2020-01-03 Thread Clément Foucault
Commit: f0ba75639a999b934b1d410f1d4b720d5e890fb1
Author: Clément Foucault
Date:   Sat Jan 4 00:34:22 2020 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rBf0ba75639a999b934b1d410f1d4b720d5e890fb1

GPencil: Refactor: Fix frame drawn without color when in onion skin + loop

===

M   source/blender/draw/engines/gpencil/gpencil_draw_utils.c

===

diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c 
b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
index 7270c257e52..eec8a43ae3f 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
@@ -115,7 +115,7 @@ void gpencil_object_visible_stroke_iter(
   /* We wrap the value using the last frame and 0 as reference. */
   /* FIXME: This might not be good for animations not starting at 
0. */
   int shift = (onion_mode_abs) ? last_gpf->framenum : 
last_gpf->runtime.frameid;
-  delta += (delta < 0) ? shift : -shift;
+  delta += (delta < 0) ? (shift + 1) : -(shift + 1);
   /* Test again with wrapped value. */
   is_in_range = (-delta <= gpd->gstep) && (delta <= 
gpd->gstep_next);
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [eca698867c8] greasepencil-refactor: GPencil: Refactor: Fix black GPobjects in hero files

2020-01-03 Thread Clément Foucault
Commit: eca698867c837c20b9ec1831bc3583628992a7d7
Author: Clément Foucault
Date:   Fri Jan 3 22:22:20 2020 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rBeca698867c837c20b9ec1831bc3583628992a7d7

GPencil: Refactor: Fix black GPobjects in hero files

This was due to missing light ubo. Now we use persistent uniform to avoid
missing a rebind.

===

M   source/blender/draw/engines/gpencil/gpencil_engine.c

===

diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c 
b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 58bf9db3e38..ad06810a878 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -939,6 +939,7 @@ static void gp_sbuffer_cache_populate(gpIterPopulateData 
*iter)
* Remember, sbuffer stroke indices start from 0. So we add last index to 
avoid
* masking issues. */
   iter->grp = DRW_shgroup_create_sub(iter->grp);
+  DRW_shgroup_uniform_block(iter->grp, "gpMaterialBlock", iter->ubo_mat);
   DRW_shgroup_uniform_float_copy(iter->grp, "strokeIndexOffset", 
iter->stroke_index_last);
 
   gp_stroke_cache_populate(NULL, NULL, iter->pd->sbuffer_stroke, iter);
@@ -987,7 +988,7 @@ static void gp_layer_cache_populate(bGPDlayer *gpl,
 
   struct GPUShader *sh = GPENCIL_shader_geometry_get(_data);
   iter->grp = DRW_shgroup_create(sh, tgp_layer->geom_ps);
-  DRW_shgroup_uniform_block(iter->grp, "gpLightBlock", iter->ubo_lights);
+  DRW_shgroup_uniform_block_persistent(iter->grp, "gpLightBlock", 
iter->ubo_lights);
   DRW_shgroup_uniform_block(iter->grp, "gpMaterialBlock", iter->ubo_mat);
   DRW_shgroup_uniform_texture(iter->grp, "gpFillTexture", iter->tex_fill);
   DRW_shgroup_uniform_texture(iter->grp, "gpStrokeTexture", iter->tex_stroke);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [94d228a4e4c] greasepencil-refactor: GPencil: Refactor: Add stroke fast drawing

2020-01-03 Thread Clément Foucault
Commit: 94d228a4e4c4aca3b08abb1129c8b6f1f2011e33
Author: Clément Foucault
Date:   Fri Jan 3 21:49:46 2020 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rB94d228a4e4c4aca3b08abb1129c8b6f1f2011e33

GPencil: Refactor: Add stroke fast drawing

This use the same behavior as previous implementation. It uses a temp
buffer to store the screen and avoid redraw.

But this will be only on demand as the drawing may not match the final
look when releasing the pen. The UI option has not been added yet.

This mode still supports blending and VFX. Just stroke ordering with the
scene not supported.

===

M   source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M   source/blender/draw/engines/gpencil/gpencil_engine.c
M   source/blender/draw/engines/gpencil/gpencil_engine.h

===

diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c 
b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
index 32c7d393955..bc6fe7efe75 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -321,6 +321,7 @@ bool GPENCIL_batch_from_sbuffer(Object *ob,
   copy_v2_v2(tpoints2d[i], [i].x);
 }
 /* Compute directly inside the IBO data buffer. */
+/* OPTI: This is a bottleneck if the stroke is very long. */
 BLI_polyfill_calc(tpoints2d, (uint)vert_len, 0, 
(uint(*)[3])ibo_builder.data);
 /* Add stroke start offset. */
 for (int i = 0; i < gps->tot_triangles * 3; i++) {
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c 
b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 8ee57a71e1b..58bf9db3e38 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -312,6 +312,8 @@ static void GPENCIL_engine_init_new(void *ved)
   stl->pd->last_material_pool = NULL;
   stl->pd->tobjects.first = NULL;
   stl->pd->tobjects.last = NULL;
+  stl->pd->sbuffer_tobjects.first = NULL;
+  stl->pd->sbuffer_tobjects.last = NULL;
   stl->pd->draw_depth_only = !DRW_state_is_fbo();
   stl->pd->scene_depth_tx = stl->pd->draw_depth_only ? txl->dummy_texture : 
dtxl->depth;
   stl->pd->is_render = true; /* TODO */
@@ -447,6 +449,8 @@ static void GPENCIL_cache_init_new(void *ved)
 {
   GPENCIL_Data *vedata = (GPENCIL_Data *)ved;
   GPENCIL_PassList *psl = vedata->psl;
+  GPENCIL_TextureList *txl = vedata->txl;
+  GPENCIL_FramebufferList *fbl = vedata->fbl;
   GPENCIL_PrivateData *pd = vedata->stl->pd;
   DRWShadingGroup *grp;
 
@@ -472,7 +476,7 @@ static void GPENCIL_cache_init_new(void *ved)
 pd->sbuffer_layer = NULL;
 pd->stroke_batch = NULL;
 pd->fill_batch = NULL;
-pd->do_stroke_fast_drawing = true;
+pd->do_fast_drawing = false;
 
 Object *ob = draw_ctx->obact;
 if (ob && ob->type == OB_GPENCIL) {
@@ -481,10 +485,33 @@ static void GPENCIL_cache_init_new(void *ved)
   ob, >stroke_batch, >fill_batch, >sbuffer_stroke)) {
 pd->sbuffer_gpd = (bGPdata *)ob->data;
 pd->sbuffer_layer = BKE_gpencil_layer_getactive(pd->sbuffer_gpd);
+pd->do_fast_drawing = false; /* TODO option */
   }
 }
   }
 
+  if (pd->do_fast_drawing) {
+pd->snapshot_buffer_dirty = (txl->snapshot_color_tx == NULL);
+const float *size = DRW_viewport_size_get();
+DRW_texture_ensure_2d(>snapshot_depth_tx, size[0], size[1], 
GPU_DEPTH24_STENCIL8, 0);
+DRW_texture_ensure_2d(>snapshot_color_tx, size[0], size[1], 
GPU_R11F_G11F_B10F, 0);
+DRW_texture_ensure_2d(>snapshot_reveal_tx, size[0], size[1], 
GPU_R11F_G11F_B10F, 0);
+
+GPU_framebuffer_ensure_config(>snapshot_fb,
+  {
+  
GPU_ATTACHMENT_TEXTURE(txl->snapshot_depth_tx),
+  
GPU_ATTACHMENT_TEXTURE(txl->snapshot_color_tx),
+  
GPU_ATTACHMENT_TEXTURE(txl->snapshot_reveal_tx),
+  });
+  }
+  else {
+/* Free uneeded buffers. */
+GPU_FRAMEBUFFER_FREE_SAFE(fbl->snapshot_fb);
+DRW_TEXTURE_FREE_SAFE(txl->snapshot_depth_tx);
+DRW_TEXTURE_FREE_SAFE(txl->snapshot_color_tx);
+DRW_TEXTURE_FREE_SAFE(txl->snapshot_reveal_tx);
+  }
+
   {
 DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_CUSTOM;
 DRW_PASS_CREATE(psl->composite_ps, state);
@@ -932,7 +959,8 @@ static void gp_layer_cache_populate(bGPDlayer *gpl,
 gp_sbuffer_cache_populate(iter);
   }
   else {
-iter->do_sbuffer_call = (gpd == iter->pd->sbuffer_gpd) && (gpl == 
iter->pd->sbuffer_layer);
+iter->do_sbuffer_call = !iter->pd->do_fast_drawing && (gpd == 
iter->pd->sbuffer_gpd) &&
+(gpl == iter->pd->sbuffer_layer);
   }
 
   GPENCIL_tLayer *tgp_layer_prev = iter->tgp_ob->layers.last;

[Bf-blender-cvs] [08fa158f7af] greasepencil-refactor: GPencil: Refactor: Improve current stroke drawing interleaving

2020-01-03 Thread Clément Foucault
Commit: 08fa158f7af6d2127d5e27b1fe3527b5775f488d
Author: Clément Foucault
Date:   Fri Jan 3 17:58:46 2020 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rB08fa158f7af6d2127d5e27b1fe3527b5775f488d

GPencil: Refactor: Improve current stroke drawing interleaving

This fixes issues with stroke sorting. The previous strokes were masking
the current stroke.

===

M   source/blender/draw/engines/gpencil/gpencil_engine.c
M   source/blender/draw/engines/gpencil/gpencil_engine.h
M   source/blender/draw/engines/gpencil/shaders/gpencil_vert.glsl

===

diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c 
b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 59631b96114..8ee57a71e1b 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -472,7 +472,7 @@ static void GPENCIL_cache_init_new(void *ved)
 pd->sbuffer_layer = NULL;
 pd->stroke_batch = NULL;
 pd->fill_batch = NULL;
-pd->do_stroke_fast_drawing = false;
+pd->do_stroke_fast_drawing = true;
 
 Object *ob = draw_ctx->obact;
 if (ob && ob->type == OB_GPENCIL) {
@@ -894,6 +894,9 @@ typedef struct gpIterPopulateData {
   GPUTexture *tex_stroke;
   /* Is the sbuffer call need to be issued. */
   int do_sbuffer_call;
+  /* Indices to do correct insertion of the sbuffer stroke. */
+  int stroke_index_last;
+  int stroke_index_offset;
 } gpIterPopulateData;
 
 static void gp_stroke_cache_populate(bGPDlayer *UNUSED(gpl),
@@ -901,6 +904,22 @@ static void gp_stroke_cache_populate(bGPDlayer 
*UNUSED(gpl),
  bGPDstroke *gps,
  void *thunk);
 
+static void gp_sbuffer_cache_populate(gpIterPopulateData *iter)
+{
+  iter->do_sbuffer_call = DRAW_NOW;
+  /* In order to draw the sbuffer stroke correctly mixed with other storkes,
+   * we need to offset the stroke index of the sbuffer stroke and the 
subsequent strokes.
+   * Remember, sbuffer stroke indices start from 0. So we add last index to 
avoid
+   * masking issues. */
+  iter->grp = DRW_shgroup_create_sub(iter->grp);
+  DRW_shgroup_uniform_float_copy(iter->grp, "strokeIndexOffset", 
iter->stroke_index_last);
+
+  gp_stroke_cache_populate(NULL, NULL, iter->pd->sbuffer_stroke, iter);
+
+  iter->stroke_index_offset = iter->pd->sbuffer_stroke->totpoints + 1;
+  iter->do_sbuffer_call = 0;
+}
+
 static void gp_layer_cache_populate(bGPDlayer *gpl,
 bGPDframe *gpf,
 bGPDstroke *UNUSED(gps),
@@ -910,9 +929,7 @@ static void gp_layer_cache_populate(bGPDlayer *gpl,
   bGPdata *gpd = (bGPdata *)iter->ob->data;
 
   if (iter->do_sbuffer_call) {
-iter->do_sbuffer_call = DRAW_NOW;
-gp_stroke_cache_populate(NULL, NULL, iter->pd->sbuffer_stroke, thunk);
-iter->do_sbuffer_call = 0;
+gp_sbuffer_cache_populate(iter);
   }
   else {
 iter->do_sbuffer_call = (gpd == iter->pd->sbuffer_gpd) && (gpl == 
iter->pd->sbuffer_layer);
@@ -959,6 +976,7 @@ static void gp_layer_cache_populate(bGPDlayer *gpl,
   DRW_shgroup_uniform_float_copy(iter->grp, "thicknessOffset", 
(float)gpl->line_change);
   DRW_shgroup_uniform_float_copy(iter->grp, "thicknessWorldScale", 
thickness_scale);
   DRW_shgroup_uniform_float_copy(iter->grp, "vertexColorOpacity", 
gpl->vertex_paint_opacity);
+  DRW_shgroup_uniform_float_copy(iter->grp, "strokeIndexOffset", 
iter->stroke_index_offset);
   DRW_shgroup_stencil_mask(iter->grp, 0xFF);
 
   bool use_onion = gpf->runtime.onion_id != 0.0f;
@@ -1040,6 +1058,8 @@ static void gp_stroke_cache_populate(bGPDlayer 
*UNUSED(gpl),
 int vcount = gps->totpoints + 1 + 1;
 DRW_shgroup_call_instance_range(iter->grp, geom, vfirst, vcount);
   }
+
+  iter->stroke_index_last = gps->runtime.stroke_start + gps->totpoints + 1;
 }
 
 static void GPENCIL_cache_populate_new(void *ved, Object *ob)
@@ -1066,8 +1086,7 @@ static void GPENCIL_cache_populate_new(void *ved, Object 
*ob)
 ob, gp_layer_cache_populate, gp_stroke_cache_populate, , 
pd->do_onion);
 
 if (iter.do_sbuffer_call) {
-  iter.do_sbuffer_call = DRAW_NOW;
-  gp_stroke_cache_populate(NULL, NULL, iter.pd->sbuffer_stroke, );
+  gp_sbuffer_cache_populate();
 }
 
 gpencil_vfx_cache_populate(vedata, ob, iter.tgp_ob);
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h 
b/source/blender/draw/engines/gpencil/gpencil_engine.h
index d62824c1da6..c23167c9223 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -502,8 +502,6 @@ typedef struct GPENCIL_PrivateData {
   /* Batches containing the temp stroke. */
   GPUBatch *stroke_batch;
   GPUBatch *fill_batch;
-  /* A stroke is currently in progress, do special drawing.  */
-  bool 

[Bf-blender-cvs] [8a1cc77fdd1] greasepencil-refactor: GPencil: Refactor: Implement sbuffer stroke drawing

2020-01-03 Thread Clément Foucault
Commit: 8a1cc77fdd1ca724906499221822f245305158e4
Author: Clément Foucault
Date:   Fri Jan 3 03:51:53 2020 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rB8a1cc77fdd1ca724906499221822f245305158e4

GPencil: Refactor: Implement sbuffer stroke drawing

This is to be able to view strokes currently being drawn.

===

M   source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M   source/blender/draw/engines/gpencil/gpencil_engine.c
M   source/blender/draw/engines/gpencil/gpencil_engine.h
M   source/blender/editors/gpencil/gpencil_paint.c
M   source/blender/editors/gpencil/gpencil_primitive.c
M   source/blender/editors/gpencil/gpencil_utils.c
M   source/blender/makesdna/DNA_gpencil_types.h

===

diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c 
b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
index 457965f050c..32c7d393955 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -24,6 +24,8 @@
 #include "BLI_polyfill_2d.h"
 #include "BLI_math_color.h"
 
+#include "DEG_depsgraph_query.h"
+
 #include "DNA_meshdata_types.h"
 #include "DNA_gpencil_types.h"
 #include "DNA_screen_types.h"
@@ -138,7 +140,7 @@ static void gpencil_buffer_add_stroke(gpStrokeVert *verts, 
const bGPDstroke *gps
   int v = gps->runtime.stroke_start;
 
   /* First point for adjacency (not drawn). */
-  int adj_idx = (is_cyclic) ? (pts_len - 1) : 1;
+  int adj_idx = (is_cyclic) ? (pts_len - 1) : min_ii(pts_len - 1, 1);
   gpencil_buffer_add_point(verts, gps, [adj_idx], v++, true);
 
   for (int i = 0; i < pts_len; i++) {
@@ -149,14 +151,13 @@ static void gpencil_buffer_add_stroke(gpStrokeVert 
*verts, const bGPDstroke *gps
 gpencil_buffer_add_point(verts, gps, [0], v++, false);
   }
   /* Last adjacency point (not drawn). */
-  adj_idx = (is_cyclic) ? 1 : (pts_len - 2);
+  adj_idx = (is_cyclic) ? 1 : max_ii(0, pts_len - 2);
   gpencil_buffer_add_point(verts, gps, [adj_idx], v++, true);
 }
 
 static void gpencil_buffer_add_fill(GPUIndexBufBuilder *ibo, const bGPDstroke 
*gps)
 {
   int tri_len = gps->tot_triangles;
-  /* Add one for the adjacency index. */
   int v = gps->runtime.stroke_start;
   for (int i = 0; i < tri_len; i++) {
 uint *tri = gps->triangles[i].verts;
@@ -255,6 +256,98 @@ GPUBatch *GPENCIL_batch_cache_fills(Object *ob, int cfra)
   return cache->fill_batch;
 }
 
+/* Return true if there is anything to draw. */
+bool GPENCIL_batch_from_sbuffer(Object *ob,
+GPUBatch **r_stroke_batch,
+GPUBatch **r_fill_batch,
+bGPDstroke **r_stroke)
+{
+  bGPdata *gpd = (bGPdata *)ob->data;
+  /* Current stroke data is stored in the original id. This is waiting 
refactor of the
+   * Depsgraph to support more granular update of the GPencil data.  */
+  bGPdata *gpd_orig = (bGPdata *)DEG_get_original_id(>id);
+  tGPspoint *tpoints = gpd_orig->runtime.sbuffer;
+  int vert_len = gpd_orig->runtime.sbuffer_used;
+
+  if (vert_len <= 0) {
+*r_stroke_batch = NULL;
+*r_fill_batch = NULL;
+return false;
+  }
+
+  const DRWContextState *draw_ctx = DRW_context_state_get();
+  Scene *scene = draw_ctx->scene;
+  ARegion *ar = draw_ctx->ar;
+
+  /* Get origin to reproject points. */
+  float origin[3];
+  bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
+  ToolSettings *ts = scene->toolsettings;
+  ED_gp_get_drawing_reference(scene, ob, gpl, ts->gpencil_v3d_align, origin);
+
+  /* Convert the sbuffer to a bGPDstroke. */
+  bGPDstroke *gps = *r_stroke = MEM_callocN(sizeof(*gps), "bGPDstroke 
sbuffer");
+  gps->totpoints = vert_len;
+  gps->mat_nr = gpd_orig->runtime.matid - 1;
+  gps->flag = gpd_orig->runtime.sbuffer_sflag;
+  gps->thickness = gpd_orig->runtime.brush_size;
+  gps->tot_triangles = max_ii(0, vert_len - 2);
+  gps->caps[0] = gps->caps[1] = GP_STROKE_CAP_ROUND;
+  gps->runtime.stroke_start = 1; /* Add one for the adjacency index. */
+  gps->points = MEM_mallocN(vert_len * sizeof(*gps->points), __func__);
+
+  for (int i = 0; i < vert_len; i++) {
+ED_gpencil_tpoint_to_point(ar, origin, [i], >points[i]);
+mul_m4_v3(ob->imat, >points[i].x);
+  }
+
+  /* Create VBO. */
+  GPUVertFormat *format = gpencil_stroke_format();
+  GPUVertBuf *vbo = GPU_vertbuf_create_with_format(format);
+  /* Add extra space at the end (and start) of the buffer because of quad load 
and cyclic. */
+  GPU_vertbuf_data_alloc(vbo, 1 + vert_len + 1 + 2);
+  gpStrokeVert *verts = (gpStrokeVert *)vbo->data;
+  /* Create IBO. */
+  GPUIndexBufBuilder ibo_builder;
+  GPU_indexbuf_init(_builder, GPU_PRIM_TRIS, gps->tot_triangles, vert_len);
+
+  /* Fill buffers with data. */
+  gpencil_buffer_add_stroke(verts, gps);
+
+  if (gps->tot_triangles > 0) {
+ 

[Bf-blender-cvs] [ab3498b0574] functions: Merge branch 'master' into functions

2020-01-03 Thread Jacques Lucke
Commit: ab3498b05746b3b86e0587b1d6e93eec7fda62b9
Author: Jacques Lucke
Date:   Fri Jan 3 11:39:41 2020 +0100
Branches: functions
https://developer.blender.org/rBab3498b05746b3b86e0587b1d6e93eec7fda62b9

Merge branch 'master' into functions

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [176a3adcfdc] undo-experiments-idnames: undoexp: Initial, *VERY* basic code using ID names.

2020-01-03 Thread Bastien Montagne
Commit: 176a3adcfdca7d33400e0117deaa723f8bcab368
Author: Bastien Montagne
Date:   Thu Jan 2 20:50:09 2020 +0100
Branches: undo-experiments-idnames
https://developer.blender.org/rB176a3adcfdca7d33400e0117deaa723f8bcab368

undoexp: Initial, *VERY* basic code using ID names.

This comes from the fact that we are now handling IDs from potentially
many different 'memory realms' (at the very least, two of them, those
read from memfile [new IDs], and those from previous Main [old IDs]).

The main consequence is that using pointers (aka memory addresses) as
'uids' is not working anymore: we'd need to keep some sort of 'history'
of all pointers a given data-block has had to get it working, and that
would likely lead to 'pointer collisions' [1] at some point or another.

So instead we need to use the only kind of uid we have for datablocks:
their names.

That patch is very basic, but it is enough to check undo/redo on basic
object and pose-bone-of-rigged-mesh dummies, not get it crashing, and
demonstrate huges speed-up in some artificial 'worst test case' scenario.

There are still several things to do from there:
* IDname handling:
  * Obviously, use a ghash instead of dummy linear list search! Most
likely use BKE_library_idmap code to generate it.
  * Check and handle pointers collisions. [1]
* Testing, testing and moar testing! These changes are highly dangerous
  and can destroy a blend file completely, so we'll need to be 100% sure
  they are working perfectly before puting them in master!

[1] Pointer collision: the issue here is with 'old' memory addresses
stored/used as uid in .blend file. When one read a .blend file as a
whole this is not an issue, since all old data-blocks where in a single
'memory realm' (the old Main valid at time of file writing), and all new
data-blocks are also in a single realm (the newly read file). Since we
only remap each pointer once, this is fine.

But when we start mixing those 'memory realms' by re-using IDs from old
Main in this undo project, we can end up with the same 'uuid' old
pointer value having to be remapped to two different new addresses.

===

M   source/blender/blenloader/intern/readfile.c

===

diff --git a/source/blender/blenloader/intern/readfile.c 
b/source/blender/blenloader/intern/readfile.c
index 5444c4ed04e..f5a72f0924b 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -9454,9 +9454,10 @@ static BHead *read_libblock(FileData *fd,
 Main *old_bmain = fd->old_mainlist->first;
 ListBase *old_lb = which_libbase(old_bmain, idcode);
 BLI_assert(old_lb != NULL);
-if (BLI_findindex(old_lb, id_bhead->old) != -1) {
+ID *id_old = NULL;
+if ((id_old = BLI_findstring(old_lb, id->name, offsetof(ID, name))) != 
NULL) {
   MEM_freeN(id);
-  id = (ID *)id_bhead->old;
+  id = id_old;
 
   /* Do not add LIB_TAG_NEW here, this should not be needed/used in 
undo case anyway (as
* this is only for do_version-like code), but for sake of 
consistency, and also because
@@ -9469,6 +9470,7 @@ static BHead *read_libblock(FileData *fd,
   id->orig_id = NULL;
 
   oldnewmap_insert(fd->libmap, id_bhead->old, id, id_bhead->code);
+  oldnewmap_insert(fd->libmap, id, id, id_bhead->code);
 
   ListBase *new_lb = which_libbase(main, idcode);
   BLI_remlink(old_lb, id);
@@ -9492,6 +9494,15 @@ static BHead *read_libblock(FileData *fd,
   /* for ID_LINK_PLACEHOLDER check */
   oldnewmap_insert(fd->libmap, id_bhead->old, id, id_bhead->code);
 
+  if (fd->old_mainlist != NULL) {
+Main *old_bmain = fd->old_mainlist->first;
+ListBase *old_lb = which_libbase(old_bmain, idcode);
+ID *id_old;
+if ((id_old = BLI_findstring(old_lb, id->name, offsetof(ID, name))) != 
NULL) {
+  oldnewmap_insert(fd->libmap, id_old, id, id_bhead->code);
+}
+  }
+
   BLI_addtail(lb, id);
 }
 else {

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [9b74e648c51] master: Fix T71495: Some Textures with AnimData not visible in Dopesheet

2020-01-03 Thread Sybren A. Stüvel
Commit: 9b74e648c512f18d81cce9ba2ceb62d4f8a8dd91
Author: Sybren A. Stüvel
Date:   Thu Jan 2 17:44:00 2020 +0100
Branches: master
https://developer.blender.org/rB9b74e648c512f18d81cce9ba2ceb62d4f8a8dd91

Fix T71495: Some Textures with AnimData not visible in Dopesheet

T71495 describes two problems with animation of textures not showing up in
the dope sheet:

1. textures connected to force fields
2. textures of brushes

This patch resolves the first case.

An alternative would be to switch to iteration of dependencies using
`BKE_library_foreach_ID_link()`. This is a good idea to do at some point,
but adding these few lines was considerably easier & safer to do.

===

M   source/blender/editors/animation/anim_filter.c

===

diff --git a/source/blender/editors/animation/anim_filter.c 
b/source/blender/editors/animation/anim_filter.c
index dd1f2758d58..4c81df8b71d 100644
--- a/source/blender/editors/animation/anim_filter.c
+++ b/source/blender/editors/animation/anim_filter.c
@@ -56,6 +56,7 @@
 #include "DNA_meta_types.h"
 #include "DNA_movieclip_types.h"
 #include "DNA_node_types.h"
+#include "DNA_object_force_types.h"
 #include "DNA_particle_types.h"
 #include "DNA_space_types.h"
 #include "DNA_sequence_types.h"
@@ -2733,6 +2734,12 @@ static size_t animdata_filter_dopesheet_ob(
   tmp_items += animdata_filter_ds_obanim(ac, _data, ads, ob, 
filter_mode);
 }
 
+/* particle deflector textures */
+if (ob->pd != NULL && ob->pd->tex != NULL && !(ads->filterflag & 
ADS_FILTER_NOTEX)) {
+  tmp_items += animdata_filter_ds_texture(
+  ac, _data, ads, ob->pd->tex, >id, filter_mode);
+}
+
 /* shape-key */
 if ((key && key->adt) && !(ads->filterflag & ADS_FILTER_NOSHAPEKEYS)) {
   tmp_items += animdata_filter_ds_keyanim(ac, _data, ads, ob, key, 
filter_mode);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [ce4005f8062] greasepencil-refactor: Merge branch 'greasepencil-object' into greasepencil-refactor

2020-01-03 Thread Antonio Vazquez
Commit: ce4005f80621008544bc3547f140b3fd0612f64b
Author: Antonio Vazquez
Date:   Fri Jan 3 10:07:00 2020 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rBce4005f80621008544bc3547f140b3fd0612f64b

Merge branch 'greasepencil-object' into greasepencil-refactor

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [807fc09431f] greasepencil-object: Merge branch 'master' into greasepencil-object

2020-01-03 Thread Antonio Vazquez
Commit: 807fc09431fcb889a9aacabdb07fb43cb165ae6d
Author: Antonio Vazquez
Date:   Fri Jan 3 10:06:16 2020 +0100
Branches: greasepencil-object
https://developer.blender.org/rB807fc09431fcb889a9aacabdb07fb43cb165ae6d

Merge branch 'master' into greasepencil-object

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs