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/modifiers | |
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/modifiers')
-rw-r--r-- | source/blender/modifiers/intern/MOD_volume_displace.cc | 2 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_volume_to_mesh.cc | 4 |
2 files changed, 3 insertions, 3 deletions
diff --git a/source/blender/modifiers/intern/MOD_volume_displace.cc b/source/blender/modifiers/intern/MOD_volume_displace.cc index 745e089b8ff..e7c4004853e 100644 --- a/source/blender/modifiers/intern/MOD_volume_displace.cc +++ b/source/blender/modifiers/intern/MOD_volume_displace.cc @@ -293,7 +293,7 @@ static Volume *modifyVolume(ModifierData *md, const ModifierEvalContext *ctx, Vo BKE_volume_load(volume, DEG_get_bmain(ctx->depsgraph)); const int grid_amount = BKE_volume_num_grids(volume); for (int grid_index = 0; grid_index < grid_amount; grid_index++) { - VolumeGrid *volume_grid = BKE_volume_grid_get(volume, grid_index); + VolumeGrid *volume_grid = BKE_volume_grid_get_for_write(volume, grid_index); BLI_assert(volume_grid != nullptr); openvdb::GridBase::Ptr grid = BKE_volume_grid_openvdb_for_write(volume, volume_grid, false); diff --git a/source/blender/modifiers/intern/MOD_volume_to_mesh.cc b/source/blender/modifiers/intern/MOD_volume_to_mesh.cc index 41ed7ae983a..3bf5cf6ab5b 100644 --- a/source/blender/modifiers/intern/MOD_volume_to_mesh.cc +++ b/source/blender/modifiers/intern/MOD_volume_to_mesh.cc @@ -155,10 +155,10 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * return create_empty_mesh(input_mesh); } - Volume *volume = static_cast<Volume *>(vmmd->object->data); + const Volume *volume = static_cast<Volume *>(vmmd->object->data); BKE_volume_load(volume, DEG_get_bmain(ctx->depsgraph)); - VolumeGrid *volume_grid = BKE_volume_grid_find(volume, vmmd->grid_name); + const VolumeGrid *volume_grid = BKE_volume_grid_find_for_read(volume, vmmd->grid_name); if (volume_grid == nullptr) { BKE_modifier_set_error(ctx->object, md, "Cannot find '%s' grid", vmmd->grid_name); return create_empty_mesh(input_mesh); |