HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_DAIndirect.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: GT_DAIndirect.h ( GT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GT_DAIndirect__
12 #define __GT_DAIndirect__
13 
14 #include "GT_API.h"
15 #include "GT_DAInherit.h"
16 
17 #include <UT/UT_ValArray.h>
18 
19 /// @brief An array to handle indirect references (i.e. shared items)
20 ///
21 /// This class takes two GT_DataArrays. The indirect array should be an array
22 /// of integers which are used to perform indirect lookup into the shared data
23 /// array.
24 /// For example: @code
25 /// GT_DataArray VertexList = [ 1, 4, 2, 3 ]
26 /// GT_DataArray &PointAttributes;
27 /// GT_DAIndirect attribs(VertexList, PointAttributes);
28 /// @endcode
29 /// This allows the point attributes to be referenced by vertex number.
31 {
32 public:
33  /// Default constructor
35  : myIndirect()
36  , GT_DAInherit()
37  { }
38  /// Convenience constructor
40  const GT_DataArrayHandle &data,
41  bool flatten_nested = false)
42  : myIndirect()
43  , GT_DAInherit()
44  {
45  init(indirect, data, flatten_nested);
46  }
47  /// Copy constructor
49  : myIndirect()
50  , GT_DAInherit()
51  {
52  init(src.myIndirect, src.myData, true);
53  }
54  /// Destructor
55  ~GT_DAIndirect() override;
56 
57  const char *className() const override { return "GT_DAIndirect"; }
58 
59  bool isValid() const override
60  { return myIndirect && myData &&
61  myIndirect->isValid() && myData->isValid(); }
62  void updateGeoDetail(const GU_ConstDetailHandle &dtl,
63  const char *attrib_name,
64  GT_Owner attrib_owner,
65  const int expected_size) override;
66 
67  /// Initialize data from an indirect array of indices and a data array
68  void init(const GT_DataArrayHandle &indirect,
69  const GT_DataArrayHandle &data,
70  bool flatten_nested);
71 
72  const GT_DataArrayHandle &getIndirect() const { return myIndirect; }
73  int64 getDataId() const override;
74 
75  GT_Size itemSize(GT_Offset offset) const override
76  { return myData->itemSize(myIndirect->getI64(offset)); }
77  GT_Size getTotalArrayEntries() const override
78  {
79  GT_Size sum = 0;
80  for (GT_Size off = 0; off < myIndirect->entries(); ++off)
81  sum += myData->itemSize(myIndirect->getI64(off));
82  return sum;
83  }
84 
85  static int getUnmapThreshold();
86 
87  GT_IMPL_INHERIT_ARRAY(getIndirect, myIndirect->entries())
88 
89 private:
90  /// Map the requested offset to the offset in my data
91  inline GT_Offset getIndirect(GT_Offset offset) const
92  { return myIndirect->getI64(offset); }
93 
94  GT_DataArrayHandle myIndirect;
95 };
96 
97 #endif
98 
GT_DAIndirect(const GT_DAIndirect &src)
Copy constructor.
Definition: GT_DAIndirect.h:48
const void * indirect
Definition: glcorearb.h:1795
GT_DataArrayHandle myData
Definition: GT_DAInherit.h:172
#define GT_API
Definition: GT_API.h:11
GLenum src
Definition: glcorearb.h:1793
GT_DAIndirect()
Default constructor.
Definition: GT_DAIndirect.h:34
An array to handle indirect references (i.e. shared items)
Definition: GT_DAIndirect.h:30
GT_Size itemSize(GT_Offset offset) const override
Return the number of elements in the array for the given item.
Definition: GT_DAIndirect.h:75
int64 getDataId() const override
Definition: GT_DAInherit.h:64
int64 GT_Offset
Definition: GT_Types.h:124
long long int64
Definition: SYS_Types.h:116
void updateGeoDetail(const GU_ConstDetailHandle &dtl, const char *attrib_name, GT_Owner attrib_owner, const int expected_size) override
Definition: GT_DAInherit.h:65
GT_DAIndirect(const GT_DataArrayHandle &indirect, const GT_DataArrayHandle &data, bool flatten_nested=false)
Convenience constructor.
Definition: GT_DAIndirect.h:39
GT_Owner
Definition: GT_Types.h:86
int64 GT_Size
Definition: GT_Types.h:123
GT_Size getTotalArrayEntries() const override
Definition: GT_DAIndirect.h:77
Base class for a data array which references another data array.
Definition: GT_DAInherit.h:18
#define GT_IMPL_INHERIT_ARRAY(MAP_INDEX, SIZE)
Definition: GT_DAInherit.h:83
void init(const GT_DataArrayHandle &data)
Definition: GT_DAInherit.h:32
const char * className() const override
Definition: GT_DAIndirect.h:57
GLintptr offset
Definition: glcorearb.h:665
const GT_DataArrayHandle & getIndirect() const
Definition: GT_DAIndirect.h:72
bool isValid() const override
Data array is valid; can be sampled from.
Definition: GT_DAIndirect.h:59
Definition: format.h:895