diff options
Diffstat (limited to 'source/blender/draw/engines/eevee/eevee_data.c')
-rw-r--r-- | source/blender/draw/engines/eevee/eevee_data.c | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/source/blender/draw/engines/eevee/eevee_data.c b/source/blender/draw/engines/eevee/eevee_data.c index a19af77124f..5ca24d296c5 100644 --- a/source/blender/draw/engines/eevee/eevee_data.c +++ b/source/blender/draw/engines/eevee/eevee_data.c @@ -24,11 +24,135 @@ #include "DRW_render.h" +#include "BLI_ghash.h" #include "BLI_memblock.h" +#include "BKE_duplilist.h" + +#include "DEG_depsgraph_query.h" + +#include "GPU_vertex_buffer.h" + #include "eevee_lightcache.h" #include "eevee_private.h" +/* Motion Blur data. */ + +static void eevee_motion_blur_mesh_data_free(void *val) +{ + EEVEE_GeometryMotionData *geom_mb = (EEVEE_GeometryMotionData *)val; + for (int i = 0; i < ARRAY_SIZE(geom_mb->vbo); i++) { + GPU_VERTBUF_DISCARD_SAFE(geom_mb->vbo[i]); + } + MEM_freeN(val); +} + +static uint eevee_object_key_hash(const void *key) +{ + EEVEE_ObjectKey *ob_key = (EEVEE_ObjectKey *)key; + uint hash = BLI_ghashutil_ptrhash(ob_key->ob); + hash = BLI_ghashutil_combine_hash(hash, BLI_ghashutil_ptrhash(ob_key->parent)); + for (int i = 0; i < 16; i++) { + if (ob_key->id[i] != 0) { + hash = BLI_ghashutil_combine_hash(hash, BLI_ghashutil_inthash(ob_key->id[i])); + } + else { + break; + } + } + return hash; +} + +/* Return false if equal. */ +static bool eevee_object_key_cmp(const void *a, const void *b) +{ + EEVEE_ObjectKey *key_a = (EEVEE_ObjectKey *)a; + EEVEE_ObjectKey *key_b = (EEVEE_ObjectKey *)b; + + if (key_a->ob != key_b->ob) { + return true; + } + if (key_a->parent != key_b->parent) { + return true; + } + if (memcmp(key_a->id, key_b->id, sizeof(key_a->id)) != 0) { + return true; + } + return false; +} + +void EEVEE_motion_blur_data_init(EEVEE_MotionBlurData *mb) +{ + if (mb->object == NULL) { + mb->object = BLI_ghash_new(eevee_object_key_hash, eevee_object_key_cmp, "EEVEE Object Motion"); + } + if (mb->geom == NULL) { + mb->geom = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "EEVEE Mesh Motion"); + } +} + +void EEVEE_motion_blur_data_free(EEVEE_MotionBlurData *mb) +{ + if (mb->object) { + BLI_ghash_free(mb->object, MEM_freeN, MEM_freeN); + mb->object = NULL; + } + if (mb->geom) { + BLI_ghash_free(mb->geom, NULL, eevee_motion_blur_mesh_data_free); + mb->geom = NULL; + } +} + +EEVEE_ObjectMotionData *EEVEE_motion_blur_object_data_get(EEVEE_MotionBlurData *mb, Object *ob) +{ + if (mb->object == NULL) { + return NULL; + } + + EEVEE_ObjectKey key, *key_p; + key.ob = ob; + DupliObject *dup = DRW_object_get_dupli(ob); + if (dup) { + key.parent = DRW_object_get_dupli_parent(ob); + memcpy(key.id, dup->persistent_id, sizeof(key.id)); + } + else { + key.parent = key.ob; + memset(key.id, 0, sizeof(key.id)); + } + + EEVEE_ObjectMotionData *ob_step = BLI_ghash_lookup(mb->object, &key); + if (ob_step == NULL) { + key_p = MEM_mallocN(sizeof(*key_p), __func__); + memcpy(key_p, &key, sizeof(*key_p)); + + ob_step = MEM_callocN(sizeof(EEVEE_ObjectMotionData), __func__); + + BLI_ghash_insert(mb->object, key_p, ob_step); + } + return ob_step; +} + +EEVEE_GeometryMotionData *EEVEE_motion_blur_geometry_data_get(EEVEE_MotionBlurData *mb, Object *ob) +{ + if (mb->geom == NULL) { + return NULL; + } + + /* Use original data as key to ensure matching accross update. */ + Object *ob_orig = DEG_get_original_object(ob); + + EEVEE_GeometryMotionData *geom_step = BLI_ghash_lookup(mb->geom, ob_orig->data); + if (geom_step == NULL) { + geom_step = MEM_callocN(sizeof(EEVEE_GeometryMotionData), __func__); + BLI_ghash_insert(mb->geom, ob_orig->data, geom_step); + } + + return geom_step; +} + +/* View Layer data. */ + void EEVEE_view_layer_data_free(void *storage) { EEVEE_ViewLayerData *sldata = (EEVEE_ViewLayerData *)storage; |