Commit: 666fe947afac6292cc8e41fc1d9c4a987f9c25a7
Author: Lukas Tönne
Date:   Thu Jun 30 13:12:21 2016 +0200
Branches: strand_gpu
https://developer.blender.org/rB666fe947afac6292cc8e41fc1d9c4a987f9c25a7

GPU code for vertex and edge buffers of strands.

This is a modification of the DerivedMesh code, which relies too much
on the DerivedMesh data structure to be used directly.

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

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/gpu/GPU_buffers.h
M       source/blender/gpu/GPU_strands.h
M       source/blender/gpu/intern/gpu_buffers.c
M       source/blender/gpu/intern/gpu_strands.c
M       source/blender/makesdna/DNA_strand_types.h

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

diff --git a/source/blender/blenkernel/BKE_strands.h 
b/source/blender/blenkernel/BKE_strands.h
index 539369b..56c7940 100644
--- a/source/blender/blenkernel/BKE_strands.h
+++ b/source/blender/blenkernel/BKE_strands.h
@@ -37,7 +37,7 @@
 #include "DNA_strand_types.h"
 
 struct DerivedMesh;
-struct GPUStrands;
+struct GPUStrandsShader;
 
 static const unsigned int STRAND_INDEX_NONE = 0xFFFFFFFF;
 
@@ -45,10 +45,18 @@ struct Strands *BKE_strands_new(void);
 struct Strands *BKE_strands_copy(struct Strands *strands);
 void BKE_strands_free(struct Strands *strands);
 
+/* ------------------------------------------------------------------------- */
+
+struct StrandData *BKE_strand_data_calc(Strands *strands);
+void BKE_strand_data_free(struct StrandData *data);
+
+/* ------------------------------------------------------------------------- */
+
 void BKE_strands_test_init(struct Strands *strands, struct DerivedMesh *scalp,
                            int totcurves, int maxverts,
                            unsigned int seed);
 
+
 struct StrandInfo *BKE_strands_scatter(struct DerivedMesh *scalp, unsigned int 
amount,
                                        const StrandCurve *controls, unsigned 
int num_controls,
                                        unsigned int seed);
diff --git a/source/blender/blenkernel/intern/strands.c 
b/source/blender/blenkernel/intern/strands.c
index 2415fb6..aa98883 100644
--- a/source/blender/blenkernel/intern/strands.c
+++ b/source/blender/blenkernel/intern/strands.c
@@ -35,9 +35,11 @@
 
 #include "BLI_math.h"
 
+#include "BKE_DerivedMesh.h"
 #include "BKE_mesh_sample.h"
 #include "BKE_strands.h"
 
+#include "GPU_buffers.h"
 #include "GPU_strands.h"
 
 Strands *BKE_strands_new(void)
@@ -58,15 +60,17 @@ Strands *BKE_strands_copy(Strands *strands)
        }
        
        /* lazy initialized */
-       nstrands->gpu_strands = NULL;
+       nstrands->gpu_shader = NULL;
+       nstrands->gpu_buffer = NULL;
        
        return nstrands;
 }
 
 void BKE_strands_free(Strands *strands)
 {
-       if (strands->gpu_strands)
-               GPU_strands_free(strands->gpu_strands);
+       if (strands->gpu_shader)
+               GPU_strand_shader_free(strands->gpu_shader);
+       GPU_strands_buffer_free(strands);
        
        if (strands->curves)
                MEM_freeN(strands->curves);
@@ -98,7 +102,7 @@ void BKE_strands_test_init(struct Strands *strands, struct 
DerivedMesh *scalp,
                        for (k = 0; k < c->num_verts; ++k, ++v) {
                                v->co[0] = 0.0f;
                                v->co[1] = 0.0f;
-                               v->co[2] = (c->num_verts > 1) ? 1.0f / 
(c->num_verts - 1) : 0.0f;
+                               v->co[2] = (c->num_verts > 1) ? (float)k / 
(c->num_verts - 1) : 0.0f;
                        }
                        
                        verts_begin += c->num_verts;
diff --git a/source/blender/blenloader/intern/readfile.c 
b/source/blender/blenloader/intern/readfile.c
index 72d1258..43ffb59 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4312,7 +4312,8 @@ static void direct_link_strands(FileData *fd, Strands 
*strands)
        strands->verts = newdataadr(fd, strands->verts);
        
        /* runtime */
-       strands->gpu_strands = NULL;
+       strands->gpu_shader = NULL;
+       strands->gpu_buffer = NULL;
 }
 
 /* ************ READ MESH ***************** */
diff --git a/source/blender/editors/space_view3d/drawobject.c 
b/source/blender/editors/space_view3d/drawobject.c
index 206ab18..accd021 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -7970,8 +7970,9 @@ 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)
+                       if (smd->strands) {
                                draw_strands(smd->strands, ob, rv3d);
+                       }
                }
        }
 
