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 isDisplayOpacity() const;
67  bool isNormal() const;
68  bool isP() const;
69 
70  void dump() const;
71  void dump(UT_JSONWriter &w) const;
72 
78  bool myIsArray;
79  };
80 
82  BRAY_AttribList(const Attrib *list, uint list_size, bool volume);
83  ~BRAY_AttribList();
84 
85  /// Look up a list of attributes in a shared table. If different
86  /// BRAY_Objects share the same attribute list, then it's possible they will
87  /// be shaded in batch. Using the shared table can improve rendering
88  /// performance.
89  static const BRAY_AttribList *findList(const Attrib *list,
90  int list_size,
91  bool for_volume);
92  static const BRAY_AttribList *findList(const BRAY_AttribList &src);
93 
94  void setCapacity(int n);
95  int addAttribute(const UT_StringHolder &name,
96  int tuple_size,
97  AttributeOwner owner,
99  bool isarray);
100 
101  template <int TSIZE=-1>
102  int getIndex(const UT_StringRef &name) const
103  {
104  for (int i = 0, n = myList.size(); i < n; ++i)
105  if (myList[i].name() == name &&
106  (TSIZE < 0 || TSIZE == myList[i].tupleSize()))
107  {
108  return i;
109  }
110  return -1;
111  }
112 
113  int size() const { return myList.size(); }
114  bool forVolume() const { return myForVolume; }
115  GA_Storage storage(int i) const { return myList[i].myStorage; }
116  int tupleSize(int i) const { return myList[i].myTupleSize; }
117  AttributeOwner owner(int i) const { return myList[i].myOwner; }
118  GA_StorageClass storageClass(int i) const { return myList[i].storageClass(); }
119  bool isArray(int i) const { return myList[i].myIsArray; }
120  const UT_StringHolder &name(int i) const { return myList[i].myName; }
121  const Attrib &attrib(int i) const { return myList[i]; }
122  const Attrib &operator[](int i) const { return myList[i]; }
123  bool isNormal(int i) const { return i == myNormal; }
124  bool isP(int i) const { return i == myP; }
125 
126  int displayColor() const { return myDisplayColor; }
127  int displayOpacity() const { return myDisplayOpacity; }
128  int normal() const { return myNormal; }
129  int getP() const { return myP; }
130 
131  bool isDicedNormal() const
132  {
133  return myNormal >= 0
134  && owner(myNormal) == ATTRIB_DICED_POINT;
135  }
136 
137  void dump() const;
138  void dump(UT_JSONWriter &w) const;
139 
140 private:
141  UT_Array<Attrib> myList;
142  int myP;
143  int myDisplayColor;
144  int myDisplayOpacity;
145  int myNormal;
146  bool myForVolume;
147 };
148 
149 #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:73
getFileOption("OpenEXR:storage") storage
Definition: HDK_Image.dox:276
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:37
GA_StorageClass storageClass() const
const Attrib & attrib(int i) const
bool isNormal(int i) const
GLdouble n
Definition: glcorearb.h:2008
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)
GLuint const GLchar * name
Definition: glcorearb.h:786
GA_Storage storage() const
GA_Storage storage(int i) const
int normal() const
int displayOpacity() const
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
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
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:51
GLenum src
Definition: glcorearb.h:1793