[Bf-blender-cvs] [3f052c6] strand_gpu: GPU buffer functions for drawing a strand edit BMesh.

Lukas Tönne noreply at git.blender.org
Wed Jul 6 12:13:22 CEST 2016


Commit: 3f052c6ab39d1a98332f883248e74933ab484cc8
Author: Lukas Tönne
Date:   Wed Jul 6 11:47:43 2016 +0200
Branches: strand_gpu
https://developer.blender.org/rB3f052c6ab39d1a98332f883248e74933ab484cc8

GPU buffer functions for drawing a strand edit BMesh.

Now the object mode and edit mode for strands use the same drawing code.
Derived render strands are not yet supported (they may need re-scattering
during editing) and the tool settings have no effect yet.

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

M	source/blender/blenkernel/BKE_editstrands.h
M	source/blender/blenkernel/intern/editstrands.c
M	source/blender/blenkernel/intern/strands.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

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

diff --git a/source/blender/blenkernel/BKE_editstrands.h b/source/blender/blenkernel/BKE_editstrands.h
index 9fb69ba..e8729af 100644
--- a/source/blender/blenkernel/BKE_editstrands.h
+++ b/source/blender/blenkernel/BKE_editstrands.h
@@ -55,9 +55,7 @@ typedef struct BMEditStrands {
 	
 	int flag;
 	
-	unsigned int vertex_glbuf;
-	unsigned int elem_glbuf;
-	unsigned int dot_glbuf;
+	struct GPUDrawStrands *gpu_buffer;
 } BMEditStrands;
 
 /* BMEditStrands->flag */
diff --git a/source/blender/blenkernel/intern/editstrands.c b/source/blender/blenkernel/intern/editstrands.c
index f0d8ea6..fb078e4 100644
--- a/source/blender/blenkernel/intern/editstrands.c
+++ b/source/blender/blenkernel/intern/editstrands.c
@@ -55,6 +55,8 @@
 
 #include "BPH_strands.h"
 
+#include "GPU_buffers.h"
+
 #include "intern/bmesh_mesh_conv.h"
 #include "intern/bmesh_strands_conv.h"
 
@@ -76,6 +78,8 @@ BMEditStrands *BKE_editstrands_copy(BMEditStrands *es)
 	es_copy->base.bm = BM_mesh_copy(es->base.bm);
 	es_copy->root_dm = CDDM_copy(es->root_dm);
 	
+	es_copy->gpu_buffer = NULL;
+	
 	return es_copy;
 }
 
@@ -125,6 +129,9 @@ void BKE_editstrands_free(BMEditStrands *es)
 		BM_mesh_free(es->base.bm);
 	if (es->root_dm)
 		es->root_dm->release(es->root_dm);
+	
+	if (es->gpu_buffer)
+		GPU_strands_buffer_free(es->gpu_buffer);
 }
 
 /* === constraints === */
