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:
authorHans Goudey <h.goudey@me.com>2021-04-08 20:00:26 +0300
committerHans Goudey <h.goudey@me.com>2021-04-08 20:00:26 +0300
commitfd414b49068c011a1fd63a304ea95bbe420d6570 (patch)
treecb08572a2ec4db702d41b12efbf2f6e010296510 /source/blender/makesrna
parentb51562ed76d5428ed4d511cd248d1b059e341661 (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/makesrna')
-rw-r--r--source/blender/makesrna/intern/rna_volume.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/source/blender/makesrna/intern/rna_volume.c b/source/blender/makesrna/intern/rna_volume.c
index 1bddd9152db..76db6f3e325 100644
--- a/source/blender/makesrna/intern/rna_volume.c
+++ b/source/blender/makesrna/intern/rna_volume.c
@@ -137,7 +137,7 @@ static void rna_Volume_grids_end(CollectionPropertyIterator *UNUSED(iter))
static PointerRNA rna_Volume_grids_get(CollectionPropertyIterator *iter)
{
Volume *volume = iter->internal.count.ptr;
- const VolumeGrid *grid = BKE_volume_grid_get(volume, iter->internal.count.item);
+ const VolumeGrid *grid = BKE_volume_grid_get_for_read(volume, iter->internal.count.item);
return rna_pointer_inherit_refine(&iter->parent, &RNA_VolumeGrid, (void *)grid);
}
@@ -207,6 +207,16 @@ static int rna_VolumeGrids_frame_filepath_length(PointerRNA *ptr)
return strlen(BKE_volume_grids_frame_filepath(volume));
}
+static bool rna_Volume_load(Volume *volume, Main *bmain)
+{
+ return BKE_volume_load(volume, bmain);
+}
+
+static bool rna_Volume_save(Volume *volume, Main *bmain, ReportList *reports, const char *filepath)
+{
+ return BKE_volume_save(volume, bmain, reports, filepath);
+}
+
#else
static void rna_def_volume_grid(BlenderRNA *brna)
@@ -335,7 +345,7 @@ static void rna_def_volume_grids(BlenderRNA *brna, PropertyRNA *cprop)
FunctionRNA *func;
PropertyRNA *parm;
- func = RNA_def_function(srna, "load", "BKE_volume_load");
+ func = RNA_def_function(srna, "load", "rna_Volume_load");
RNA_def_function_ui_description(func, "Load list of grids and metadata from file");
RNA_def_function_flag(func, FUNC_USE_MAIN);
parm = RNA_def_boolean(func, "success", 0, "", "True if grid list was successfully loaded");
@@ -344,7 +354,7 @@ static void rna_def_volume_grids(BlenderRNA *brna, PropertyRNA *cprop)
func = RNA_def_function(srna, "unload", "BKE_volume_unload");
RNA_def_function_ui_description(func, "Unload all grid and voxel data from memory");
- func = RNA_def_function(srna, "save", "BKE_volume_save");
+ func = RNA_def_function(srna, "save", "rna_Volume_save");
RNA_def_function_ui_description(func, "Save grids and metadata to file");
RNA_def_function_flag(func, FUNC_USE_MAIN | FUNC_USE_REPORTS);
parm = RNA_def_string_file_path(func, "filepath", NULL, 0, "", "File path to save to");