diff --git a/source/blender/editors/space_view3d/drawstrands.c 
b/source/blender/editors/space_view3d/drawstrands.c
index 88a5e3d..952aef2 100644
--- a/source/blender/editors/space_view3d/drawstrands.c
+++ b/source/blender/editors/space_view3d/drawstrands.c
@@ -40,10 +40,12 @@
 #include "BLI_utildefines.h"
 #include "BLI_math.h"
 
+#include "BKE_DerivedMesh.h"
 #include "BKE_strands.h"
 
 #include "BIF_gl.h"
 
+#include "GPU_buffers.h"
 #include "GPU_debug.h"
 #include "GPU_shader.h"
 #include "GPU_strands.h"
@@ -52,11 +54,20 @@
 
 void draw_strands(Strands *strands, Object *ob, RegionView3D *rv3d)
 {
-       GPUStrands *gpu_strands = GPU_strands_get(strands);
+       GPUStrandsShader *gpu_shader = GPU_strand_shader_get(strands);
+       GPUDrawStrands *gds;
        
-       GPU_strands_bind_uniforms(gpu_strands, ob->obmat, rv3d->viewmat);
-       GPU_strands_bind(gpu_strands, rv3d->viewmat, rv3d->viewinv);
+       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;
+       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);
@@ -80,6 +91,7 @@ void draw_strands(Strands *strands, Object *ob, RegionView3D 
*rv3d)
        /* cleanup */
        glBindBuffer(GL_ARRAY_BUFFER, 0);
        glDeleteBuffers(1, &vertex_buffer);
+#endif
        
-       GPU_strands_unbind(gpu_strands);
+       GPU_strand_shader_unbind(gpu_shader);
 }
diff --git a/source/blender/gpu/GPU_buffers.h b/source/blender/gpu/GPU_buffers.h
index 7972d13..3f7a3c5 100644
--- a/source/blender/gpu/GPU_buffers.h
+++ b/source/blender/gpu/GPU_buffers.h
@@ -52,6 +52,7 @@ struct GPUDrawObject;
 struct GridCommonGPUBuffer;
 struct PBVH;
 struct MVert;