diff --git a/source/blender/blenkernel/intern/strands.c b/source/blender/blenkernel/intern/strands.c
index 847bd5f..02a4c16 100644
--- a/source/blender/blenkernel/intern/strands.c
+++ b/source/blender/blenkernel/intern/strands.c
@@ -72,7 +72,6 @@ void BKE_strands_free(Strands *strands)
 {
 	if (strands->gpu_shader)
 		GPU_strand_shader_free(strands->gpu_shader);
-	GPU_strands_buffer_free(strands->data_final);
 	
 	if (strands->data_final)
 		BKE_strand_data_free(strands->data_final);
@@ -163,7 +162,7 @@ StrandData *BKE_strand_data_calc(Strands *strands, DerivedMesh *scalp,
 void BKE_strand_data_free(StrandData *data)
 {
 	if (data) {
-		GPU_strands_buffer_free(data);
+		GPU_strands_buffer_free(data->gpu_buffer);
 		
 		if (data->verts)
 			MEM_freeN(data->verts);
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index fa976de..6b29232 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -7977,17 +7977,20 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short
 		if (md->type == eModifierType_Strands) {
 			StrandsModifierData *smd = (StrandsModifierData *)md;
 			BMEditStrands *edit = (ob->mode & OB_MODE_HAIR_EDIT && is_obact) ? smd->edit : NULL;
+			bool show_controls = smd->flag & MOD_STRANDS_SHOW_CONTROL_STRANDS;
+			bool show_strands = smd->flag & MOD_STRANDS_SHOW_RENDER_STRANDS;
 			
 			if (edit) {
 				if (!(dflag & DRAW_PICKING) && scene->obedit == NULL) {
-					draw_strands_edit_hair(scene, v3d, ar, edit);
+					draw_strands_edit_hair(scene, v3d, rv3d, ob,
+					                       smd->strands, edit,
+					                       show_controls, show_strands);
 				}
 			}
 			else {
 				if (smd->strands && smd->strands->data_final) {
-					bool show_controls = smd->flag & MOD_STRANDS_SHOW_CONTROL_STRANDS;
-					bool show_strands = smd->flag & MOD_STRANDS_SHOW_RENDER_STRANDS;
-					draw_strands(smd->strands, smd->strands->data_final, ob, rv3d,
+					draw_strands(scene, v3d, rv3d, ob,
+					             smd->strands, smd->strands->data_final,
 					             show_controls, show_strands);
 				}
 			}
diff --git a/source/blender/editors/space_view3d/drawstrands.c b/source/blender/editors/space_view3d/drawstrands.c
index 7161de7..4014dd8 100644
--- a/source/blender/editors/space_view3d/drawstrands.c
+++ b/source/blender/editors/space_view3d/drawstrands.c
@@ -66,7 +66,8 @@
 
 #include "view3d_intern.h"  // own include
 
-void draw_strands(Strands *strands, StrandData *data, Object *ob, RegionView3D *rv3d,
+void draw_strands(Scene *UNUSED(scene), View3D *UNUSED(v3d), RegionView3D *rv3d,
+                  Object *ob, Strands *strands, StrandData *data,
                   bool show_controls, bool show_strands)
 {
 	GPUStrandsShader *gpu_shader = GPU_strand_shader_get(strands);
@@ -108,6 +109,7 @@ void draw_strands(Strands *strands, StrandData *data, Object *ob, RegionView3D *
 /*************************/
 /*** Edit Mode Drawing ***/
 
+#if 0
 typedef enum StrandsShadeMode {
 	STRANDS_SHADE_FLAT,
 	STRANDS_SHADE_HAIR,
@@ -413,9 +415,25 @@ static void draw_dots(BMEditStrands *edit, const StrandsDrawInfo *info, bool sel
 	if (totelem > 0)
 		glDrawArrays(GL_POINTS, 0, totelem);
 }
+#endif
 
-void draw_strands_edit_hair(Scene *scene, View3D *v3d, ARegion *UNUSED(ar), BMEditStrands *edit)
+void draw_strands_edit_hair(Scene *UNUSED(scene), View3D *UNUSED(v3d), RegionView3D *rv3d,
+                            Object *ob, Strands *strands, BMEditStrands *edit,
+                            bool show_controls, bool show_strands)
 {
+	GPUStrandsShader *gpu_shader = GPU_strand_shader_get(strands);
+	
+	if (show_controls) {
+		GPU_editstrands_setup_edges(edit);
+		GPUDrawStrands *gds = edit->gpu_buffer;
+		if (gds->control_points && gds->control_edges) {
+			GPU_buffer_draw_elements(gds->control_edges, GL_LINES, 0,
+			                         (gds->totverts - gds->totcurves) * 2);
+		}
+		GPU_buffers_unbind();
+	}
+	
+#if 0
 	HairEditSettings *settings = &scene->toolsettings->hair_edit;
 	
 	StrandsDrawInfo info;
@@ -436,4 +454,5 @@ void draw_strands_edit_hair(Scene *scene, View3D *v3d, ARegion *UNUSED(ar), BMEd
 	unbind_gpu_buffers_dots();
 	
 	restore_opengl_state(&info);
+#endif
 }
diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h
index 3e9c99b..ec47ad5 100644
--- a/source/blender/editors/space_view3d/view3d_intern.h
+++ b/source/blender/editors/space_view3d/view3d_intern.h
@@ -289,10 +289,13 @@ ARegion *view3d_has_tools_region(ScrArea *sa);
 extern const char *view3d_context_dir[]; /* doc access */
 
 /* drawstrands.c */
-void draw_strands(struct Strands *strands, struct StrandData *data, struct Object *ob, struct RegionView3D *rv3d,
+void draw_strands(struct Scene *scene, struct View3D *v3d, struct RegionView3D *rv3d,
+                  struct Object *ob, struct Strands *strands, struct StrandData *data,
                   bool show_controls, bool show_strands);
 
-void draw_strands_edit_hair(Scene *scene, View3D *v3d, ARegion *ar, struct BMEditStrands *edit);
+void draw_strands_edit_hair(struct Scene *scene, struct View3D *v3d, struct RegionView3D *rv3d,
+                            struct Object *ob, struct Strands *strands, struct BMEditStrands *edit,
+                            bool show_controls, bool show_strands);
 
 /* 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 32f2192..fa9decc 100644
--- a/source/blender/gpu/GPU_buffers.h
+++ b/source/blender/gpu/GPU_buffers.h
@@ -53,6 +53,7 @@ struct GridCommonGPUBuffer;
 struct PBVH;
 struct MVert;
 struct StrandData;
+struct BMEditStrands;
 
 typedef struct GPUBuffer {
 	size_t size;        /* in bytes */
@@ -295,8 +296,12 @@ void GPU_strands_setup_verts(struct StrandData *strands);
 void GPU_strands_setup_edges(struct StrandData *strands);
 void GPU_strands_setup_roots(struct StrandData *strands);
 
+void GPU_editstrands_setup_verts(struct BMEditStrands *strands);
+void GPU_editstrands_setup_edges(struct BMEditStrands *strands);
+void GPU_editstrands_setup_roots(struct BMEditStrands *strands);
+
 void GPU_strands_buffer_unbind(void);
 
-void GPU_strands_buffer_free(struct StrandData *strands);
+void GPU_strands_buffer_free(struct GPUDrawStrands *gpu_buffer);
 
 #endif
diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index 61e64fd..1fed60a 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -50,6 +50,7 @@
 
 #include "BKE_ccg.h"
 #include "BKE_DerivedMesh.h"
+#include "BKE_editstrands.h"
 #include "BKE_paint.h"
 #include "BKE_mesh.h"
 #include "BKE_pbvh.h"
@@ -2181,12 +2182,12 @@ static GPUBufferTexture *gpu_strands_buffer_texture_from_type(GPUDrawStrands *gd
 }
 
 /* get the amount of space to allocate for a buffer of a particular type */
-static size_t gpu_strands_buffer_size_from_type(StrandData *strands, GPUStrandBufferType type)
+static size_t gpu_strands_buffer_size_from_type(GPUDrawStrands *gpu_buffer, GPUStrandBufferType type)
 {
 	const int components = gpu_strand_buffer_type_settings[type].num_components;
-	const int totverts = strands->gpu_buffer->totverts;
-	const int totcurves = strands->gpu_buffer->totcurves;
-	const int totroots = strands->gpu_buffer->totroots;
+	const int totverts = gpu_buffer->totverts;
+	const int totcurves = gpu_buffer->totcurves;
+	const int totroots = gpu_buffer->totroots;
 	
 	switch (type) {
 		case GPU_STRAND_BUFFER_CONTROL_VERTEX:
@@ -2202,6 +2203,84 @@ static size_t gpu_strands_buffer_size_from_type(StrandData *strands, GPUStrandBu
 	}
 }
 
+typedef void (*StrandsCopyGPUDataCb)(void *userdata, GPUStrandBufferType type, float *varray);
+
+static GPUBuffer *gpu_strands_setup_buffer_type(GPUDrawStrands *gpu_buffer,
+                                                GPUStrandBufferType type,
+                                                StrandsCopyGPUDataCb copy_data,
+                                                void *userdata,
+                                                GPUBuffer *buffer)
+{
+	GPUBufferPool *pool;
+	float *varray;
+	const GPUBufferTypeSettings *ts = &gpu_strand_buffer_type_settings[type];
+	GLenum target = ts->gl_buffer_type;
+	size_t size = gpu_strands_buffer_size_from_type(gpu_buffer, type);
+
+	pool = gpu_get_global_buffer_pool();
+
+	BLI_mutex_lock(&buffer_mutex);
+
+	/* alloc a GPUBuffer; fall back to legacy mode on failure */
+	if (!buffer) {
+		if (!(buffer = gpu_buffer_alloc_intern(size))) {
+			BLI_mutex_unlock(&buffer_mutex);
+			return NULL;
+		}
+	}
+
+	/* bind the buffer and discard previous data,
+	 * avoids stalling gpu */
+	glBindBuffer(target, bu

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list