HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_DAConstant.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_DAConstant.h ( GT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GT_DAConstant__
12 #define __GT_DAConstant__
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 Extend a single element from a source array to emulate a larger array
21 ///
22 /// Given a source data array, this class will emulate a larger array by
23 /// extending a single element from the source array over a given size.
24 /// For example: @code
25 /// GT_DataArray &src;
26 /// GT_DAConstant varying;
27 /// varying.init(32, 100);
28 /// @endcode
29 /// Creates an array of 100 entries referencing element 32 from the source
30 /// array.
32 {
33 public:
34  /// Default constructor
36  : mySize(0)
37  , myOffset(0)
38  , GT_DAInherit()
39  {
40  }
41  /// Useful constructor
44  : myOffset(offset)
45  , mySize(size)
46  , GT_DAInherit(data)
47  {
48  }
49  /// Copy constructor
51  : myOffset(src.myOffset),
52  mySize(src.mySize),
53  GT_DAInherit(src)
54  {
55  }
56  ~GT_DAConstant() override;
57 
58  const char *className() const override { return "GT_DAConstant"; }
59 
60  GT_Size itemSize(GT_Offset) const override
61  { return GT_DAInherit::itemSize(myOffset); }
62  GT_Size getTotalArrayEntries() const override
63  { return mySize * itemSize(myOffset); }
64 
65  /// Create a constant data array from the existing data array.
66  static const GT_DataArrayHandle createConstant(
67  const GT_DataArrayHandle &h,
69  GT_Size size);
70 
71  /// Initialize with given data
74  {
75  GT_DAInherit::init(data);
76  myOffset = offset;
77  mySize = size;
78  }
79 
80  GT_IMPL_INHERIT_ARRAY(getIndirect, mySize)
81 
82 private:
83  /// Map the requested offset to the offset in my data
84  inline GT_Offset getIndirect(GT_Offset) const
85  { return myOffset; }
86 
87  GT_Offset myOffset;
88  GT_Size mySize;
89 };
90 
91 #endif
GT_Size itemSize(GT_Offset offset) const override
Definition: GT_DAInherit.h:53
const char * className() const override
Definition: GT_DAConstant.h:58
Extend a single element from a source array to emulate a larger array.
Definition: GT_DAConstant.h:31
#define GT_API
Definition: GT_API.h:13
GT_Size getTotalArrayEntries() const override
Definition: GT_DAConstant.h:62
GT_DAConstant(const GT_DAConstant &src)
Copy constructor.
Definition: GT_DAConstant.h:50
GLintptr offset
Definition: glcorearb.h:665
void init(const GT_DataArrayHandle &data, GT_Offset offset, GT_Size size)
Initialize with given data.
Definition: GT_DAConstant.h:72
int64 GT_Offset
Definition: GT_Types.h:129
GT_DAConstant(const GT_DataArrayHandle &data, GT_Offset offset, GT_Size size)
Useful constructor.
Definition: GT_DAConstant.h:42
int64 GT_Size
Definition: GT_Types.h:128
GLsizeiptr size
Definition: glcorearb.h:664
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
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:84
GT_Size itemSize(GT_Offset) const override
Return the number of elements in the array for the given item.
Definition: GT_DAConstant.h:60
void init(const GT_DataArrayHandle &data)
Definition: GT_DAInherit.h:33
GT_DAConstant()
Default constructor.
Definition: GT_DAConstant.h:35
Definition: format.h:1821
GLenum src
Definition: glcorearb.h:1793