From fd414b49068c011a1fd63a304ea95bbe420d6570 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Thu, 8 Apr 2021 12:00:26 -0500 Subject: 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 --- intern/cycles/blender/blender_volume.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'intern') diff --git a/intern/cycles/blender/blender_volume.cpp b/intern/cycles/blender/blender_volume.cpp index 0ff4de846e1..772ab9f5c8a 100644 --- a/intern/cycles/blender/blender_volume.cpp +++ b/intern/cycles/blender/blender_volume.cpp @@ -26,7 +26,7 @@ #ifdef WITH_OPENVDB # include openvdb::GridBase::ConstPtr BKE_volume_grid_openvdb_for_read(const struct Volume *volume, - struct VolumeGrid *grid); + const struct VolumeGrid *grid); #endif CCL_NAMESPACE_BEGIN @@ -227,7 +227,7 @@ class BlenderVolumeLoader : public VDBImageLoader { const bool unload = !b_volume_grid.is_loaded(); ::Volume *volume = (::Volume *)b_volume.ptr.data; - VolumeGrid *volume_grid = (VolumeGrid *)b_volume_grid.ptr.data; + const VolumeGrid *volume_grid = (VolumeGrid *)b_volume_grid.ptr.data; grid = BKE_volume_grid_openvdb_for_read(volume, volume_grid); if (unload) { -- cgit v1.2.3