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