Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Rood <dev@lucarood.com>2017-05-19 18:13:48 +0300
committerLuca Rood <dev@lucarood.com>2017-05-19 18:23:19 +0300
commit42804d49b54a4522423849c402b6d55521b18512 (patch)
tree2d9bd93457b0defd65204a6189abab900db73178 /source/blender/draw/intern/draw_cache_impl_particles.c
parentc62bec8d99bc17c861353cccf50e8b05ab0af973 (diff)
Implement particle drawing with draw manager
This still has a couple of issues: * Instancing is not working when multiple particle systems use the same primitive. Only the last particle system to be drawn with a particular primitive shows up. * Because of colors being passed as uniforms with static variables, the color of the collection of the last object to be evauluated is used for all particles being displayed. Also, note that while this is being drawn in the clay engine, this might be moved to the object mode later intead. Part of T51378
Diffstat (limited to 'source/blender/draw/intern/draw_cache_impl_particles.c')
-rw-r--r--source/blender/draw/intern/draw_cache_impl_particles.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/source/blender/draw/intern/draw_cache_impl_particles.c b/source/blender/draw/intern/draw_cache_impl_particles.c
index d4247a0e365..e51873ca9a5 100644
--- a/source/blender/draw/intern/draw_cache_impl_particles.c
+++ b/source/blender/draw/intern/draw_cache_impl_particles.c
@@ -268,6 +268,43 @@ static void particle_batch_cache_ensure_pos_and_seg(ParticleSystem *psys, Partic
}
}
+static void particle_batch_cache_ensure_pos(ParticleSystem *psys, ParticleBatchCache *cache)
+{
+ if (cache->pos == NULL) {
+ static VertexFormat format = { 0 };
+ static unsigned pos_id, rot_id;
+ int i, curr_point;
+ ParticleData *pa;
+
+ VERTEXBUFFER_DISCARD_SAFE(cache->pos);
+ ELEMENTLIST_DISCARD_SAFE(cache->segments);
+
+ if (format.attrib_ct == 0) {
+ /* initialize vertex format */
+ pos_id = VertexFormat_add_attrib(&format, "pos", COMP_F32, 3, KEEP_FLOAT);
+ rot_id = VertexFormat_add_attrib(&format, "rot", COMP_F32, 4, KEEP_FLOAT);
+ }
+
+ cache->pos = VertexBuffer_create_with_format(&format);
+ VertexBuffer_allocate_data(cache->pos, psys->totpart);
+
+ for (curr_point = 0, i = 0, pa = psys->particles; i < psys->totpart; i++, pa++) {
+ if (pa->state.time >= pa->time && pa->state.time < pa->dietime &&
+ !(pa->flag & (PARS_NO_DISP | PARS_UNEXIST)))
+ {
+ VertexBuffer_set_attrib(cache->pos, pos_id, curr_point, pa->state.co);
+ VertexBuffer_set_attrib(cache->pos, rot_id, curr_point, pa->state.rot);
+
+ curr_point++;
+ }
+ }
+
+ if (curr_point != psys->totpart) {
+ VertexBuffer_resize_data(cache->pos, curr_point);
+ }
+ }
+}
+
Batch *DRW_particles_batch_cache_get_hair(ParticleSystem *psys)
{
ParticleBatchCache *cache = particle_batch_cache_get(psys);
@@ -280,3 +317,15 @@ Batch *DRW_particles_batch_cache_get_hair(ParticleSystem *psys)
return cache->hairs;
}
+
+Batch *DRW_particles_batch_cache_get_dots(ParticleSystem *psys)
+{
+ ParticleBatchCache *cache = particle_batch_cache_get(psys);
+
+ if (cache->hairs == NULL) {
+ particle_batch_cache_ensure_pos(psys, cache);
+ cache->hairs = Batch_create(PRIM_POINTS, cache->pos, NULL);
+ }
+
+ return cache->hairs;
+}