HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BRAY_AttribList.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: BRAY_AttribList.h (RAY Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __BRAY_AttribList__
12 #define __BRAY_AttribList__
13 
14 #include "BRAY_API.h"
15 #include <UT/UT_Array.h>
16 #include <UT/UT_StringHolder.h>
17 #include <UT/UT_NonCopyable.h>
18 #include <UT/UT_IntrusivePtr.h>
19 #include <GA/GA_Types.h>
20 
21 class UT_JSONWriter;
22 
23 /// Each BRAY_Object can define a list of attributes that it can evaluate.
26 {
27 public:
29  {
30  ATTRIB_INVALID = -1,
31 
32  ATTRIB_VERTEX = GA_ATTRIB_VERTEX,
33  ATTRIB_POINT = GA_ATTRIB_POINT,
34  ATTRIB_UNIFORM = GA_ATTRIB_PRIMITIVE,
35  ATTRIB_CONSTANT = GA_ATTRIB_DETAIL,
38 
39  MAX_ATTRIB_TYPE
40  };
41  static const char *owner(AttributeOwner); // Return a label
42 
44  {
45  Attrib() = delete;
47  int tuple_size,
48  AttributeOwner owner,
49  GA_Storage store,
50  bool is_array)
51  : myName(name)
52  , myTupleSize(tuple_size)
53  , myOwner(owner)
54  , myStorage(store)
55  , myStorageClass(GAstorageClass(store))
56  , myIsArray(is_array)
57  {
58  }
59  const UT_StringHolder &name() const { return myName; }
60  int tupleSize() const { return myTupleSize; }
61  AttributeOwner owner() const { return myOwner; }
62  GA_Storage storage() const { return myStorage; }
63  GA_StorageClass storageClass() const { return myStorageClass; }
64  bool isArray() const { return myIsArray; }
65  bool isDisplayColor() const;
66  bool isNormal() const;
67  bool isP() const;
68 
69  void dump() const;
70  void dump(UT_JSONWriter &w) const;
71 
77  bool myIsArray;
78  };
79 
81  BRAY_AttribList(const Attrib *list, uint list_size, bool volume);
82  ~BRAY_AttribList();
83 
84  /// Look up a list of attributes in a shared table. If different
85  /// BRAY_Objects share the same attribute list, then it's possible they will
86  /// be shaded in batch. Using the shared table can improve rendering
87  /// performance.
88  static const BRAY_AttribList *findList(const Attrib *list,
89  int list_size,
90  bool for_volume);
91  static const BRAY_AttribList *findList(const BRAY_AttribList &src);
92 
93  void setCapacity(int n);
94  int addAttribute(const UT_StringHolder &name,
95  int tuple_size,
96  AttributeOwner owner,
98  bool isarray);
99 
100  template <int TSIZE=-1>
101  int getIndex(const UT_StringRef &name) const
102  {
103  for (int i = 0, n = myList.size(); i < n; ++i)
104  if (myList[i].name() == name &&
105  (TSIZE < 0 || TSIZE == myList[i].tupleSize()))
106  {
107  return i;
108  }
109  return -1;
110  }
111 
112  int size() const { return myList.size(); }
113  bool forVolume() const { return myForVolume; }
114  GA_Storage storage(int i) const { return myList[i].myStorage; }
115  int tupleSize(int i) const { return myList[i].myTupleSize; }
116  AttributeOwner owner(int i) const { return myList[i].myOwner; }
117  GA_StorageClass storageClass(int i) const { return myList[i].storageClass(); }
118  bool isArray(int i) const { return myList[i].myIsArray; }
119  const UT_StringHolder &name(int i) const { return myList[i].myName; }
120  const Attrib &attrib(int i) const { return myList[i]; }
121  const Attrib &operator[](int i) const { return myList[i]; }
122  bool isNormal(int i) const { return i == myNormal; }
123  bool isP(int i) const { return i == myP; }
124 
125  int displayColor() const { return myDisplayColor; }
126  int normal() const { return myNormal; }
127  int getP() const { return myP; }
128 
129  bool isDicedNormal() const
130  {
131  return myNormal >= 0
132  && owner(myNormal) == ATTRIB_DICED_POINT;
133  }
134 
135  void dump() const;
136  void dump(UT_JSONWriter &w) const;
137 
138 private:
139  UT_Array<Attrib> myList;
140  int myP;
141  int myDisplayColor;
142  int myNormal;
143  bool myForVolume;
144 };
145 
146 #endif
GA_API const char * GAstorageClass(GA_StorageClass store)
Lookup the storage name from the storage type.
bool isDicedNormal() const
GA_StorageClass
Definition: GA_Types.h:71
GA_StorageClass storageClass(int i) const
bool isArray(int i) const
int getP() const
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:35
GA_StorageClass storageClass() const
GLuint const GLchar * name
Definition: glcorearb.h:785
GLenum src
Definition: glcorearb.h:1792
const Attrib & attrib(int i) const
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
bool isNormal(int i) const
const Attrib & operator[](int i) const
int size() const
bool forVolume() const
Attrib(const UT_StringHolder &name, int tuple_size, AttributeOwner owner, GA_Storage store, bool is_array)
GA_Storage storage() const
GA_Storage storage(int i) const
int normal() const
GLdouble n
Definition: glcorearb.h:2007
AttributeOwner owner(int i) const
const UT_StringHolder & name(int i) const
GA_StorageClass myStorageClass
Each BRAY_Object can define a list of attributes that it can evaluate.
AttributeOwner owner() const
bool isP(int i) const
int tupleSize(int i) const
UT_StringHolder myName
#define BRAY_API
Definition: BRAY_API.h:12
getOption("OpenEXR.storage") storage
Definition: HDK_Image.dox:276
int getIndex(const UT_StringRef &name) const
int displayColor() const
unsigned int uint
Definition: SYS_Types.h:45
const UT_StringHolder & name() const
GA_Storage
Definition: GA_Types.h:49