HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RAY_PackedQuery.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: RAY_PackedQuery.h (RAY Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __RAY_PackedQuery__
12 #define __RAY_PackedQuery__
13 
14 #include "RAY_API.h"
15 #include <UT/UT_StringHolder.h>
16 #include <GT/GT_Handles.h>
17 
18 class GEO_Primitive;
19 class RAY_Procedural;
20 class VPRM_Data;
21 
22 /// When a new procedural is created from a packed primitive, the geometry
23 /// generated by the procedural should be able to access the attributes from
24 /// the packed primitive using the @c renderstate("packed:NAME") method.
25 ///
26 /// This class is used to implement the packed query for a procedural. Once
27 /// you create a @c RAY_PackedQuery, you can assign it to the procedural using
28 /// @c RAY_Procedural::setPackedQuery().
30 {
31 public:
32  using KeyType = int64;
33 
34  SYS_FORCE_INLINE static bool isValidKey(KeyType k) { return k != 0; }
35 
36  /// Create a packed query for the procedural, possibly inheriting from
38  : myInheritFrom()
39  {
40  }
41  virtual ~RAY_PackedQuery();
42 
43  /// Create a query struct for a primitive.
44  static RAY_PackedQuery *create(const GEO_Primitive *prim);
45  /// Create a query struct for a set of GT attributes. The inherit_from
46  /// should either be the current query id or a -1.
47  static RAY_PackedQuery *create(const GT_AttributeListHandle &detail,
48  const GT_AttributeListHandle &uniform,
49  exint uniform_index,
50  const GT_AttributeListHandle &primdet,
51  const GT_AttributeListHandle &packinfo);
52 
53  /// Try to import the packed setting of the given name (the "packed:" prefix
54  /// is stripped off). For example, "Cd" (not "packed:Cd")
55  /// This can be specialized for @code
56  /// T in {int32, int64, fpreal32, fpreal64, UT_StringHolder }
57  /// @endcode
58  template <typename T>
59  bool import(const UT_StringRef &name, T *val, int size) const
60  {
61  if (doImport(name, val, size))
62  return true;
63  const RAY_PackedQuery *parent = find(myInheritFrom);
64  return parent ? parent->import(name, val, size) : false;
65  }
66 
67  /// Set the inheritance for the query. If settings aren't found on this
68  /// query, we search the parent (if there is one).
69  void setInheritFrom(const KeyType parent) { myInheritFrom = parent; }
70 
71 protected:
72  /// @{
73  /// Import data from the packed primitive
74  virtual bool doImport(const UT_StringRef &name,
75  int32 *val, int n) const = 0;
76  virtual bool doImport(const UT_StringRef &name,
77  int64 *val, int n) const = 0;
78  virtual bool doImport(const UT_StringRef &name,
79  fpreal32 *val, int n) const = 0;
80  virtual bool doImport(const UT_StringRef &name,
81  fpreal64 *val, int n) const = 0;
82  virtual bool doImport(const UT_StringRef &name,
83  UT_StringHolder *val, int n) const = 0;
84  /// @}
85 private:
86  const RAY_PackedQuery *find(KeyType id) const;
87 
88  KeyType myInheritFrom;
89 };
90 
91 #endif
int int32
Definition: SYS_Types.h:39
RAY_PackedQuery()
Create a packed query for the procedural, possibly inheriting from.
static SYS_FORCE_INLINE bool isValidKey(KeyType k)
int64 exint
Definition: SYS_Types.h:125
Procedural primitive for mantra (RAY)
float fpreal32
Definition: SYS_Types.h:200
double fpreal64
Definition: SYS_Types.h:201
GLdouble n
Definition: glcorearb.h:2008
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
long long int64
Definition: SYS_Types.h:116
GLuint const GLchar * name
Definition: glcorearb.h:786
GLsizeiptr size
Definition: glcorearb.h:664
#define RAY_API
Definition: RAY_API.h:12
bool import(const UT_StringRef &name, T *val, int size) const
GLuint GLfloat * val
Definition: glcorearb.h:1608
void setInheritFrom(const KeyType parent)
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool
Definition: core.h:2089