Page MenuHome

Refactor: Const correct Custom Data API, prepare for CoW
ClosedPublic

Authored by Hans Goudey (HooglyBoogly) on Feb 17 2022, 5:31 PM.

Details

Summary

Currently you can retrieve a mutable array from a const CustomData.
That makes code unsafe since the compiler can't check for correctness
itself. Fix that by introducing a separate function to retrieve mutable
arrays from CustomData. The new functions have the _for_write
suffix that make the code's intention clearer.

Because it makes retrieving write access an explicit step, this change
also makes proper copy-on-write possible for attributes.

Notes:

  • The previous "duplicate referenced layer" functions are redundant with retrieving layers with write access
  • The custom data functions that give a specific index only have for_write to simplify the API

Diff Detail

Repository
rB Blender

Event Timeline

Jacques Lucke (JacquesLucke) requested review of this revision.Feb 17 2022, 5:31 PM
Jacques Lucke (JacquesLucke) created this revision.
Hans Goudey (HooglyBoogly) retitled this revision from Prepare custom data API for attribute sharing. (WIP) to Refactor: Const correct Custom Data API, prepare for CoW.
Hans Goudey (HooglyBoogly) edited the summary of this revision. (Show Details)
Hans Goudey (HooglyBoogly) edited the summary of this revision. (Show Details)

Split off some changes that were only adding const

Need to merge master again and then this should pass the buildbot before merging.

source/blender/blenkernel/BKE_customdata.h
400

Would be good to update the comments a bit.

source/blender/blenkernel/intern/mesh_legacy_convert.cc
304

clang format

source/blender/blenkernel/intern/subsurf_ccg.c
394

getNumLoops looks wrong

This revision is now accepted and ready to land.Fri, Jan 13, 10:54 PM
Hans Goudey (HooglyBoogly) marked 2 inline comments as done.
Hans Goudey (HooglyBoogly) marked an inline comment as done.