[Bf-blender-cvs] [7ba3936] strand_gpu: More detailed invalidation function for strand draw data.

Lukas Tönne noreply at git.blender.org
Thu Jul 14 16:48:24 CEST 2016


Commit: 7ba393651f34df7b54072a264dd03099d3817930
Author: Lukas Tönne
Date:   Thu Jul 14 16:46:58 2016 +0200
Branches: strand_gpu
https://developer.blender.org/rB7ba393651f34df7b54072a264dd03099d3817930

More detailed invalidation function for strand draw data.

Currently only used in its broadest form for freeing the whole buffer,
but could be used in the future to selectively invalidate parts of the
data, to avoid costly uploading of large but static buffers.

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

M	source/blender/gpu/GPU_strands.h
M	source/blender/gpu/intern/gpu_strands_buffer.c

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

diff --git a/source/blender/gpu/GPU_strands.h b/source/blender/gpu/GPU_strands.h
index 86cbdc3..b68c104 100644
--- a/source/blender/gpu/GPU_strands.h
+++ b/source/blender/gpu/GPU_strands.h
@@ -87,11 +87,19 @@ typedef struct GPUDrawStrandsParams {
 	bool use_geomshader;
 } GPUDrawStrandsParams;
 
+typedef enum GPUStrandsComponent {
+	GPU_STRANDS_COMPONENT_CONTROLS = (1 << 0),
+	GPU_STRANDS_COMPONENT_FIBER_ATTRIBUTES = (1 << 1),
+	GPU_STRANDS_COMPONENT_FIBERS = (1 << 2) | GPU_STRANDS_COMPONENT_FIBER_ATTRIBUTES,
+	GPU_STRANDS_COMPONENT_ALL = ~0,
+} GPUStrandsComponent;
+
 struct GPUDrawStrands *GPU_strands_buffer_create(struct GPUDrawStrandsParams *params);
 
 void GPU_strands_setup_verts(struct GPUDrawStrands *gpu_buffer, struct GPUDrawStrandsParams *params);
 void GPU_strands_setup_edges(struct GPUDrawStrands *gpu_buffer, struct GPUDrawStrandsParams *params);
 void GPU_strands_setup_fibers(struct GPUDrawStrands *gpu_buffer, struct GPUDrawStrandsParams *params);
+void GPU_strands_buffer_invalidate(struct GPUDrawStrands *gpu_buffer, GPUStrandsComponent);
 
 void GPU_strands_buffer_unbind(void);
 
diff --git a/source/blender/gpu/intern/gpu_strands_buffer.c b/source/blender/gpu/intern/gpu_strands_buffer.c
index a9d7c419..3a5b8ca 100644
--- a/source/blender/gpu/intern/gpu_strands_buffer.c
+++ b/source/blender/gpu/intern/gpu_strands_buffer.c
@@ -962,32 +962,58 @@ void GPU_strands_buffer_unbind(void)
 	glActiveTexture(GL_TEXTURE0);
 }
 
-void GPU_strands_buffer_free(GPUDrawStrands *gpu_buffer)
+void GPU_strands_buffer_invalidate(GPUDrawStrands *gpu_buffer, GPUStrandsComponent components)
 {
-	if (gpu_buffer) {
-#if 0 /* XXX crashes, maybe not needed for buffer textures? */
-		if (gpu_buffer->control_curves_tex.id)
-			glDeleteTextures(1, &gpu_buffer->control_curves_tex.id);
-		if (gpu_buffer->control_points_tex.id)
-			glDeleteTextures(1, &gpu_buffer->control_points_tex.id);
-		...
-#endif
-		
+	if (components & GPU_STRANDS_COMPONENT_CONTROLS) {
 		GPU_buffer_free(gpu_buffer->strand_points);
 		GPU_buffer_free(gpu_buffer->strand_edges);
 		GPU_buffer_free(gpu_buffer->control_points);
 		GPU_buffer_free(gpu_buffer->control_normals);
 		GPU_buffer_free(gpu_buffer->control_tangents);
 		GPU_buffer_free(gpu_buffer->control_curves);
-		GPU_buffer_free(gpu_buffer->fibers);
-		GPU_buffer_free(gpu_buffer->fiber_points);
-		GPU_buffer_free(gpu_buffer->fiber_edges);
+		gpu_buffer->strand_points = NULL;
+		gpu_buffer->strand_edges = NULL;
+		gpu_buffer->control_points = NULL;
+		gpu_buffer->control_normals = NULL;
+		gpu_buffer->control_tangents = NULL;
+		gpu_buffer->control_curves = NULL;
+	}
+	if (components & GPU_STRANDS_COMPONENT_FIBER_ATTRIBUTES) {
 		GPU_buffer_free(gpu_buffer->fiber_position);
 		GPU_buffer_free(gpu_buffer->fiber_normal);
 		GPU_buffer_free(gpu_buffer->fiber_tangent);
 		GPU_buffer_free(gpu_buffer->fiber_control_index);
 		GPU_buffer_free(gpu_buffer->fiber_control_weight);
 		GPU_buffer_free(gpu_buffer->fiber_root_distance);
+		gpu_buffer->fiber_position = NULL;
+		gpu_buffer->fiber_normal = NULL;
+		gpu_buffer->fiber_tangent = NULL;
+		gpu_buffer->fiber_control_index = NULL;
+		gpu_buffer->fiber_control_weight = NULL;
+		gpu_buffer->fiber_root_distance = NULL;
+	}
+	if (components & GPU_STRANDS_COMPONENT_FIBERS) {
+		GPU_buffer_free(gpu_buffer->fibers);
+		GPU_buffer_free(gpu_buffer->fiber_points);
+		GPU_buffer_free(gpu_buffer->fiber_edges);
+		gpu_buffer->fibers = NULL;
+		gpu_buffer->fiber_points = NULL;
+		gpu_buffer->fiber_edges = NULL;
+	}
+}
+
+void GPU_strands_buffer_free(GPUDrawStrands *gpu_buffer)
+{
+	if (gpu_buffer) {
+#if 0 /* XXX crashes, maybe not needed for buffer textures? */
+		if (gpu_buffer->control_curves_tex.id)
+			glDeleteTextures(1, &gpu_buffer->control_curves_tex.id);
+		if (gpu_buffer->control_points_tex.id)
+			glDeleteTextures(1, &gpu_buffer->control_points_tex.id);
+		...
+#endif
+		
+		GPU_strands_buffer_invalidate(gpu_buffer, GPU_STRANDS_COMPONENT_ALL);
 		
 		MEM_freeN(gpu_buffer);
 	}




More information about the Bf-blender-cvs mailing list