+struct Strands;
 
 typedef struct GPUBuffer {
        size_t size;        /* in bytes */
@@ -143,6 +144,20 @@ typedef struct GPUVertPointLink {
        int point_index;
 } GPUVertPointLink;
 
+typedef struct GPUDrawStrands {
+       GPUBuffer *points;
+       GPUBuffer *normals;
+       GPUBuffer *uv;
+       GPUBuffer *uv_tex;
+       GPUBuffer *colors;
+       GPUBuffer *edges;
+       GPUBuffer *uvedges;
+       GPUBuffer *triangles; /* triangle index buffer */
+
+       unsigned int totverts;
+       unsigned int totcurves;
+} GPUDrawStrands;
+
 
 
 /* used for GLSL materials */
@@ -268,4 +283,9 @@ bool GPU_pbvh_buffers_diffuse_changed(GPU_PBVH_Buffers 
*buffers, struct GSet *bm
 void GPU_free_pbvh_buffers(GPU_PBVH_Buffers *buffers);
 void GPU_free_pbvh_buffer_multires(struct GridCommonGPUBuffer 
**grid_common_gpu_buffer);
 
+/* strands */
+
+void GPU_strands_setup(struct Strands *strands);
+void GPU_strands_buffer_free(struct Strands *strands);
+
 #endif
diff --git a/source/blender/gpu/GPU_strands.h b/source/blender/gpu/GPU_strands.h
index 7d73b38..c3a58d3 100644
--- a/source/blender/gpu/GPU_strands.h
+++ b/source/blender/gpu/GPU_strands.h
@@ -38,20 +38,20 @@ extern "C" {
 
 struct Strands;
 
-typedef struct GPUStrands GPUStrands;
+typedef struct GPUStrandsShader GPUStrandsShader;
 
-GPUStrands *GPU_strands_get(struct Strands *strands);
+GPUStrandsShader *GPU_strand_shader_get(struct Strands *strands);
 
-void GPU_strands_free(struct GPUStrands *gpu_strands);
+void GPU_strand_shader_free(struct GPUStrandsShader *gpu_shader);
 
-void GPU_strands_bind(
-        GPUStrands *gpu_strands,
+void GPU_strand_shader_bind(
+        GPUStrandsShader *gpu_shader,
         float viewmat[4][4], float viewinv[4][4]);
-void GPU_strands_bind_uniforms(
-        GPUStrands *gpu_strands,
+void GPU_strand_shader_bind_uniforms(
+        GPUStrandsShader *gpu_shader,
         float obmat[4][4], float viewmat[4][4]);
-void GPU_strands_unbind(GPUStrands *gpu_strands);
-bool GPU_strands_bound(GPUStrands *gpu_strands);
+void GPU_strand_shader_unbind(GPUStrandsShader *gpu_shader);
+bool GPU_strand_shader_bound(GPUStrandsShader *gpu_shader);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/gpu/intern/gpu_buffers.c 
b/source/blender/gpu/intern/gpu_buffers.c
index 36d297f..c13e6f5 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -46,12 +46,14 @@
 #include "BLI_threads.h"
 
 #include "DNA_meshdata_types.h"
+#include "DNA_strand_types.h"
 
 #include "BKE_ccg.h"
 #include "BKE_DerivedMesh.h"
 #include "BKE_paint.h"
 #include "BKE_mesh.h"
 #include "BKE_pbvh.h"
+#include "BKE_strands.h"
 
 #include "GPU_buffers.h"
 #include "GPU_draw.h"
@@ -74,7 +76,7 @@ typedef struct {
 } GPUBufferTypeSettings;
 
 
-static size_t gpu_buffer_size_from_type(DerivedMesh *dm, GPUBufferType type);
+static size_t gpu_mesh_buffer_size_from_type(DerivedMesh *dm, GPUBufferType 
type);
 
 const GPUBufferTypeSettings gpu_buffer_type_settings[] = {
     /* vertex */
@@ -464,7 +466,7 @@ static GPUBuffer *gpu_buffer_setup(DerivedMesh *dm, 
GPUDrawObject *object,
        int i;
        const GPUBufferTypeSettings *ts = &gpu_buffer_type_settings[type];
        GLenum target = ts->gl_buffer_type;
-       size_t size = gpu_buffer_size_from_type(dm, type);
+       size_t size = gpu_mesh_buffer_size_from_type(dm, type);
        GLboolean uploaded;
 
        pool = gpu_get_global_buffer_pool();
@@ -550,7 +552,7 @@ static GPUBuffer 
**gpu_drawobject_buffer_from_type(GPUDrawObject *gdo, GPUBuffer
 }
 
 /* get the amount of space to allocate for a buffer of a particular type */
-static size_t gpu_buffer_size_from_type(DerivedMesh *dm, GPUBufferType type)
+static size_t gpu_mesh_buffer_size_from_type(DerivedMesh *dm, GPUBufferType 
type)
 {
        const int components = gpu_buffer_type_settings[type].num_components;
        switch (type) {
@@ -2089,3 +2091,228 @@ void GPU_end_draw_pbvh_BB(void)
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
        glPopAttrib();
 }
+
+/* *************** */
+/* Strands Buffers */
+
+/* get the GPUDrawObject buffer associated with a type */
+static GPUBuffer **gpu_strands_buffer_from_type(GPUDrawStrands *gds, 
GPUBufferType type)
+{
+       switch (type) {
+               case GPU_BUFFER_VERTEX:
+                       return &gds->points;
+               case GPU_BUFFER_NORMAL:
+                       return &gds->normals;
+               case GPU_BUFFER_COLOR:
+                       return &gds->colors;
+               case GPU_BUFFER_UV:
+                       return &gds->uv;
+               case GPU_BUFFER_UV_TEXPAINT:
+                       return &gds->uv_tex;
+               case GPU_BUFFER_EDGE:
+                       return &gds->edges;
+               case GPU_BUFFER_UVEDGE:
+                       return &gds->uvedges;
+               case GPU_BUFFER_TRIANGLES:
+                       return &gds->triangles;
+               default:
+                       return NULL;
+       }
+}
+
+/* get the amount of space to allocate for a buffer o

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