Commit: 87b65f1324dbc56a259cdbc99d6d34138d0c0f5e
Author: Lukas Tönne
Date:   Thu Jun 30 18:37:45 2016 +0200
Branches: strand_gpu
https://developer.blender.org/rB87b65f1324dbc56a259cdbc99d6d34138d0c0f5e

Intermediate struct StrandData for storing base data for drawing.

This is equivalent to the DerivedMesh stage in the Mesh -> DM -> GPUBuffer
pipeline. The Strands struct is the base editable user data, StrandsData
is preprocessed data with evaluated root matrices and applied for object
space drawing.

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

M       source/blender/blenkernel/BKE_strands.h
M       source/blender/blenkernel/intern/strands.c
M       source/blender/blenloader/intern/readfile.c
M       source/blender/editors/space_view3d/drawobject.c
M       source/blender/editors/space_view3d/drawstrands.c
M       source/blender/editors/space_view3d/view3d_intern.h
M       source/blender/gpu/GPU_buffers.h
M       source/blender/gpu/intern/gpu_buffers.c
M       source/blender/makesdna/DNA_strand_types.h
M       source/blender/modifiers/intern/MOD_strands.c

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

diff --git a/source/blender/blenkernel/BKE_strands.h 
b/source/blender/blenkernel/BKE_strands.h
index 56c7940..f73294f 100644
--- a/source/blender/blenkernel/BKE_strands.h
+++ b/source/blender/blenkernel/BKE_strands.h
@@ -47,7 +47,37 @@ void BKE_strands_free(struct Strands *strands);
 
 /* ------------------------------------------------------------------------- */
 
-struct StrandData *BKE_strand_data_calc(Strands *strands);
+typedef struct StrandVertexData {
+       /* Position */
+       float co[3];
+       int pad;
+} StrandVertexData;
+
+typedef struct StrandCurveData {
+       /* Start of vertex list */
+       unsigned int verts_begin;
+       /* Number of vertices in the curve */
+       unsigned int num_verts;
+       
+       /* Transform from strand space to object space */
+       float mat[4][4];
+} StrandCurveData;
+
+typedef struct StrandData {
+       /* Array of vertices */
+       StrandVertexData *verts;
+       /* Array of curves */
+       StrandCurveData *curves;
+       
+       /* Total number of vertices */
+       int totverts;
+       /* Total number of curves */
+       int totcurves;
+       
+       struct GPUDrawStrands *gpu_buffer;
+} StrandData;
+
+struct StrandData *BKE_strand_data_calc(struct Strands *strands, struct 
DerivedMesh *scalp);
 void BKE_strand_data_free(struct StrandData *data);
 
 /* ------------------------------------------------------------------------- */
diff --git a/source/blender/blenkernel/intern/strands.c 
b/source/blender/blenkernel/intern/strands.c
index aa98883..e07b09a 100644
--- a/source/blender/blenkernel/intern/strands.c
+++ b/source/blender/blenkernel/intern/strands.c
@@ -61,7 +61,7 @@ Strands *BKE_strands_copy(Strands *strands)
        
        /* lazy initialized */
        nstrands->gpu_shader = NULL;
-       nstrands->gpu_buffer = NULL;
+       nstrands->data_final = NULL;
        
        return nstrands;
 }
@@ -70,7 +70,10 @@ void BKE_strands_free(Strands *strands)
 {
        if (strands->gpu_shader)
                GPU_strand_shader_free(strands->gpu_shader);
-       GPU_strands_buffer_free(strands);
+       GPU_strands_buffer_free(strands->data_final);
+       
+       if (strands->data_final)
+               BKE_strand_data_free(strands->data_final);
        
        if (strands->curves)
                MEM_freeN(strands->curves);
@@ -79,6 +82,53 @@ void BKE_strands_free(Strands *strands)
        MEM_freeN(strands);
 }
 
