diff options
author | Hans Goudey <h.goudey@me.com> | 2021-04-08 20:00:26 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-04-08 20:00:26 +0300 |
commit | fd414b49068c011a1fd63a304ea95bbe420d6570 (patch) | |
tree | cb08572a2ec4db702d41b12efbf2f6e010296510 /source/blender/draw/intern | |
parent | b51562ed76d5428ed4d511cd248d1b059e341661 (diff) |
Cleanup: Use const arguments for volume code
The problem was that you could getting write access to a grid from a
`const Volume *` without breaking const correctness. I encountered this
when working on support for volumes in the bounding box node. For
geometry nodes there is an important distinction between getting data
"for read" and "for write", with the former returning a `const` version
of the data.
Also, for volumes it was necessary to cast away const, since all of
the relevant functions in `volume.cc` didn't have const versions. This
patch adds `const` in these places, distinguising between "for read"
and "for write" versions of functions where necessary.
The downside is that loading and unloading in the global volume cache
needs const write-access to some member variables. I see that as an
inherent problem that comes up with caching that never has a beautiful
solution anyway.
Some of the const-ness could probably be propogated futher in EEVEE
code, but I'll leave that out, since there is another level of caching.
Differential Revision: https://developer.blender.org/D10916
Diffstat (limited to 'source/blender/draw/intern')
-rw-r--r-- | source/blender/draw/intern/draw_cache.h | 3 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache_impl_volume.c | 10 |
2 files changed, 7 insertions, 6 deletions
diff --git a/source/blender/draw/intern/draw_cache.h b/source/blender/draw/intern/draw_cache.h index c15c246992d..c58dd85b6ed 100644 --- a/source/blender/draw/intern/draw_cache.h +++ b/source/blender/draw/intern/draw_cache.h @@ -244,7 +244,8 @@ typedef struct DRWVolumeGrid { float bounds_to_texture[4][4]; } DRWVolumeGrid; -DRWVolumeGrid *DRW_volume_batch_cache_get_grid(struct Volume *volume, struct VolumeGrid *grid); +DRWVolumeGrid *DRW_volume_batch_cache_get_grid(struct Volume *volume, + const struct VolumeGrid *grid); struct GPUBatch *DRW_cache_volume_face_wireframe_get(struct Object *ob); struct GPUBatch *DRW_cache_volume_selection_surface_get(struct Object *ob); diff --git a/source/blender/draw/intern/draw_cache_impl_volume.c b/source/blender/draw/intern/draw_cache_impl_volume.c index 7244dfd12c3..52ebf1b239e 100644 --- a/source/blender/draw/intern/draw_cache_impl_volume.c +++ b/source/blender/draw/intern/draw_cache_impl_volume.c @@ -225,7 +225,7 @@ GPUBatch *DRW_volume_batch_cache_get_wireframes_face(Volume *volume) VolumeBatchCache *cache = volume_batch_cache_get(volume); if (cache->face_wire.batch == NULL) { - VolumeGrid *volume_grid = BKE_volume_grid_active_get(volume); + const VolumeGrid *volume_grid = BKE_volume_grid_active_get_for_read(volume); if (volume_grid == NULL) { return NULL; } @@ -274,7 +274,7 @@ GPUBatch *DRW_volume_batch_cache_get_selection_surface(Volume *volume) { VolumeBatchCache *cache = volume_batch_cache_get(volume); if (cache->selection_surface == NULL) { - VolumeGrid *volume_grid = BKE_volume_grid_active_get(volume); + const VolumeGrid *volume_grid = BKE_volume_grid_active_get_for_read(volume); if (volume_grid == NULL) { return NULL; } @@ -284,8 +284,8 @@ GPUBatch *DRW_volume_batch_cache_get_selection_surface(Volume *volume) return cache->selection_surface; } -static DRWVolumeGrid *volume_grid_cache_get(Volume *volume, - VolumeGrid *grid, +static DRWVolumeGrid *volume_grid_cache_get(const Volume *volume, + const VolumeGrid *grid, VolumeBatchCache *cache) { const char *name = BKE_volume_grid_name(grid); @@ -351,7 +351,7 @@ static DRWVolumeGrid *volume_grid_cache_get(Volume *volume, return cache_grid; } -DRWVolumeGrid *DRW_volume_batch_cache_get_grid(Volume *volume, VolumeGrid *volume_grid) +DRWVolumeGrid *DRW_volume_batch_cache_get_grid(Volume *volume, const VolumeGrid *volume_grid) { VolumeBatchCache *cache = volume_batch_cache_get(volume); DRWVolumeGrid *grid = volume_grid_cache_get(volume, volume_grid, cache); |