SoCache(3)
π SoCache π
okay bestie, gather round, because today we're talking about SoCache β the superclass for all the internal cache classes in Coin. she's the mom of the cache world and she's iconic for it π
she lives in the library functions manual, and honestly? she's giving structure, she's giving organization, she's giving "I hold everything together." let's get into it π
β¨ SYNOPSIS β¨
#include <Inventor/caches/SoCache.h>
Inherited by SoBoundingBoxCache, SoConvexDataCache, SoGLRenderCache, SoNormalCache, SoPrimitiveVertexCache, and SoTextureCoordinateCache. the whole girl squad fr fr π«Ά
πΈ Public Member Functions
SoCache (SoState *const state)β the constructor, she's born β¨void ref (void)β bump that reference countvoid unref (SoState *state=NULL)β drop that reference countvoid addElement (const SoElement *const elem)β add a dependency elementvirtual void addCacheDependency (const SoState *state, SoCache *cache)β link caches togethervirtual SbBool isValid (const SoState *state) constβ vibe check on the cacheconst SoElement * getInvalidElement (const SoState *const state) constβ who ruined the vibe?void invalidate (void)β force the cache to be invalid
π Protected Member Functions
virtual void destroy (SoState *state)β cleanup before deletionvirtual ~SoCache ()β the destructor, she's leaving π
π Detailed Description π
The SoCache class is the superclass for all internal cache classes.
She organizes reference counting so it's possible to share cache instances between everyone (sharing is caring, no cap π). She also organizes a list of elements that will affect the cache. and here's the tea: if any of those elements have changed since the cache was created, the cache is invalid. periodt.
π§ the cache element test algorithm (iykyk)
The cache element test algorithm in Coin works like this:
- Every element that is read before it's written when a cache is created gets stored in the
SoCache's element list. This is done to detect when something outside the cache changes. π
Example: you have a SoCoordinate3 node outside an SoSeparator, but an SoIndexedFaceSet inside the SoSeparator. If the SoSeparator creates a cache, SoIndexedFaceSet will read SoCoordinateElement, and since SoCoordinateElement hasn't been set after the cache was opened, the cache stores that element in the cache's list of element dependencies.
- At the next frame, the
SoSeparatorwill test if the cache is valid, and will then test all dependency elements. If one of the elements doesn't match, the cache is not valid and can't be used. sorry babe, she's expired π
That's the basics. There are some steps you have to do when creating a cache to make the cache dependencies work. Basically you have to do it like this:
SbBool storedinvalid = SoCacheElement::setInvalid(FALSE);
state->push();
SoMyCache * cache = new SoMyCache(state);
cache->ref();
SoCacheElement::set(state, cache);
buildMyCache();
state->pop();
SoCacheElement::setInvalid(storedinvalid);
so let's break down this little ritual, because it's literally a sequence bestie, order matters:
- First, you reset and store the old value of the cache invalid-flag.
- Then, you
push()the state so that the cache can detect when something outside the cache is changed (and to be able to change the cache element). - Next, you create the cache β don't forget to
refit π (this is the part people forget, and then everything falls apart). - Finally, set the current cache in the cache element and build the cache.
- After building the cache, you
pop()the state and restore the invalid-cache flag.
When building the cache, all elements that are read will be copied into the cache (using SoElement::copyMatchInfo()), and these copied elements are used to test the validity of the cache (in SoCache::isValid()). cute, right? π
You don't have to manually add element dependencies. They will automatically be picked up when creating the cache. This is handled in SoElement::getConstElement(). she does the work so you don't have to π
If you want the cache to be invalidated when some field inside your node is changed, it's common to overload the notify()-method, and call SoCache::invalidate() whenever the notify()-method for your node is called. See for instance SoShape::notify().
β οΈ also, don't delete the cache in yournotify()method. wait until the next time the cache is needed beforeunref-ing the old cache. do NOT do it early, that's the trap πͺ€
π Constructor & Destructor Documentation π
π SoCache::SoCache (SoState *const state)
Constructor with state being the current state. hi bestie, welcome to the world β¨
π SoCache::~SoCache () [protected], [virtual]
Destructor. bye bestie, it was real π
π₯ Member Function Documentation π₯
β void SoCache::ref (void )
Increases the reference count by one. one more person showed up to the party π
β void SoCache::unref (SoState * state = NULL)
Decreases the reference count by one. When the reference count reaches zero, the cache is deleted. The SoCache::destroy() method is called before the destructor is called. so she gets a proper goodbye first π₯Ί
β void SoCache::addElement (const SoElement *const elem)
Adds elem to the list of elements this cache depends on. your new dependency, bestie π
β void SoCache::addCacheDependency (const SoState * state, SoCache * cache) [virtual]
Adds dependencies from cache to this cache. caches linking arms, we love to see it π«Ά
β SbBool SoCache::isValid (const SoState * state) const [virtual]
Return TRUE if this cache is valid, FALSE otherwise. the ultimate vibe check π
Reimplemented in SoGLRenderCache.
β const SoElement * SoCache::getInvalidElement (const SoState *const state) const
Returns the element that caused the invalidation. Returns NULL if the cache is valid, or if the cache was not invalidated bacause of an element. (yes, that's "bacause" β I'm not fixing the typo, it's part of her charm π)
β void SoCache::invalidate (void )
Forces a cache to be invalid. sometimes you just gotta β¨
β void SoCache::destroy (SoState * state) [protected], [virtual]
Can be overridden by subclasses to clean up before they are deleted. Default method does nothing. she's low maintenance like that.
Reimplemented in SoGLRenderCache.
π Author π
Generated automatically by Doxygen for Coin from the source code.
and that's the whole page bestie!! this was Coin Version 3.1.3, page SoCache(3), and she ate every single time π
β¨ no cap, fr fr. mwah π«Άπ
π¦ where this page comes from
- fedora 43: Coin3-devel 3.1.3-40.fc43 Β· GPL-2.0-only
- fedora 43: Coin3-devel 3.1.3-40.fc43 Β· GPL-2.0-only
- fedora 44: Coin3-devel 3.1.3-42.fc44 Β· GPL-2.0-only
- fedora 44: Coin3-devel 3.1.3-42.fc44 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms