HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GA_VertexPool.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_VertexPool.h ( GA Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GA_VertexPool__
12 #define __GA_VertexPool__
13 
14 #include "GA_API.h"
15 #include "GA_Types.h"
16 #include "GA_TempBuffer.h"
17 
18 #define GA_VERTEX_POOL_SIZE 32
19 
20 class GA_Detail;
21 
22 #if defined(GA_STRICT_TYPES)
23  #include <SYS/SYS_TypeDecorate.h>
24  class GA_VertexPoolIndexTag {};
25  typedef GA_OrdinalType<GA_VertexPoolIndexTag, GA_Size> GA_VertexPoolIndex;
27 #else
29 #endif
30 
31 /// @brief Manages allocation/deletion of temporary vertex/points for a detail.
32 ///
33 /// This class stores a list of temporary points and vertices for a detail.
34 /// The class is used by GA_WorkVertexBuffer and is referenced by handle lists.
36 {
37 private:
38  /// Objects are private to the attribute handle lists
39  GA_VertexPool();
40  ~GA_VertexPool();
41 
42  void bindDetail(GA_Detail &gdp);
43  void bindDetail(const GA_Detail &gdp);
44  void unbindDetail();
45 
46  friend class GA_AttributeRefMap;
47  friend class ga_VertexPoolProxy;
49 
50 public:
51  /// Return whether this pool is bound to a detail, and hence available
52  /// for us.
53  bool isBound() const { return myDetail != 0; }
54 
55  /// Return the detail which holds the temporary vertices/points.
56  /// @note This may @b not be the same as the detail passed into the
57  /// constructor.
59  {
60  return *myDetail;
61  }
62 
63  /// If the vertex pool was constructed using a const detail, the pool will
64  /// have made a copy of the detail and this method will return true.
65  bool isDetailCopied() const
66  {
67  return myCopiedDetail;
68  }
69 
70  /// Look up the GA_Offset at the given index
71  GA_Offset getVertex(GA_VertexPoolIndex index) const
72  {
73  return myVertices(index);
74  }
75  GA_Offset getPoint(GA_VertexPoolIndex index) const
76  {
77  return myPoints(index);
78  }
79 
80  /// Number of vertices in the vertex pool
81  GA_Size entries() const { return myVertices.entries(); }
82 
83  /// Reserve memory for the given amount of vertices without changing the
84  /// number of entries. Only has an effect if num_elems > entries().
85  void reserve(GA_Size num_elems);
86 
87  /// Append a single vertex (with an optional point link)
88  /// The method returns the offset in the pool (not the offset in the detail)
89  GA_VertexPoolIndex appendVertex(GA_Offset pt=GA_INVALID_OFFSET);
90 
91  /// Rewire a single vertex to a new point link.
92  void rewireVertexPoint(GA_VertexPoolIndex index,
93  GA_Offset point);
94 
95  /// Append @c nvertex vertices to the pool. The offsets are returned in
96  /// the buffer provided.
97  void appendVertices(GA_VertexPoolIndex *buffer, GA_Size nvertex)
98  {
99  for (GA_Size i = 0; i < nvertex; ++i)
100  buffer[i] = appendVertex();
101  }
102 
103  /// Append a single point
104  /// The method returns the offset in the pool (not the offset in the detail)
105  GA_VertexPoolIndex appendPoint();
106 
107  /// Append @c nvertex vertices to the pool. The offsets are returned in
108  /// the buffer provided.
109  void appendPoints(GA_VertexPoolIndex *buffer, GA_Size nvertex)
110  {
111  for (GA_Size i = 0; i < nvertex; ++i)
112  buffer[i] = appendPoint();
113  }
114 
115 
116  /// Free a vertex. If the index is invalid (i.e. < 0), the free is
117  /// silently skipped.
118  void freeVertex(GA_VertexPoolIndex index);
119 
120  /// Free a list of vertices
121  void freeVertices(const GA_VertexPoolIndex *list, GA_Size nvertex)
122  {
123  for (GA_Size i = 0; i < nvertex; ++i)
124  freeVertex(list[i]);
125  }
126 
127  /// Free a point. If the index is invalid (i.e. < 0), the free is
128  /// silently skipped. Vertices should be free'd before points.
129  void freePoint(GA_VertexPoolIndex index);
130 
131  /// Free a list of points. Vertices should be free'd before points.
132  void freePoints(const GA_VertexPoolIndex *list, GA_Size nvertex)
133  {
134  for (GA_Size i = 0; i < nvertex; ++i)
135  freePoint(list[i]);
136  }
137 
138  const GA_Offset *array() const { return myVertices.data(); }
139  GA_Offset *array() { return myVertices.data(0); }
140 
141 private:
142  void clear();
143  GA_Offset validatePoint(GA_Offset point);
144 
145  GA_Detail *myDetail;
146  GA_TempBuffer<GA_Offset> myVertices;
147  GA_TempBuffer<GA_Offset> myPoints;
148  GA_Size myVCount, myPCount;
149  bool myCopiedDetail;
150 };
151 
152 #endif
GA_Detail & getDetail()
Definition: GA_VertexPool.h:58
void freeVertices(const GA_VertexPoolIndex *list, GA_Size nvertex)
Free a list of vertices.
void freePoints(const GA_VertexPoolIndex *list, GA_Size nvertex)
Free a list of points. Vertices should be free'd before points.
void appendPoints(GA_VertexPoolIndex *buffer, GA_Size nvertex)
Manages allocation/deletion of temporary vertex/points for a detail.
Definition: GA_VertexPool.h:35
#define GA_API
Definition: GA_API.h:12
GA_Size GA_VertexPoolIndex
Definition: GA_VertexPool.h:20
GA_Offset getVertex(GA_VertexPoolIndex index) const
Look up the GA_Offset at the given index.
Definition: GA_VertexPool.h:71
GLuint buffer
Definition: glcorearb.h:659
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
#define GA_INVALID_OFFSET
Definition: GA_Types.h:654
GA_Size entries() const
Number of vertices in the vertex pool.
Definition: GA_VertexPool.h:81
GA_Size GA_Offset
Definition: GA_Types.h:617
const GA_Offset * array() const
#define SYS_DECLARE_IS_POD(T)
Declare a type as POD.
A handle to simplify manipulation of multiple attributes.
bool isDetailCopied() const
Definition: GA_VertexPool.h:65
GA_Offset * array()
GLuint index
Definition: glcorearb.h:785
Container class for all geometry.
Definition: GA_Detail.h:96
void appendVertices(GA_VertexPoolIndex *buffer, GA_Size nvertex)
Definition: GA_VertexPool.h:97
bool isBound() const
Definition: GA_VertexPool.h:53
GA_Offset getPoint(GA_VertexPoolIndex index) const
Definition: GA_VertexPool.h:75