HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GA_PrimitiveTracker.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: GA_PrimitiveTracker.h ( GA Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GA_PrimitiveTracker__
12 #define __GA_PrimitiveTracker__
13 
14 #include "GA_API.h"
15 #include "GA_PrimitiveTypeId.h"
16 #include "GA_Types.h"
17 #include <UT/UT_Assert.h>
18 
20 
21 /// Class which keeps counts of each type of primitive
23 {
24 public:
27  : myCounts(nullptr)
28  , myEntries(0)
29  {}
32  {
33  clear();
34  }
35 
37  void add(int id)
38  {
39  if (id >= myEntries)
40  grow(id+1);
41  myCounts[id]++;
42  }
43  void add(const GA_PrimitiveTracker &that)
44  {
45  if (that.myEntries > myEntries)
46  grow(that.myEntries);
47  for (int id = 0; id < that.myEntries; ++id)
48  myCounts[id] += that.myCounts[id];
49  }
51  void addMultiple(int id, GA_Size n)
52  {
53  if (id >= myEntries)
54  grow(id+1);
55  myCounts[id] += n;
56  }
57  /// this += (changed - orig)
58  /// This is so that items can be added or removed in separate trackers in
59  /// parallel, and then the changes can be merged back into the original.
60  void applyDiff(const GA_PrimitiveTracker &orig, const GA_PrimitiveTracker &changed)
61  {
62  int maxentries = SYSmax(orig.myEntries, changed.myEntries);
63  if (maxentries > myEntries)
64  grow(maxentries);
65  for (int id = 0; id < maxentries; ++id)
66  myCounts[id] += ((id < changed.myEntries) ? changed.myCounts[id] : 0)
67  - ((id < orig.myEntries) ? orig.myCounts[id] : 0);
68  }
70  void del(int id)
71  {
72  UT_ASSERT_P(id < myEntries);
73  myCounts[id]--;
74  UT_ASSERT_P(myCounts[id] >= 0);
75  }
76  void clear()
77  {
78  if (myEntries)
79  grow(0);
80  }
81  bool contains(const GA_PrimitiveTypeId &type) const
82  {
83  int id = type.get();
84  return id >= myEntries ? false : myCounts[id] > 0;
85  }
86  bool containsOnly(const UT_Array<GA_PrimitiveTypeId> &allowed) const
87  {
88  for (int id = 0; id < myEntries; id++)
89  {
90  if (!myCounts[id])
91  continue;
92 
93  // See if we are in the allowed list.
94  bool matched = false;
95  for (auto && allow : allowed)
96  {
97  if (allow.get() == id)
98  {
99  matched = true;
100  break;
101  }
102  }
103  if (!matched)
104  return false;
105  }
106  return true;
107  }
109  {
110  int id = type.get();
111  return id >= myEntries ? 0 : myCounts[id];
112  }
113 
115  {
116  if (myEntries != that.myEntries)
117  {
118  grow(that.myEntries);
119  }
120  for (int i = 0, n = myEntries; i < n; ++i)
121  {
122  myCounts[i] = that.myCounts[i];
123  }
124  return *this;
125  }
126 
127  /// Check to see if there are any primitives which have hasLocalTransform()
128  bool hasLocalTransform(const GA_PrimitiveFactory &f) const;
129 
130  /// Check to see if there are any primitives that may need to flush
131  /// CE buffesr.
132  bool hasCECaches(const GA_PrimitiveFactory &f) const;
133 
134  /// Extract the counts for each primitive type into an array. The array
135  /// should be large enough to hold gdp.getPrimitiveFactory().getTypeCount().
136  /// The method returns the sum of all the primitive in the list
137  GA_Size fillCounts(GA_Size *counts, GA_Size array_size) const;
138 
139  int64 getMemoryUsage(bool inclusive) const
140  {
141  int64 mem = inclusive ? sizeof(*this) : 0;
142  if (myEntries)
143  mem += myEntries * sizeof(myCounts[0]);
144  return mem;
145  }
146 
147 private:
148  void grow(int size);
149 
150  GA_Size *myCounts;
151  int myEntries;
152 };
153 
154 #endif
SYS_FORCE_INLINE ~GA_PrimitiveTracker()
#define SYSmax(a, b)
Definition: SYS_Math.h:1365
void add(const GA_PrimitiveTracker &that)
SYS_FORCE_INLINE GA_PrimitiveTracker()
#define GA_API
Definition: GA_API.h:12
GA_Size count(const GA_PrimitiveTypeId &type) const
SYS_FORCE_INLINE void add(int id)
png_uint_32 i
Definition: png.h:2877
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:211
GLsizeiptr size
Definition: glcorearb.h:663
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:101
GLuint id
Definition: glcorearb.h:654
long long int64
Definition: SYS_Types.h:106
GLdouble n
Definition: glcorearb.h:2007
GLfloat f
Definition: glcorearb.h:1925
Class which keeps counts of each type of primitive.
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
SYS_FORCE_INLINE void addMultiple(int id, GA_Size n)
SYS_FORCE_INLINE void del(int id)
SYS_FORCE_INLINE int get() const
bool contains(const GA_PrimitiveTypeId &type) const
GA_PrimitiveTracker & operator=(const GA_PrimitiveTracker &that)
void applyDiff(const GA_PrimitiveTracker &orig, const GA_PrimitiveTracker &changed)
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
bool containsOnly(const UT_Array< GA_PrimitiveTypeId > &allowed) const
int64 getMemoryUsage(bool inclusive) const