+/* ------------------------------------------------------------------------- */
+
+StrandData *BKE_strand_data_calc(Strands *strands, DerivedMesh *scalp)
+{
+       StrandData *data = MEM_callocN(sizeof(StrandData), "StrandData");
+       
+       data->totverts = strands->totverts;
+       data->totcurves = strands->totcurves;
+       data->verts = MEM_mallocN(sizeof(StrandVertexData) * data->totverts, 
"StrandVertexData");
+       data->curves = MEM_mallocN(sizeof(StrandCurveData) * data->totcurves, 
"StrandCurveData");
+       
+       int c;
+       StrandCurve *scurve = strands->curves;
+       StrandCurveData *curve = data->curves;
+       for (c = 0; c < data->totcurves; ++c, ++scurve, ++curve) {
+               curve->verts_begin = scurve->verts_begin;
+               curve->num_verts = scurve->num_verts;
+               
+               BKE_mesh_sample_eval(scalp, &scurve->root, curve->mat[3], 
curve->mat[2], curve->mat[0]);
+               cross_v3_v3v3(curve->mat[1], curve->mat[2], curve->mat[0]);
+               
+               int v;
+               StrandVertex *svert = strands->verts + scurve->verts_begin;
+               StrandVertexData *vert = data->verts + curve->verts_begin;
+               for (v = 0; v < curve->num_verts; ++v, ++svert, ++vert) {
+                       mul_v3_m4v3(vert->co, curve->mat, svert->co);
+               }
+       }
+       
+       return data;
+}
+
+void BKE_strand_data_free(StrandData *data)
+{
+       if (data) {
+               GPU_strands_buffer_free(data);
+               
+               if (data->verts)
+                       MEM_freeN(data->verts);
+               if (data->curves)
+                       MEM_freeN(data->curves);
+               MEM_freeN(data);
+       }
+}
+
+/* ------------------------------------------------------------------------- */
+
 void BKE_strands_test_init(struct Strands *strands, struct DerivedMesh *scalp,
                            int totcurves, int maxverts,
                            unsigned int seed)
diff --git a/source/blender/blenloader/intern/readfile.c 
b/source/blender/blenloader/intern/readfile.c
index 43ffb59..9d05178 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4313,7 +4313,7 @@ static void direct_link_strands(FileData *fd, Strands 
*strands)
        
        /* runtime */
        strands->gpu_shader = NULL;
-       strands->gpu_buffer = NULL;
+       strands->data_final = NULL;
 }
 
 /* ************ READ MESH ***************** */
diff --git a/source/blender/editors/space_view3d/drawobject.c 
b/source/blender/editors/space_view3d/drawobject.c
index accd021..b67eff3 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -74,6 +74,7 @@
 #include "BKE_particle.h"
 #include "BKE_pointcache.h"
 #include "BKE_scene.h"
+#include "BKE_strands.h"
 #include "BKE_subsurf.h"
 #include "BKE_unit.h"
 #include "BKE_tracking.h"
@@ -7970,8 +7971,8 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, 
Base *base, const short
                if (md->type == eModifierType_Strands) {
                        StrandsModifierData *smd = (StrandsModifierData *)md;
                        
-                       if (smd->strands) {
-                               draw_strands(smd->strands, ob, rv3d);
+                       if (smd->strands && smd->strands->data_final) {
+                               draw_strands(smd->strands, 
smd->strands->data_final, ob, rv3d);
                        }
                }
        }
diff --git a/source/blender/editors/space_view3d/drawstrands.c 
b/source/blender/editors/space_view3d/drawstrands.c
index 952aef2..c7b2276 100644
--- a/source/blender/editors/space_view3d/drawstrands.c
+++ b/source/blender/editors/space_view3d/drawstrands.c
@@ -52,7 +52,7 @@
 
 #include "view3d_intern.h"  // own include
 
-void draw_strands(Strands *strands, Object *ob, RegionView3D *rv3d)
+void draw_strands(Strands *strands, StrandData *data, Object *ob, RegionView3D 
*rv3d)
 {
        GPUStrandsShader *gpu_shader = GPU_strand_shader_get(strands);
        GPUDrawStrands *gds;
@@ -60,38 +60,12 @@ void draw_strands(Strands *strands, Object *ob, 
RegionView3D *rv3d)
        GPU_strand_shader_bind_uniforms(gpu_shader, ob->obmat, rv3d->viewmat);
        GPU_strand_shader_bind(gpu_shader, rv3d->viewmat, rv3d->viewinv);
        
-       GPU_strands_setup(strands);
-       gds = strands->gpu_buffer;
+       GPU_strands_setup(data);
+       gds = data->gpu_buffer;
        if (gds->points && gds->edges) {
                GPU_buffer_draw_elements(gds->edges, GL_LINES, 0, 
(gds->totverts - gds->totcurves) * 2);
        }
        GPU_buffers_unbind();
        
-#if 0
-       GLuint vertex_buffer;
-       glGenBuffers(1, &vertex_buffer);
-       glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
-       
-       const size_t numverts = 4;
-       float verts[12] = {
-           0.0f, 0.0f, 0.0f,
-           1.0f, 0.0f, 0.0f,
-           0.0f, 1.0f, 0.0f,
-           1.0f, 1.0f, 0.0f,
-       };
-       glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 * numverts, verts, 
GL_STATIC_DRAW);
-
-       glEnableClientState(GL_VERTEX_ARRAY);
-       glVertexPointer(3, GL_FLOAT, 0, NULL);
-
-       glDrawArrays(GL_TRIANGLES, 0, numverts);
-
-       glDisableClientState(GL_VERTEX_ARRAY);
-
-       /* cleanup */
-       glBindBuffer(GL_ARRAY_BUFFER, 0);
-       glDeleteBuffers(1, &vertex_buffer);
-#endif
-       
        GPU_strand_shader_unbind(gpu_shader);
 }
