[Bf-blender-cvs] [4fbebd6] strand_gpu: Use an additional texture buffer for storing curve indices.
Lukas Tönne
noreply at git.blender.org
Tue Jul 5 09:57:16 CEST 2016
Commit: 4fbebd6c09c3a5aa848bd520ce05b2fb57545e9e
Author: Lukas Tönne
Date: Sat Jul 2 14:46:18 2016 +0200
Branches: strand_gpu
https://developer.blender.org/rB4fbebd6c09c3a5aa848bd520ce05b2fb57545e9e
Use an additional texture buffer for storing curve indices.
The geometry shader will need to do 2 texture lookups per control,
first for getting the control curve start and length, then for
reading the appropriate curve vertices.
===================================================================
M source/blender/gpu/GPU_buffers.h
M source/blender/gpu/intern/gpu_buffers.c
===================================================================
diff --git a/source/blender/gpu/GPU_buffers.h b/source/blender/gpu/GPU_buffers.h
index f18aad3..c769f01 100644
--- a/source/blender/gpu/GPU_buffers.h
+++ b/source/blender/gpu/GPU_buffers.h
@@ -150,11 +150,13 @@ typedef struct GPUBufferTexture {
typedef struct GPUDrawStrands {
GPUBuffer *control_points;
+ GPUBuffer *control_curves;
GPUBuffer *control_edges;
GPUBuffer *root_points;
/* GL texture id for control point texture buffer */
GPUBufferTexture control_points_tex;
+ GPUBufferTexture control_curves_tex;
unsigned int totverts;
unsigned int totcurves;
diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index 0782b52..e427e68 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -2103,6 +2103,7 @@ typedef struct RootVertex {
typedef enum GPUStrandBufferType {
GPU_STRAND_BUFFER_CONTROL_VERTEX = 0,
+ GPU_STRAND_BUFFER_CONTROL_CURVE,
GPU_STRAND_BUFFER_CONTROL_EDGE,
GPU_STRAND_BUFFER_ROOT_VERTEX,
} GPUStrandBufferType;
@@ -2110,6 +2111,8 @@ typedef enum GPUStrandBufferType {
const GPUBufferTypeSettings gpu_strand_buffer_type_settings[] = {
/* CONTROL_VERTEX */
{GL_ARRAY_BUFFER, 3},
+ /* CONTROL_CURVE */
+ {GL_ELEMENT_ARRAY_BUFFER, 2},
/* CONTROL_EDGE */
{GL_ELEMENT_ARRAY_BUFFER, 2},
/* ROOT_VERTEX */
@@ -2122,6 +2125,8 @@ static GPUBuffer **gpu_strands_buffer_from_type(GPUDrawStrands *gds, GPUStrandBu
switch (type) {
case GPU_STRAND_BUFFER_CONTROL_VERTEX:
return &gds->control_points;
+ case GPU_STRAND_BUFFER_CONTROL_CURVE:
+ return &gds->control_curves;
case GPU_STRAND_BUFFER_CONTROL_EDGE:
return &gds->control_edges;
case GPU_STRAND_BUFFER_ROOT_VERTEX:
@@ -2138,6 +2143,9 @@ static GPUBufferTexture *gpu_strands_buffer_texture_from_type(GPUDrawStrands *gd
case GPU_STRAND_BUFFER_CONTROL_VERTEX:
*format = GL_RGB32F;
return &gds->control_points_tex;
+ case GPU_STRAND_BUFFER_CONTROL_CURVE:
+ *format = GL_R32UI;
+ return &gds->control_curves_tex;
default:
*format = 0;
return NULL;
@@ -2155,6 +2163,8 @@ static size_t gpu_strands_buffer_size_from_type(StrandData *strands, GPUStrandBu
switch (type) {
case GPU_STRAND_BUFFER_CONTROL_VERTEX:
return sizeof(float) * components * totverts;
+ case GPU_STRAND_BUFFER_CONTROL_CURVE:
+ return sizeof(int) * components * totcurves;
case GPU_STRAND_BUFFER_CONTROL_EDGE:
return sizeof(int) * components * (totverts - totcurves);
case GPU_STRAND_BUFFER_ROOT_VERTEX:
@@ -2186,6 +2196,18 @@ static void strands_copy_vertex_buffer(StrandData *strands, float (*varray)[3])
}
}
+static void strands_copy_curve_buffer(StrandData *strands, unsigned int (*varray)[2])
+{
+ int totcurves = strands->totcurves, c;
+
+ StrandCurveData *curve = strands->curves;
+ for (c = 0; c < totcurves; ++c, ++curve) {
+ (*varray)[0] = curve->verts_begin;
+ (*varray)[1] = curve->num_verts;
+ ++varray;
+ }
+}
+
static void strands_copy_edge_buffer(StrandData *strands, unsigned int (*varray)[2])
{
int totcurves = strands->totcurves, c;
@@ -2226,6 +2248,9 @@ static void strands_copy_gpu_data(StrandData *strands, GPUStrandBufferType type,
case GPU_STRAND_BUFFER_CONTROL_VERTEX:
strands_copy_vertex_buffer(strands, (float (*)[3])varray);
break;
+ case GPU_STRAND_BUFFER_CONTROL_CURVE:
+ strands_copy_curve_buffer(strands, (unsigned int (*)[2])varray);
+ break;
case GPU_STRAND_BUFFER_CONTROL_EDGE:
strands_copy_edge_buffer(strands, (unsigned int (*)[2])varray);
break;
@@ -2356,6 +2381,10 @@ void GPU_strands_setup_edges(StrandData *strands)
void GPU_strands_setup_roots(StrandData *strands)
{
+ if (!strands_setup_buffer_common(strands, GPU_STRAND_BUFFER_CONTROL_VERTEX, false))
+ return;
+ if (!strands_setup_buffer_common(strands, GPU_STRAND_BUFFER_CONTROL_CURVE, false))
+ return;
if (!strands_setup_buffer_common(strands, GPU_STRAND_BUFFER_ROOT_VERTEX, false))
return;
@@ -2366,6 +2395,10 @@ void GPU_strands_setup_roots(StrandData *strands)
GLStates |= (GPU_BUFFER_VERTEX_STATE);
glActiveTexture(GL_TEXTURE0);
+ if (strands->gpu_buffer->control_curves_tex.id != 0) {
+ glBindTexture(GL_TEXTURE_BUFFER, strands->gpu_buffer->control_curves_tex.id);
+ }
+ glActiveTexture(GL_TEXTURE1);
if (strands->gpu_buffer->control_points_tex.id != 0) {
glBindTexture(GL_TEXTURE_BUFFER, strands->gpu_buffer->control_points_tex.id);
}
More information about the Bf-blender-cvs
mailing list