Commit: fe5b74c36cb2ed7105143a20557e1ffea3f1fb5e
Author: Lukas Tönne
Date:   Thu May 24 10:24:10 2018 +0100
Branches: hair_guides hair_guides_grooming
https://developer.blender.org/rBfe5b74c36cb2ed7105143a20557e1ffea3f1fb5e

Only pass export cache to lower level draw functions, do export on higher 
levels.

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

M       source/blender/draw/engines/eevee/eevee_materials.c
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_hair.c
M       source/blender/draw/intern/draw_hair.c

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

diff --git a/source/blender/draw/engines/eevee/eevee_materials.c 
b/source/blender/draw/engines/eevee/eevee_materials.c
index e4c93d50fe2..734624329da 100644
--- a/source/blender/draw/engines/eevee/eevee_materials.c
+++ b/source/blender/draw/engines/eevee/eevee_materials.c
@@ -32,6 +32,7 @@
 #include "BLI_string_utils.h"
 
 #include "BKE_DerivedMesh.h"
+#include "BKE_hair.h"
 #include "BKE_particle.h"
 #include "BKE_paint.h"
 #include "BKE_pbvh.h"
@@ -1445,8 +1446,13 @@ static void material_hair(
        float mat[4][4];
        copy_m4_m4(mat, ob->obmat);
        
+       HairExportCache *hair_export = BKE_hair_export_cache_new();
+       BKE_hair_export_cache_update(hair_export, hsys, subdiv, scalp, 
HAIR_EXPORT_ALL);
+       
        const DRWHairFiberTextureBuffer *fiber_buffer = NULL;
-       struct Gwn_Batch *hair_geom = DRW_cache_hair_get_fibers(hsys, scalp, 
subdiv, &fiber_buffer);
+       struct Gwn_Batch *hair_geom = DRW_cache_hair_get_fibers(hsys, 
hair_export, &fiber_buffer);
+       
+       BKE_hair_export_cache_free(hair_export);
        
        if (!hsys->draw_texture_cache) {
                hsys->draw_texture_cache = 
DRW_texture_create_2D(fiber_buffer->width, fiber_buffer->height,
diff --git a/source/blender/draw/intern/draw_cache.c 
b/source/blender/draw/intern/draw_cache.c
index 3659ba49743..7e85d0ba547 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -2985,25 +2985,20 @@ Gwn_Batch *DRW_cache_particles_get_prim(int type)
 
 /** \name Hair */
 
-Gwn_Batch *DRW_cache_hair_get_fibers(struct HairSystem *hsys, struct 
DerivedMesh *scalp, int subdiv,
+Gwn_Batch *DRW_cache_hair_get_fibers(struct HairSystem *hsys, const struct 
HairExportCache *hair_export,
                                      const struct DRWHairFiberTextureBuffer 
**r_buffer)
 {
-       return DRW_hair_batch_cache_get_fibers(hsys, scalp, subdiv, r_buffer);
+       return DRW_hair_batch_cache_get_fibers(hsys, hair_export, r_buffer);
 }
 
-Gwn_Batch *DRW_cache_hair_get_follicle_points(struct HairSystem *hsys, struct 
DerivedMesh *scalp)
+Gwn_Batch *DRW_cache_hair_get_follicle_points(struct HairSystem *hsys, const 
struct HairExportCache *hair_export)
 {
-       return DRW_hair_batch_cache_get_follicle_points(hsys, scalp);
+       return DRW_hair_batch_cache_get_follicle_points(hsys, hair_export);
 }
 
-Gwn_Batch *DRW_cache_hair_get_guide_curve_points(struct HairSystem *hsys, 
struct DerivedMesh *scalp, int subdiv)
+Gwn_Batch *DRW_cache_hair_get_guide_curve_edges(struct HairSystem *hsys, const 
struct HairExportCache *hair_export)
 {
-       return DRW_hair_batch_cache_get_guide_curve_points(hsys, scalp, subdiv);
-}
-
-Gwn_Batch *DRW_cache_hair_get_guide_curve_edges(struct HairSystem *hsys, 
struct DerivedMesh *scalp, int subdiv)
-{
-       return DRW_hair_batch_cache_get_guide_curve_edges(hsys, scalp, subdiv);
+       return DRW_hair_batch_cache_get_guide_curve_edges(hsys, hair_export);
 }
 
 /* 3D cursor */
diff --git a/source/blender/draw/intern/draw_cache.h 
b/source/blender/draw/intern/draw_cache.h
index dcec0bed151..025a5d06bf1 100644
--- a/source/blender/draw/intern/draw_cache.h
+++ b/source/blender/draw/intern/draw_cache.h
@@ -32,8 +32,8 @@ struct ModifierData;
 struct Object;
 struct PTCacheEdit;
 struct HairSystem;
+struct HairExportCache;
 struct DRWHairFiberTextureBuffer;
-struct DerivedMesh;
 
 void DRW_shape_cache_free(void);
 
@@ -177,11 +177,10 @@ struct Gwn_Batch 
*DRW_cache_particles_get_edit_tip_points(struct Object *object,
 struct Gwn_Batch *DRW_cache_particles_get_prim(int type);
 
 /* Hair */
-struct Gwn_Batch *DRW_cache_hair_get_fibers(struct HairSystem *hsys, struct 
DerivedMesh *scalp, int subdiv,
+struct Gwn_Batch *DRW_cache_hair_get_fibers(struct HairSystem *hsys, const 
struct HairExportCache *hair_export,
                                             const struct 
DRWHairFiberTextureBuffer **r_buffer);
-struct Gwn_Batch *DRW_cache_hair_get_follicle_points(struct HairSystem *hsys, 
struct DerivedMesh *scalp);
-struct Gwn_Batch *DRW_cache_hair_get_guide_curve_points(struct HairSystem 
*hsys, struct DerivedMesh *scalp, int subdiv);
-struct Gwn_Batch *DRW_cache_hair_get_guide_curve_edges(struct HairSystem 
*hsys, struct DerivedMesh *scalp, int subdiv);
+struct Gwn_Batch *DRW_cache_hair_get_follicle_points(struct HairSystem *hsys, 
const struct HairExportCache *hair_export);
+struct Gwn_Batch *DRW_cache_hair_get_guide_curve_edges(struct HairSystem 
*hsys, const struct HairExportCache *hair_export);
 
 /* Metaball */
 struct Gwn_Batch *DRW_cache_mball_surface_get(struct Object *ob);
diff --git a/source/blender/draw/intern/draw_cache_impl.h 
b/source/blender/draw/intern/draw_cache_impl.h
index 8566c78a7d8..e6eb3542792 100644
--- a/source/blender/draw/intern/draw_cache_impl.h
+++ b/source/blender/draw/intern/draw_cache_impl.h
@@ -36,8 +36,8 @@ struct ModifierData;
 struct ParticleSystem;
 struct PTCacheEdit;
 struct HairSystem;
+struct HairExportCache;
 struct DRWHairFiberTextureBuffer;
-struct DerivedMesh;
 
 struct Curve;
 struct Lattice;
@@ -137,10 +137,9 @@ struct Gwn_Batch 
*DRW_particles_batch_cache_get_edit_inner_points(struct Object
 struct Gwn_Batch *DRW_particles_batch_cache_get_edit_tip_points(struct Object 
*object, struct ParticleSystem *psys, struct PTCacheEdit *edit);
 
 /* Hair */
-struct Gwn_Batch *DRW_hair_batch_cache_get_fibers(struct HairSystem *hsys, 
struct DerivedMesh *scalp, int subdiv,
+struct Gwn_Batch *DRW_hair_batch_cache_get_fibers(struct HairSystem *hsys, 
const struct HairExportCache *hair_export,
                                                   const struct 
DRWHairFiberTextureBuffer **r_buffer);
-struct Gwn_Batch *DRW_hair_batch_cache_get_follicle_points(struct HairSystem 
*hsys, struct DerivedMesh *scalp);
-struct Gwn_Batch *DRW_hair_batch_cache_get_guide_curve_points(struct 
HairSystem *hsys, struct DerivedMesh *scalp, int subdiv);
-struct Gwn_Batch *DRW_hair_batch_cache_get_guide_curve_edges(struct HairSystem 
*hsys, struct DerivedMesh *scalp, int subdiv);
+struct Gwn_Batch *DRW_hair_batch_cache_get_follicle_points(struct HairSystem 
*hsys, const struct HairExportCache *hair_export);
+struct Gwn_Batch *DRW_hair_batch_cache_get_guide_curve_edges(struct HairSystem 
*hsys, const struct HairExportCache *hair_export);
 
 #endif /* __DRAW_CACHE_IMPL_H__ */
diff --git a/source/blender/draw/intern/draw_cache_impl_hair.c 
b/source/blender/draw/intern/draw_cache_impl_hair.c
index 531f8bf40b1..58ac4d8b4f4 100644
--- a/source/blender/draw/intern/draw_cache_impl_hair.c
+++ b/source/blender/draw/intern/draw_cache_impl_hair.c
@@ -298,17 +298,13 @@ static void hair_batch_cache_ensure_fiber_texbuffer(const 
HairExportCache *hair_
 
 Gwn_Batch *DRW_hair_batch_cache_get_fibers(
         HairSystem *hsys,
-        struct DerivedMesh *scalp,
-        int subdiv,
+        const HairExportCache *hair_export,
         const DRWHairFiberTextureBuffer **r_buffer)
 {
        HairBatchCache *cache = hair_batch_cache_get(hsys);
 
        TIMEIT_START(DRW_hair_batch_cache_get_fibers);
 
-       HairExportCache *hair_export = BKE_hair_export_cache_new();
-       BKE_hair_export_cache_update(hair_export, hsys, subdiv, scalp, 
HAIR_EXPORT_ALL);
-
        if (cache->fibers == NULL) {
                TIMEIT_BENCH(hair_batch_cache_ensure_fibers(hair_export, cache),
                             hair_batch_cache_ensure_fibers);
@@ -324,23 +320,20 @@ Gwn_Batch *DRW_hair_batch_cache_get_fibers(
                *r_buffer = &cache->texbuffer;
        }
 
-       BKE_hair_export_cache_free(hair_export);
-
        TIMEIT_END(DRW_hair_batch_cache_get_fibers);
 
        return cache->fibers;
 }
 
 static void hair_batch_cache_ensure_follicles(
-        HairSystem *hsys,
-        struct DerivedMesh *scalp,
+        const HairExportCache *hair_export,
         eHairDrawFollicleMode mode,
         HairBatchCache *cache)
 {
        GWN_VERTBUF_DISCARD_SAFE(cache->follicle_verts);
        GWN_INDEXBUF_DISCARD_SAFE(cache->follicle_edges);
        
-       const HairPattern *pattern = hsys->pattern;
+       const unsigned int point_count = hair_export->totfibercurves;
        
        static Gwn_VertFormat format = { 0 };
        static unsigned pos_id;
@@ -352,49 +345,88 @@ static void hair_batch_cache_ensure_follicles(
        
        cache->follicle_verts = GWN_vertbuf_create_with_format(&format);
        
-       GWN_vertbuf_data_alloc(cache->follicle_verts, pattern->num_follicles);
+       GWN_vertbuf_data_alloc(cache->follicle_verts, point_count);
        
-       HairFollicle *follicle = pattern->follicles;
-       for (int i = 0; i < pattern->num_follicles; ++i, ++follicle) {
-               float co[3], nor[3], tang[3];
-               BKE_mesh_sample_eval_DM(scalp, &follicle->mesh_sample, co, nor, 
tang);
-               
-               GWN_vertbuf_attr_set(cache->follicle_verts, pos_id, (unsigned 
int)i, co);
+       float (*root_co)[3] = hair_export->fiber_root_position;
+       for (int i = 0; i < hair_export->totfibercurves; ++i, ++root_co) {
+               GWN_vertbuf_attr_set(cache->follicle_verts, pos_id, (unsigned 
int)i, *root_co);
        }
        
        UNUSED_VARS(mode);
 }
 
-Gwn_Batch *DRW_hair_batch_cache_get_follicle_points(
-        HairSystem *hsys,
-        struct DerivedMesh *scalp)
+Gwn_Batch *DRW_hair_batch_cache_get_follicle_points(HairSystem *hsys, const 
HairExportCache *hair_export)
 {
        HairBatchCache *cache = hair_batch_cache_get(hsys);
 
        if (cache->follicles == NULL) {
-               hair_batch_cache_ensure_follicles(hsys, scalp, 
HAIR_DRAW_FOLLICLE_POINTS, cache);
+               hair_batch_cache_ensure_follicles(hair_export, 
HAIR_DRAW_FOLLICLE_POINTS, cache);
                
                cache->follicles = GWN_batch_create(GWN_PRIM_POINTS, 
cache->follicle_verts, NULL);
        }
 
        return cache->follicles;
-       
 }
 
-Gwn_Batch *DRW_hair_batch_cache_get_guide_curve_points(
-        HairSystem *hsys,
-        struct DerivedMesh *scalp,
-        int subdiv)
+static void hair_batch_cache_ensure_guide_curves(
+        const HairExportCache *hair_export,
+        eHairDrawGuideMode mode,
+        HairBatchCache *cache)
 {
-       UNUSED_VARS(hsys, scalp, subdiv);
-       return NULL;
+       GWN_VERTBUF_DISCARD_SAFE(cache->guide_curve_verts);
+       GWN_INDEXBUF_DISCARD_SAFE(cache->guide_curve_edges);
+       
+       const unsigned int point_count = hair_export->totguideverts;
+       const unsigned int elems_count = hair_export->totguideverts - 
hair_export->totguidecurves;
+       
+       static Gwn_VertFormat format = { 0 };
+       static unsigned pos_id;
+       
+       /* initialize vertex format */
+       if (format.attrib_ct == 0) {
+               pos_id = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 
3, GWN_FETCH_FLOAT);
+       }
+       
+       cache

@@ 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