VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtCDBStateSetCache.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2025 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #include <osgEarth/Common>
11 #include <osgEarth/Threading>
12 #include <osg/StateSet>
13 #include <set>
14 
15 namespace makVrv
16 {
17  namespace oe
18  {
19  namespace CDB
20  {
23  class DtCDBStateSetCache : public osg::Referenced
24  {
25  public:
30 
34  void setMaxSize( unsigned maxSize );
35 
39  bool eligible( osg::StateSet* stateSet ) const;
40 
44  bool eligible( osg::StateAttribute* attr ) const;
45 
46  void setOptimizeTextureAttributes( bool optimizeTexAtt );
47  bool optimizeTextureAttributes() const;
49  bool traverseProxies() const;
50  void setProtectAfterCache( bool protect );
51  bool protectAfterCache() const;
52 
58  void consolidateStateAttributes( osg::Node* node );
59 
64  void consolidateStateSets( osg::Node* node );
65 
69  void optimize( osg::Node* node );
70 
78  bool share( osg::ref_ptr<osg::StateSet>& input );
79 
88 
91  void protect();
92 
96  void clear();
97 
98  void dumpStats();
99 
100  void releaseGLObjects( osg::State* state ) const;
101 
102  void resizeGLObjectBuffers( unsigned size );
103 
104  protected:
105 
106  virtual ~DtCDBStateSetCache();
107 
109  {
111  const osg::ref_ptr<osg::StateSet>& lhs,
112  const osg::ref_ptr<osg::StateSet>& rhs ) const
113  {
114  return lhs->compare( *(rhs.get()), true ) < 0;
115  }
116  };
117  typedef std::set< osg::ref_ptr<osg::StateSet>, CompareStateSets> StateSetSet;
119 
121  {
124  const osg::ref_ptr<osg::StateAttribute>& rhs ) const
125  {
126  return lhs->compare( *rhs.get() ) < 0;
127  }
128  };
129  typedef std::set< osg::ref_ptr<osg::StateAttribute>, CompareStateAttributes> StateAttributeSet;
131 
132  mutable std::mutex _mutex;
133 
134  void prune();
135  void pruneIfNecessary();
136  unsigned _maxSize;
137  unsigned _pruneCount;
138 
142  //stats
145  unsigned _attrShareHits;
147  };
148  }
149  }
150 }
bool eligible(osg::StateSet *stateSet) const
Check whether a StateSet is eligible for sharing.
unsigned _attrShareMisses
Definition: DtCDBStateSetCache.h:146
void setProtectAfterCache(bool protect)
Definition: DtCDBStateSetCache.h:108
void consolidateStateSets(osg::Node *node)
Scans a graph and combines equivalent statesets into a single shared stateset.
std::set< osg::ref_ptr< osg::StateSet >, CompareStateSets > StateSetSet
Definition: DtCDBStateSetCache.h:117
std::set< osg::ref_ptr< osg::StateAttribute >, CompareStateAttributes > StateAttributeSet
Definition: DtCDBStateSetCache.h:129
bool operator()(const osg::ref_ptr< osg::StateSet > &lhs, const osg::ref_ptr< osg::StateSet > &rhs) const
Definition: DtCDBStateSetCache.h:110
voidpf void uLong size
Definition: ioapi.h:39
unsigned _attrsIneligible
Definition: DtCDBStateSetCache.h:144
StateAttributeSet _stateAttributeCache
Definition: DtCDBStateSetCache.h:130
bool _protectAfterCache
Definition: DtCDBStateSetCache.h:139
void optimize(osg::Node *node)
Calls consolidateStateAttributes followed by consolidateStateSets.
unsigned _pruneCount
Definition: DtCDBStateSetCache.h:137
bool _traverseProxies
Definition: DtCDBStateSetCache.h:140
StateSetSet _stateSetCache
Definition: DtCDBStateSetCache.h:118
void setOptimizeTextureAttributes(bool optimizeTexAtt)
bool share(osg::ref_ptr< osg::StateSet > &input)
Looks in the cache for a stateset matching the input.
void setTraverseProxies(bool traverseProxies)
unsigned _attrShareAttempts
Definition: DtCDBStateSetCache.h:143
bool operator()(const osg::ref_ptr< osg::StateAttribute > &lhs, const osg::ref_ptr< osg::StateAttribute > &rhs) const
Definition: DtCDBStateSetCache.h:122
std::mutex _mutex
Definition: DtCDBStateSetCache.h:132
void clear()
Clears out the cache.
void setMaxSize(unsigned maxSize)
Caps the size of the cache.
void releaseGLObjects(osg::State *state) const
unsigned _maxSize
Definition: DtCDBStateSetCache.h:136
Custom implementation of osgEarth::StateSetCache as it is not virtually extensible.
Definition: DtCDBStateSetCache.h:23
unsigned _attrShareHits
Definition: DtCDBStateSetCache.h:145
bool _optimizeTextureState
Definition: DtCDBStateSetCache.h:141
void resizeGLObjectBuffers(unsigned size)
void consolidateStateAttributes(osg::Node *node)
Scans a graph and combines equivalents state attributes into single shared attribute.
void protect()
marks all caches statesets as DYNAMIC so they cannot be shared again.
DtCDBStateSetCache()
Constructs a new cache.

Document ID: Generated on Thu Oct 15 21:27:02 EDT 2026 from SVN revision 296421
Copyright © 2005-2026 MAK Technologies. All Rights Reserved (www.mak.com)