diff --git a/source/blender/editors/space_view3d/view3d_intern.h 
b/source/blender/editors/space_view3d/view3d_intern.h
index eb1a65c..45e9113 100644
--- a/source/blender/editors/space_view3d/view3d_intern.h
+++ b/source/blender/editors/space_view3d/view3d_intern.h
@@ -47,6 +47,7 @@ struct bMotionPath;
 struct bPoseChannel;
 struct Mesh;
 struct Strands;
+struct StrandData;
 struct wmNDOFMotionData;
 struct wmOperatorType;
 struct wmWindowManager;
@@ -287,7 +288,7 @@ ARegion *view3d_has_tools_region(ScrArea *sa);
 extern const char *view3d_context_dir[]; /* doc access */
 
 /* drawstrands.c */
-void draw_strands(struct Strands *strands, struct Object *ob, struct 
RegionView3D *rv3d);
+void draw_strands(struct Strands *strands, struct StrandData *data, struct 
Object *ob, struct RegionView3D *rv3d);
 
 /* drawvolume.c */
 void draw_smoke_volume(struct SmokeDomainSettings *sds, struct Object *ob,
diff --git a/source/blender/gpu/GPU_buffers.h b/source/blender/gpu/GPU_buffers.h
index 3f7a3c5..d936570 100644
--- a/source/blender/gpu/GPU_buffers.h
+++ b/source/blender/gpu/GPU_buffers.h
@@ -52,7 +52,7 @@ struct GPUDrawObject;
 struct GridCommonGPUBuffer;
 struct PBVH;
 struct MVert;
-struct Strands;
+struct StrandData;
 
 typedef struct GPUBuffer {
        size_t size;        /* in bytes */
@@ -285,7 +285,7 @@ void GPU_free_pbvh_buffer_multires(struct 
GridCommonGPUBuffer **grid_common_gpu_
 
 /* strands */
 
-void GPU_strands_setup(struct Strands *strands);
-void GPU_strands_buffer_free(struct Strands *strands);
+void GPU_strands_setup(struct StrandData *strands);
+void GPU_strands_buffer_free(struct StrandData *strands);
 
 #endif
diff --git a/source/blender/gpu/intern/gpu_buffers.c 
b/source/blender/gpu/intern/gpu_buffers.c
index c13e6f5..90930de 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -2121,7 +2121,7 @@ static GPUBuffer 
**gpu_strands_buffer_from_type(GPUDrawStrands *gds, GPUBufferTy
 }
 
 /* get the amount of space to allocate for a buffer of a particular type */
-static size_t gpu_strands_buffer_size_from_type(Strands *strands, 
GPUBufferType type)
+static size_t gpu_strands_buffer_size_from_type(StrandData *strands, 
GPUBufferType type)
 {
        const int components = gpu_buffer_type_settings[type].num_components;
        const int totverts = strands->gpu_buffer->totverts;
@@ -2149,7 +2149,7 @@ static size_t gpu_strands_buffer_size_from_type(Strands 
*strands, GPUBufferType
        }
 }
 
-static GPUDrawStrands *strands_buffer_create(Strands *strands)
+static GPUDrawStrands *strands_buffer_create(StrandData *strands)
 {
        GPUDrawStrands *gsb = MEM_callocN(sizeof(GPUDrawStrands), 
"GPUStrandsBuffer");
        
@@ -2159,34 +2159,34 @@ static GPUDrawStrands *strands_buffer_create(Strands 
*strands)
        return gsb;
 }
 
-static void strands_copy_vertex_buffer(Strands *strands, float (*varray)[3])
+static void strands_copy_vertex_buffer(StrandData *strands, float (*varray)[3])
 {
        int totverts = strands->totverts, v;
        
-       StrandVertex *vert = strands->verts;
+       StrandVertexData *vert = strands->verts;
        for (v = 0; v < totverts; ++v, ++vert) {
                copy_v3_v3(*varray++, vert->co);
        }
 }
 
-static void strands_copy_edge_buffer(Strands *strands, unsigned int 
(*varray)[2])
+static void strands_copy_edge_buffer(StrandData *strands,

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