diff options
author | Lukas Tönne <lukas.toenne@gmail.com> | 2016-07-08 14:29:17 +0300 |
---|---|---|
committer | Lukas Tönne <lukas.toenne@gmail.com> | 2016-07-08 17:22:21 +0300 |
commit | bbe11e39492db63d87305bcfbe157f7efda73179 (patch) | |
tree | 223a81594cb3b0c2993597a493b226ccc44cf1a9 /source/blender/editors/space_view3d | |
parent | fa1abf564e9d551db6d5be38891d246a055300c7 (diff) |
Unified buffer creation for drawing strands in object and edit mode.
Control strands are now drawn without subdivision. Control and fiber
strands get their own vertex buffers for this purpose.
The intermediate StrandData has been removed, because it is just
redundant storage of the draw data buffers. The results in StrandData
are not used for further editing, so there is really no point in
keeping them around.
Diffstat (limited to 'source/blender/editors/space_view3d')
-rw-r--r-- | source/blender/editors/space_view3d/drawobject.c | 15 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/drawstrands.c | 96 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_intern.h | 13 |
3 files changed, 67 insertions, 57 deletions
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 180116ca11d..eddc9f2fca4 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -7976,23 +7976,14 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short for (md = ob->modifiers.first; md; md = md->next) { 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_STRANDS; - bool show_strands = smd->flag & MOD_STRANDS_SHOW_FIBERS; - if (edit) { + if (ob->mode & OB_MODE_HAIR_EDIT && is_obact) { if (!(dflag & DRAW_PICKING) && scene->obedit == NULL) { - draw_strands_edit_hair(scene, v3d, rv3d, ob, - smd->strands, edit, - show_controls, show_strands); + draw_strands_edit(scene, v3d, rv3d, ob, smd); } } else { - if (smd->strands && smd->strands->data_final) { - draw_strands(scene, v3d, rv3d, ob, - smd->strands, smd->strands->data_final, - show_controls, show_strands); - } + draw_strands(scene, v3d, rv3d, ob, smd); } } } diff --git a/source/blender/editors/space_view3d/drawstrands.c b/source/blender/editors/space_view3d/drawstrands.c index 1beeaf0984c..3889308f1ee 100644 --- a/source/blender/editors/space_view3d/drawstrands.c +++ b/source/blender/editors/space_view3d/drawstrands.c @@ -31,6 +31,7 @@ #include "MEM_guardedalloc.h" +#include "DNA_modifier_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" #include "DNA_screen_types.h" @@ -66,43 +67,54 @@ #include "view3d_intern.h" // own include -void draw_strands(Scene *UNUSED(scene), View3D *UNUSED(v3d), RegionView3D *rv3d, - Object *ob, Strands *strands, StrandData *data, - bool show_controls, bool show_strands) +void draw_strands(Scene *scene, View3D *UNUSED(v3d), RegionView3D *rv3d, + Object *ob, StrandsModifierData *smd) { - GPUStrandsShader *gpu_shader = GPU_strand_shader_get(strands); + Strands *strands = smd->strands; + bool show_controls = smd->flag & MOD_STRANDS_SHOW_STRANDS; + bool show_strands = smd->flag & MOD_STRANDS_SHOW_FIBERS; + if (strands == NULL) + return; + + GPUDrawStrandsParams params = {0}; + params.strands = smd->strands; + params.root_dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH); + params.subdiv = smd->subdiv; + + if (smd->gpu_buffer == NULL) + smd->gpu_buffer = GPU_strands_buffer_create(¶ms); + GPUDrawStrands *buffer = smd->gpu_buffer; + GPUStrandsShader *shader = GPU_strand_shader_get(strands); if (show_controls) { - GPU_strands_setup_edges(data); - GPUDrawStrands *gds = data->gpu_buffer; - if (gds->strand_points && gds->strand_edges) { - GPU_buffer_draw_elements(gds->strand_edges, GL_LINES, 0, - (gds->totverts - gds->totcurves) * 2); + GPU_strands_setup_edges(buffer, ¶ms); + if (buffer->strand_points && buffer->strand_edges) { + GPU_buffer_draw_elements(buffer->strand_edges, GL_LINES, 0, + buffer->strand_totedges * 2); } GPU_buffers_unbind(); } if (show_strands) { - GPU_strand_shader_bind_uniforms(gpu_shader, ob->obmat, rv3d->viewmat); - GPU_strand_shader_bind(gpu_shader, rv3d->viewmat, rv3d->viewinv); + GPU_strand_shader_bind_uniforms(shader, ob->obmat, rv3d->viewmat); + GPU_strand_shader_bind(shader, rv3d->viewmat, rv3d->viewinv); - GPU_strands_setup_fibers(data); - GPUDrawStrands *gds = data->gpu_buffer; - if (gds->fiber_points) { + GPU_strands_setup_fibers(buffer, ¶ms); + if (buffer->fiber_points) { struct GPUAttrib *attrib; int num_attrib; - GPU_strand_shader_get_attributes(strands->gpu_shader, &attrib, &num_attrib); + GPU_strand_shader_get_attributes(shader, &attrib, &num_attrib); int elemsize = GPU_attrib_element_size(attrib, num_attrib); - GPU_interleaved_attrib_setup(gds->fiber_points, attrib, num_attrib, elemsize, false); + GPU_interleaved_attrib_setup(buffer->fiber_points, attrib, num_attrib, elemsize, false); - glDrawArrays(GL_POINTS, 0, gds->totfibers * elemsize); + glDrawArrays(GL_POINTS, 0, buffer->totfibers * elemsize); GPU_interleaved_attrib_unbind(); } GPU_strands_buffer_unbind(); - GPU_strand_shader_unbind(gpu_shader); + GPU_strand_shader_unbind(shader); } } @@ -417,43 +429,55 @@ static void draw_dots(BMEditStrands *edit, const StrandsDrawInfo *info, bool sel } #endif -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) +void draw_strands_edit(Scene *scene, View3D *UNUSED(v3d), RegionView3D *rv3d, + Object *ob, StrandsModifierData *smd) { - GPUStrandsShader *gpu_shader = GPU_strand_shader_get(strands); + BMEditStrands *edit = smd->edit; + bool show_controls = smd->flag & MOD_STRANDS_SHOW_STRANDS; + bool show_strands = smd->flag & MOD_STRANDS_SHOW_FIBERS; + + if (smd->strands == NULL || edit == NULL) + return; + + GPUDrawStrandsParams params = {0}; + params.strands = smd->strands; + params.edit = edit; + params.root_dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH); + params.subdiv = smd->subdiv; + + if (smd->gpu_buffer == NULL) + smd->gpu_buffer = GPU_strands_buffer_create(¶ms); + GPUDrawStrands *buffer = smd->gpu_buffer; + GPUStrandsShader *shader = GPU_strand_shader_get(smd->strands); if (show_controls) { - GPU_editstrands_setup_edges(edit); - GPUDrawStrands *gds = edit->gpu_buffer; - if (gds->strand_points && gds->strand_edges) { - GPU_buffer_draw_elements(gds->strand_edges, GL_LINES, 0, - (gds->totverts - gds->totcurves) * 2); + GPU_strands_setup_edges(buffer, ¶ms); + if (buffer->strand_points && buffer->strand_edges) { + GPU_buffer_draw_elements(buffer->strand_edges, GL_LINES, 0, buffer->strand_totedges * 2); } GPU_buffers_unbind(); } if (show_strands) { - GPU_strand_shader_bind_uniforms(gpu_shader, ob->obmat, rv3d->viewmat); - GPU_strand_shader_bind(gpu_shader, rv3d->viewmat, rv3d->viewinv); + GPU_strand_shader_bind_uniforms(shader, ob->obmat, rv3d->viewmat); + GPU_strand_shader_bind(shader, rv3d->viewmat, rv3d->viewinv); - GPU_editstrands_setup_fibers(edit); - GPUDrawStrands *gds = edit->gpu_buffer; - if (gds->fiber_points) { + GPU_strands_setup_fibers(buffer, ¶ms); + if (buffer->fiber_points) { struct GPUAttrib *attrib; int num_attrib; - GPU_strand_shader_get_attributes(strands->gpu_shader, &attrib, &num_attrib); + GPU_strand_shader_get_attributes(shader, &attrib, &num_attrib); int elemsize = GPU_attrib_element_size(attrib, num_attrib); - GPU_interleaved_attrib_setup(gds->fiber_points, attrib, num_attrib, elemsize, false); + GPU_interleaved_attrib_setup(buffer->fiber_points, attrib, num_attrib, elemsize, false); - glDrawArrays(GL_POINTS, 0, gds->totfibers * elemsize); + glDrawArrays(GL_POINTS, 0, buffer->totfibers * elemsize); GPU_interleaved_attrib_unbind(); } GPU_strands_buffer_unbind(); - GPU_strand_shader_unbind(gpu_shader); + GPU_strand_shader_unbind(shader); } #if 0 diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h index ec47ad53d25..ced1b9b6cb4 100644 --- a/source/blender/editors/space_view3d/view3d_intern.h +++ b/source/blender/editors/space_view3d/view3d_intern.h @@ -46,9 +46,7 @@ struct bContext; struct bMotionPath; struct bPoseChannel; struct Mesh; -struct Strands; -struct StrandData; -struct BMEditStrands; +struct StrandsModifierData; struct wmNDOFMotionData; struct wmOperatorType; struct wmWindowManager; @@ -290,12 +288,9 @@ extern const char *view3d_context_dir[]; /* doc access */ /* drawstrands.c */ 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(struct Scene *scene, struct View3D *v3d, struct RegionView3D *rv3d, - struct Object *ob, struct Strands *strands, struct BMEditStrands *edit, - bool show_controls, bool show_strands); + struct Object *ob, struct StrandsModifierData *smd); +void draw_strands_edit(struct Scene *scene, struct View3D *v3d, struct RegionView3D *rv3d, + struct Object *ob, struct StrandsModifierData *smd); /* drawvolume.c */ void draw_smoke_volume(struct SmokeDomainSettings *sds, struct Object *ob, |