HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BRAY_Interface.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_Interface.h (BRAY Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __BRAY_Interface__
12 #define __BRAY_Interface__
13 
14 #include "BRAY_API.h"
15 #include <UT/UT_Array.h>
16 #include <UT/UT_StringHolder.h>
17 #include <UT/UT_StringArray.h>
18 #include <UT/UT_NonCopyable.h>
19 #include <UT/UT_Options.h>
20 #include <UT/UT_SharedPtr.h>
21 #include <UT/UT_IntrusivePtr.h>
22 #include <UT/UT_UniquePtr.h>
23 #include <UT/UT_Rect.h>
24 #include <UT/UT_VectorTypes.h>
25 #include <GT/GT_Handles.h>
26 #include <GT/GT_DataArray.h>
27 #include <PXL/PXL_Common.h>
28 #include "BRAY_Types.h"
29 
30 // Classes referenced by the interface
31 class BRAY_Procedural;
33 class BRAY_AOVBuffer;
34 class BRAY_Camera;
35 class BRAY_Object;
36 class BRAY_Renderer;
37 class BRAY_Light;
38 class BRAY_Scene;
39 class BRAY_ShaderGraph;
40 class BRAY_ShaderInstance;
41 class BRAY_VexMaterial;
42 class VPRM_Space;
43 class VPRM_OptionSet;
44 class UT_JSONWriter;
45 
48 
49 namespace BRAY
50 {
51 
52 class CameraPtr;
53 class LightPtr;
54 class MaterialPtr;
55 class ObjectPtr;
56 class ScenePtr;
57 class ShaderGraphPtr;
58 
60 {
61 public:
62  SpacePtr();
63  SpacePtr(const VPRM_SpacePtr &s);
64  SpacePtr(const SpacePtr &s);
65  SpacePtr(const UT_Matrix4D &xforms);
66  SpacePtr(const UT_Matrix4D *xforms, size_t num_motion_segments);
67  ~SpacePtr();
68  SpacePtr &operator=(const SpacePtr &s);
69 
70  /// @{
71  /// Private access
72  bool isValid() const { return mySpace.get() != nullptr; }
73  VPRM_SpacePtr &space() { return mySpace; }
74  const VPRM_SpacePtr &space() const { return mySpace; }
75  /// @}
76  /// Bool operator to test validity of pointer
77  SYS_SAFE_BOOL operator bool() const { return isValid(); }
78 
79  /// Multiply by the given space (i.e. this * sp)
80  SpacePtr mulSpace(const SpacePtr &sp) const;
81 
82  /// Return the number of motion segments
83  int motionSegments() const;
84  const UT_Matrix4D &getTransform(int segment) const;
85  void getTransform(UT_Matrix4D &x, BRAYtime shutter) const;
86  void dump() const;
87  void dump(UT_JSONWriter &w) const;
88 private:
89  VPRM_SpacePtr mySpace;
90 };
91 
92 /// The OptionSet acts as a pointer to an underlying set of options for various
93 /// different object types.
95 {
96 public:
97  OptionSet();
98  /// The copy c-tor will copy the underlying pointer, but refer to the same
99  /// underlying object.
100  OptionSet(const OptionSet &src);
101  OptionSet(const VPRM_OptionSetPtr &o);
102  ~OptionSet();
103 
104  /// The assignment operator will change the pointer to the underlying
105  /// object. Both OptionSets will point to the same underlying object.
106  OptionSet &operator=(const OptionSet &o);
107 
108  /// This will create a new OptionSet, inheriting state information from the
109  /// this option set. Note that changing values in the this set @b may
110  /// result in unexpected changes in the new option set.
111  OptionSet duplicate() const;
112 
113  /// @{
114  /// Private access
115  bool isValid() const { return myOptions.get() != nullptr; }
116  VPRM_OptionSetPtr &options() { return myOptions; }
117  const VPRM_OptionSetPtr &options() const { return myOptions; }
118  /// @}
119  /// Bool operator to test validity of pointer
120  SYS_SAFE_BOOL operator bool() const { return isValid(); }
121 
122  /// Return the name associated with a given option (i.e. dicingquality)
123  const UT_StringHolder &name(int token) const;
124 
125  /// Return the fully qualified name (i.e. karma::object::dicingquality)
126  UT_StringHolder fullName(int token) const;
127 
128  /// Return the token associated with a given name (or -1 if invalid)
129  int find(const UT_StringRef &name) const;
130 
131  /// Import a property value. Method is specialized for T in:
132  /// - bool
133  /// - int32/int64
134  /// - fpreal32/fpreal64
135  /// - UT_StringHolder
136  template <typename T>
137  const T *import(int token, T *val, size_t n) const;
138 
139  /// Interface to set an property. This template class is specialized for:
140  /// - bool
141  /// - int32
142  /// - int64
143  /// - fpreal32
144  /// - fpreal64
145  /// - UT_StringHolder
146  template <typename T>
147  bool set(int token, const T *value, exint tuple_size);
148 
149  /// Simple interface to set a scalar property
150  template <typename T>
151  SYS_FORCE_INLINE bool set(int token, const T &value)
152  {
153  return set(token, &value, 1);
154  }
155 
156  /// Test whether a value is the same as the current property
157  template <typename T>
158  bool isEqual(int token, const T *value, exint tuple_size) const;
159 
160  /// Simple interface for equality of a scalar value.
161  template <typename T>
162  SYS_FORCE_INLINE bool isEqual(int token, const T &value) const
163  {
164  return isEqual(token, &value, 1);
165  }
166 
167  /// Test whether an option has variadic arguments
168  bool isVariadic(int token) const;
169 
170  /// Return the size of an option. This can be used for variadics
171  exint size(int token) const;
172 
173  /// Return the storage of an option. This will only be one of:
174  /// - GT_STORE_INVALID
175  /// - GT_STORE_UINT8 (for bool storage)
176  /// - GT_STORE_INT64
177  /// - GT_STORE_REAL64
178  /// - GT_STORE_STRING
179  GT_Storage storage(int token) const;
180 
181  /// @{
182  /// Direct access to internal option data. There are no checks on these
183  /// methods
184  const bool *bval(int token) const;
185  const int64 *ival(int token) const;
186  const fpreal64 *fval(int token) const;
187  const UT_StringHolder *sval(int token) const;
188  /// @}
189 
190  /// @private Debug the options (only available in debug builds)
191  void dump(UT_JSONWriter &w) const;
192 
193 private:
194  VPRM_OptionSetPtr myOptions;
195 };
196 
197 /// When defining materials for face sets, the material specification is
198 /// given by a pair of the @c MaterialPtr and an array of integers. The
199 /// integers specify the list of faces to material and must appear in
200 /// sorted order (smallest to largest).
201 /// Interface to the scene manager
203 {
204 public:
205  ScenePtr() = default;
206  ~ScenePtr();
207 
208  /// Allocate a new scene
209  static ScenePtr allocScene();
210 
211  /// Test validity
212  bool isValid() const { return myScene.get() != nullptr; }
213 
214  /// Test whether the scene is thread-safe
215  bool threadSafe() const;
216 
217  /// Test whether the renderer supports nested instancing
218  bool nestedInstancing() const;
219 
220  /// Update an object in the scene
221  void updateObject(const ObjectPtr &ptr, BRAY_EventType event);
222 
223  /// Update light object in the scene
224  void updateLight(const LightPtr &ptr, BRAY_EventType event);
225 
226  /// Update camera object in the scene
227  void updateCamera(const CameraPtr &ptr, BRAY_EventType event);
228 
229  /// Update material object in the scene
230  void updateMaterial(const MaterialPtr &ptr, BRAY_EventType event);
231 
232  /// @{
233  /// Set the unit scale for the scene - this is in meters/unit. For
234  /// example, centimeters would be 0.01.
235  void setSceneUnits(fpreal64 units);
236  fpreal64 sceneUnits() const;
237  /// @}
238 
239  /// Set camera ray visibility. The mask should be a combination of
240  /// - BRAY_RAY_CAMERA
241  /// - BRAY_PROXY_CAMERA
242  /// - BRAY_GUIDE_CAMERA
243  /// For example, (BRAY_RAY_CAMERA|BRAY_GUIDE_CAMERA) will cause guide and
244  /// renderable object to be visible to camera rays, but not proxy objects
245  void setCameraRayMask(BRAY_RayVisibility mask);
246 
247  /// Set shadow ray visibility. The mask should be a combination of
248  /// - BRAY_RAY_SHADOW
249  /// - BRAY_PROXY_SHADOW
250  /// - BRAY_GUIDE_SHADOW
251  /// For example, (BRAY_RAY_SHADOW|BRAY_PROXY_SHADOW) will cause proxy and
252  /// renderable object to cast shadows, but not GUIDE objects.
253  void setShadowRayMask(BRAY_RayVisibility mask);
254 
255  /// Force redicing of displacement and subd surfaces on the next render.
256  /// This will only take effect on the next call to beginRender().
257  void forceRedice();
258 
259  /// @{
260  /// Private access to the underling scene
261  SYS_SAFE_BOOL operator bool() const { return isValid(); }
262  const BRAY_Scene *scenePtr() const { return myScene.get(); }
263  BRAY_Scene *scenePtr() { return myScene.get(); }
264  /// @}
265 
266  /// After changing any options, must commit prior to rendering
267  void commitOptions();
268 
269  /// Grab a copy of the current scene options
270  OptionSet sceneOptions() const;
271 
272  /// Grab a copy of the current object properties.
273  OptionSet objectProperties() const;
274 
275  /// Grab a copy of the current light properties
276  OptionSet lightProperties() const;
277 
278  /// Grab a copy of the current camera properties
279  OptionSet cameraProperties() const;
280 
281  /// Grab a copy of the current image plane properties
282  OptionSet planeProperties() const;
283 
284  /// Grab a the default properties for a given type. Changing their values
285  /// will cause all future objects created to inherit the new values.
286  OptionSet defaultProperties(BRAY_PropertyType type) const;
287 
288  /// @{
289  /// Convenience methods to look up scene and scene options.
290  /// Get an scene option value.
291  template <typename T>
293  T *val, size_t n) const
294  {
295  return sceneOptions().import(token, val, n);
296  }
297 
298  /// Interface to set an option. This template class is specialized for:
299  template <typename T>
301  const T *value,
302  exint tuple_size)
303  {
304  return sceneOptions().set(token, value, tuple_size);
305  }
306 
307  /// Simple interface to set a scalar option
308  template <typename T>
309  SYS_FORCE_INLINE bool
311  {
312  return setOption(token, &value, 1);
313  }
314 
315  /// Return the size of an option. This can be used for variadics
316  /// (e.g. shading quality will be 1)
318  {
319  return sceneOptions().size(token);
320  }
321 
322  /// Return the storage class of an option.
325  {
326  return sceneOptions().storage(token);
327  }
328 
329  /// Return whether an option has variadic arguments
330  SYS_FORCE_INLINE bool
332  {
333  return sceneOptions().isVariadic(token);
334  }
336  { return *sceneOptions().bval(t); }
338  { return *sceneOptions().ival(t); }
340  { return *sceneOptions().fval(t); }
342  { return *sceneOptions().sval(t); }
343  /// @}
344 
345  /// @{
346  /// Convenience methods to look up object properties.
347  /// Get an object property value.
348  template <typename T>
350  T *val, size_t n) const
351  {
352  return objectProperties().import(token, val, n);
353  }
354 
355  /// Interface to set an property. This template class is specialized for:
356  template <typename T>
358  const T *value,
359  exint tuple_size)
360  {
361  return objectProperties().set(token, value, tuple_size);
362  }
363 
364  /// Locking the object property prevents any overriding of the property
365  /// after the fact, essentially turning the property into a read-only
366  /// property. This method is intended to lock default properties. The
367  /// current value of the property is used as the value.
368  ///
369  /// The return value is the previous lock state of the property.
370  bool lockProperty(BRAY_ObjectProperty token, bool state);
371 
372  /// Lock properties based on a string pattern of parameter names. This
373  /// method returns the number of properties modified.
374  exint lockProperties(const char *pattern, bool state);
375 
376  /// Lock or unlock all object properties.
378  { return lockProperties("*", state); }
379 
380  /// Simple interface to set a scalar property
381  template <typename T>
382  SYS_FORCE_INLINE bool
384  {
385  return setProperty(token, &value, 1);
386  }
387 
388  /// Return the size of an option. This can be used for variadics
389  /// (e.g. shading quality will be 1)
391  {
392  return objectProperties().size(token);
393  }
394 
395  /// Return the storage class of an option.
398  {
399  return objectProperties().storage(token);
400  }
401 
402  /// Return whether an property has variadic arguments
403  SYS_FORCE_INLINE bool
405  {
406  return objectProperties().isVariadic(token);
407  }
409  { return *objectProperties().bval(t); }
411  { return *objectProperties().ival(t); }
413  { return *objectProperties().fval(t); }
415  { return *objectProperties().sval(t); }
416  /// @}
417 
418  /// Create a light
419  LightPtr createLight(const UT_StringHolder &name);
420 
421  /// Create a camera
422  CameraPtr createCamera(const UT_StringHolder &name);
423 
424  /// Create a material
425  MaterialPtr createMaterial(const UT_StringHolder &name);
426 
427  /// Find a material.
428  MaterialPtr findMaterial(const UT_StringRef &name) const;
429 
430  /// Add a named transform space (that can be referenced from VEX)
431  /// Returns true if the space was added (false if the space already exists)
432  bool addSpace(const UT_StringHolder &name,
433  const SpacePtr &space,
434  bool replace_existing = true);
435 
436  /// Add traceset name to global list (categories on objects that do not
437  /// belong to this list will be ignored)
438  /// Returns true if added, false if already exists.
439  bool addTraceset(const UT_StringHolder &name);
440 
441  /// Check to see if a traceset exists.
442  bool isTraceset(const UT_StringHolder &name);
443 
444  /// Create a shader nodegraph
445  ShaderGraphPtr createShaderGraph(const UT_StringHolder &name);
446 
447  /// Load an HDA to define shader code. Not all applications support this
448  /// feature.
449  bool loadHDA(const char *path);
450 
451 private:
452  UT_SharedPtr<BRAY_Scene> myScene;
453 };
454 
455 /// Input connector for materials. This defines the name of the geometry
456 /// attribute (@c myInputName) to bind to the VEX shader parameter (@c myParmName)
458 {
459  enum class Storage
460  {
461  FLOAT,
462  INTEGER,
463  STRING
464  };
466  const UT_StringHolder &shader_parm,
467  Storage store,
468  int tsize,
469  bool is_array)
470  : myGeometry(primvar)
471  , myParmName(shader_parm)
472  , myStorage(store)
473  , myTupleSize(tsize)
474  , myIsArray(is_array)
475  {
476  }
477 
478  UT_StringHolder myGeometry; // Input name (primvar name)
479  UT_StringHolder myParmName; // Parameter Name (VEX parameter name)
480  Storage myStorage; // Base storage type
481  int myTupleSize; // Element tuple size
482  bool myIsArray; // Whether parameter is an array
483 };
484 
486 
487 /// Interface to scene materials
489 {
490 public:
491  MaterialPtr(BRAY_VexMaterial *mat = nullptr)
492  : myMat(mat)
493  {
494  }
496 
497  bool isValid() const { return myMat != nullptr; }
498 
499  /// @{
500  /// Access to the underling material
501  SYS_SAFE_BOOL operator bool() const { return isValid(); }
502  const BRAY_VexMaterial *materialPtr() const { return myMat; }
503  /// @}
504 
505  /// Update the surface shader and arguments
506  void updateSurface(const ScenePtr &scene,
507  const UT_StringArray &arguments);
508  /// Update the displacement shader and arguments
509  /// Returns true if arguments changed.
510  bool updateDisplace(const ScenePtr &scene,
511  const UT_StringArray &arguments);
512 
513  /// Update surface shader VEX code. The @c preload flag is used when other
514  /// shaders in the network might depend on the code being updated.
515  void updateSurfaceCode(const ScenePtr &scene,
516  const UT_StringHolder &name,
517  const UT_StringRef &code,
518  bool preload=false);
519  /// Update displacement shader VEX code The @c preload flag is used when
520  /// other shaders in the network might depend on the code being updated.
521  /// Returns true if the name or the code changed.
522  bool updateDisplaceCode(const ScenePtr &scene,
523  const UT_StringHolder &name,
524  const UT_StringRef &code,
525  bool preload=false);
526 
527  /// Update the surface shader graph
528  void updateSurfaceGraph(const ScenePtr &scene,
529  const UT_StringHolder &name,
530  const ShaderGraphPtr &graphptr);
531  /// Update the displacement shader graph
532  /// Returns true if the name or the code changed.
533  bool updateDisplaceGraph(const ScenePtr &scene,
534  const UT_StringHolder &name,
535  const ShaderGraphPtr &graphptr);
536 
537  /// Set the material input list
538  void setInputs(const MaterialInputList &inputs, bool for_surface);
539 
540 private:
541  BRAY_VexMaterial *myMat;
542 };
543 
545 {
547  const MaterialPtr &material = MaterialPtr())
548  : myFaceList(facelist)
549  , myMaterial(material)
550  {
551  }
554 };
555 
557 {
558 public:
559  ObjectPtr() = default;
560  ~ObjectPtr();
561 
562  /// Create an object given a GT_Primitive handle.
563  /// At the current time, the only classes supported are:
564  /// - GT_PrimPolygonMesh
565  /// - GT_PrimSubdivisionMesh
566  /// - GT_PrimCurveMesh
567  /// - GT_PrimPointMesh
568  /// The method will return a nullptr if it can't create a primitive
569  static ObjectPtr createGeometry(const GT_PrimitiveHandle &prim);
570 
571  /// Create a volume given its detail attribute and the names and
572  /// GT_PrimitiveHandles of the corresponding fields in the volume
574  static ObjectPtr createVolume(const UT_StringHolder &name);
575 
576  /// Create an instance of an object
577  static ObjectPtr createInstance(const ObjectPtr &obj,
578  const UT_StringHolder &name);
579 
580  /// Create a nested scene graph
581  static ObjectPtr createScene();
582 
583  /// Create a procedural object.
584  /// Ownership of the procedural is passed to the object.
585  static ObjectPtr createProcedural(UT_UniquePtr<BRAY_Procedural> proc);
586 
587  /// Test validity
588  bool isValid() const { return myObject != nullptr; }
589 
590  /// Query if object is a leaf node (ie not scenegraph or instance)
591  bool isLeaf() const;
592 
593  /// @{
594  /// Access to the underlying object
595  SYS_SAFE_BOOL operator bool() const { return isValid(); }
596  const BRAY_Object *objectPtr() const { return myObject.get(); }
597  BRAY_Object *objectPtr() { return myObject.get(); }
598  /// @}
599 
600  /// Bind a material to the object. The method will fail if the underlying
601  /// object cannot set the material.
602  bool setMaterial(ScenePtr &scene,
603  const MaterialPtr &mat,
604  const OptionSet &opts,
605  exint nfacesets=0,
606  const FacesetMaterial *faceset_mat=nullptr);
607 
608  /// Set the prototype for an instance object
609  void setInstancePrototype(const ObjectPtr &proto);
610 
611  /// Set the transform on the instance
612  void setInstanceTransforms(const UT_Array<SpacePtr> &xforms);
613 
614  /// Set attributes on instances
615  void setInstanceAttributes(const ScenePtr &scene,
616  const GT_AttributeListHandle &alist);
617 
618  /// Set property overrides for instances. The array must have an entry for
619  /// every instance. It's possible to have default options. Each
620  /// attribute's name should match an object property name. Warnings will
621  /// be output if an attribute doesn't match.
622  void setInstanceProperties(const ScenePtr &scene,
623  const GT_AttributeListHandle &alist);
624 
625  /// Set instance IDs. If not set (or given an empty array), it is assumed
626  /// that the ids are contiguous 0...N-1 where N is the number of xforms.
627  void setInstanceIds(UT_Array<exint> ids);
628 
629  /// Add an object to a scene
630  void addInstanceToScene(ObjectPtr &obj);
631 
632  /// Check to make sure that number of xforms, attribute list, ids all match
633  bool validateInstance() const;
634 
635  /// @{
636  /// This will return the object's base properties, or the scene defaults if
637  /// the object isn't defined yet.
638  OptionSet objectProperties(const ScenePtr &scene);
639  const OptionSet objectProperties(const ScenePtr &scene) const;
640  /// @}
641 
642  /// Get the underlying GT_PrimitiveHandle (if possible). This method may
643  /// return a nullptr.
644  GT_PrimitiveHandle geometry() const;
645 
646  /// Pointer to the contained procedural. This may return a nullptr.
647  BRAY_Procedural *procedural();
648 
649  /// Update the geometry for the object. The method will fail if you're
650  /// trying to change the underlying primitive type.
651  bool setGeometry(const GT_PrimitiveHandle &prim);
652 
653  /// Update volume fields. This method will fail if the underlying
654  /// primitive isn't a volume (see createVolume())
655  bool setVolume(const ScenePtr &scene,
656  const GT_AttributeListHandle &clist,
657  const FieldList& fields);
658 
659  /// Return the detail attributes for a volume primitive
660  const GT_AttributeListHandle &volumeDetailAttributes() const;
661 
662  /// TODO: Deprecate this
663  void takeOwnership(BRAY_Object *obj);
664 
665 protected:
667 };
668 
670 {
671 public:
673  : myLight(lp)
674  {
675  }
676  ~LightPtr();
677 
678  /// Test validity
679  bool isValid() const { return myLight != nullptr; }
680 
681  /// @{
682  /// Access to the underlying object
683  SYS_SAFE_BOOL operator bool() const { return isValid(); }
684  const BRAY_Light *lightPtr() const { return myLight.get(); }
685  BRAY_Light *lightPtr() { return myLight.get(); }
686  /// @}
687 
688  /// Return the type of light
689  BRAY_LightType type() const;
690 
691  /// Set the transform on the instance
692  void setTransform(const SpacePtr &xforms);
693 
694  /// Set the shader for the light
695  void setShader(ScenePtr &scene, const UT_StringArray &args);
696 
697  /// Get the current object properties for modification.
698  OptionSet objectProperties();
699 
700  /// Get the current light properties for modification.
701  OptionSet lightProperties();
702 
703  /// After changing any options, must lock prior to rendering
704  void commitOptions(ScenePtr &scene);
705 
706 protected:
708 
709 };
710 
712 {
713 public:
715  : myCamera(cp)
716  {
717  }
718  ~CameraPtr();
719 
720  /// Test validity
721  bool isValid() const { return myCamera != nullptr; }
722 
723  /// @{
724  /// Access to the underlying object
725  SYS_SAFE_BOOL operator bool() const { return isValid(); }
726  const BRAY_Camera *cameraPtr() const { return myCamera.get(); }
727  BRAY_Camera *cameraPtr() { return myCamera.get(); }
728  /// @}
729 
730  /// Set the transform on the instance
731  void setTransform(const SpacePtr &xforms);
732 
733  /// Set the lens shader for the camera
734  void setShader(const ScenePtr &scene, const UT_StringArray &args);
735 
736  /// Get the current object properties for modification.
737  OptionSet objectProperties();
738 
739  /// Set number of motion samples for animated camera properties (1 upon
740  /// construction). The last motion sample is assumed to have time offset of
741  /// 1.0. (eg. if there are 3 samples, the time offsets are: 0, 0.5, 1.0)
742  void resizeCameraProperties(int nseg);
743 
744  /// Get the current camera properties for modification.
745  UT_Array<OptionSet> cameraProperties();
746 
747  /// After changing any options, must lock prior to rendering
748  void commitOptions(ScenePtr &scene);
749 
750 protected:
752 
753 };
754 
756 {
757 public:
758  AOVBufferPtr() = default;
759 
761  : myAOVBuffer(aov)
762  {}
763 
765 
766  bool operator==(const AOVBufferPtr &aov) const
767  { return aov.myAOVBuffer == myAOVBuffer; }
768  bool operator!=(const AOVBufferPtr &aov) const
769  { return !(*this == aov); }
770 
771  const UT_StringHolder &getName() const;
772  const UT_StringHolder &getVariable() const;
773 
774  int getXres() const;
775  int getYres() const;
776  PXL_DataFormat getFormat() const;
777  PXL_Packing getPacking() const;
778 
779  void *map();
780  void unmap();
781  bool isMapped() const;
782 
783  // For extra channels
784  int getNumExtra() const;
785  const UT_StringHolder &nameExtra(int idx) const;
786  PXL_DataFormat getFormatExtra(int idx) const;
787  PXL_Packing getPackingExtra(int idx) const;
788  void *mapExtra(int idx);
789  void unmapExtra(int idx);
790 
791  // metadata to write to header of output file
792  const UT_Options &getMetadata() const;
793 
794  bool isConverged() const;
795  void setConverged();
796  void clearConverged();
797 
798  // Valid only after raster is allocated (ie render started)
799  bool isValid() const;
800 
801  SYS_SAFE_BOOL operator bool() const { return isValid(); }
802 
803 private:
804  UT_SharedPtr<BRAY_AOVBuffer> myAOVBuffer;
805 };
806 
807 /// A render product represents an output file
809 {
810 public:
811  // Test whether the type is understook by karma
812  // For example "karma:checkpoint"
813  static bool isKnownType(const UT_StringRef &type);
814 
815  // Clear all existing output files
816  static void clearFiles(BRAY::ScenePtr &scene);
817 
818  struct BRAY_API AOV
819  {
821  : myName(name)
822  {
823  }
824  /// Method is specialized for T in:
825  /// - bool
826  /// - int32/int64
827  /// - fpreal32/fpreal64
828  /// - UT_StringHolder
829  template <typename T>
830  bool setOption(const UT_StringHolder &name,
831  const T *value,
832  exint size);
833  template <typename T>
834  bool setOption(const UT_StringHolder &name, const T &value)
835  { return setOption(name, &value, 1); }
836 
837  /// Copy over options from those passed in
838  bool setOptions(const UT_Options &options);
839 
840  const UT_StringHolder &name() const { return myName; }
841  const UT_Options &options() const { return myOptions; }
842  private:
843  UT_StringHolder myName;
844  UT_Options myOptions;
845  };
847  const UT_StringHolder &filename,
848  const UT_StringHolder &type)
849  : myScene(scene)
850  , myFilename(filename)
851  , myType(type)
852  {
853  }
854 
856  {
857  if (myFilename)
858  commit();
859  }
860 
861  /// @{
862  /// Method is specialized for T in:
863  /// - bool
864  /// - int32/int64
865  /// - fpreal32/fpreal64
866  /// - UT_StringHolder
867  template <typename T>
868  bool setOption(const UT_StringHolder &name,
869  const T *value,
870  exint size);
871  template <typename T>
872  bool setOption(const UT_StringHolder &name, const T &value)
873  { return setOption(name, &value, 1); }
874  /// @}
875 
876  /// Copy over options from those passed in
877  bool setOptions(const UT_Options &options);
878 
879  /// Add an AOV to this output file
881  {
882  myAOVs.emplace_back(name);
883  return myAOVs.last();
884  }
885 
886  /// Commit and add this output file to the render
887  bool commit()
888  {
889  bool result = doCommit();
890  cancel(); // Once committed, no more changes
891  return result;
892  }
893  /// Cancel this output file for some reason
894  void cancel() { myFilename.clear(); }
895 
896 private:
897  bool doCommit();
898  BRAY::ScenePtr &myScene;
899  UT_StringHolder myFilename;
900  UT_StringHolder myType;
901  UT_Array<AOV> myAOVs;
902  UT_Options myOptions;
903 };
904 
905 
906 /// Interface to the renderer
908 {
909 public:
910  /// Class used to define image planes
911  struct ImagePlane
912  {
915  int mySize;
918  };
919 
920  struct Stats
921  {
923  {
928  };
929 
931  {
932  clear();
933  myFrameCount = 0;
934  }
935  void clear()
936  {
937  myWorldToCamera = UT_Matrix4D(1);
938  myWorldToScreen = UT_Matrix4D(1);
939  myStage = STAGE_INACTIVE;
940  myPercentDone = 0;
941  myCameraRays = 0;
942  myIndirectRays = 0;
943  myOcclusionRays = 0;
944  myLightGeoRays = 0;
945  myProbeRays = 0;
946  myObjectCountsSet = false;
947  myPolyCount = UT_Vector2I(0, 0);
948  myCurveCount = UT_Vector2I(0, 0);
949  myPointCount = UT_Vector2I(0, 0);
950  myPointMeshCount = UT_Vector2I(0, 0);
951  myVolumeCount = UT_Vector2I(0, 0);
952  myProceduralCount = UT_Vector2I(0, 0);
953  myLightCount = 0;
954  myLightTreeCount = 0;
955  myCameraCount = 0;
956  myOctreeBuildTime = 0;
957  myLoadWallClock = 0;
958  myLoadCPU = 0;
959  myLoadSystem = 0;
960  myLoadMemory = 0;
961  myTotalWallClock = 0;
962  myTotalCPU = 0;
963  myTotalSystem = 0;
964  myCurrentMemory = 0;
965  myPeakMemory = 0;
966  myFilterErrors.clear();
967  myPrimvar.clear();
968  myDetailedTimes.clear();
969  }
970 
971  /// Transform matrices
974 
975  /// Current state of rendering
977 
978  /// Total number of frames rendered
980 
981  /// Percent complete of current frame
983 
984  /// Ray counts
990 
991  /// Object counts -- only defined if verbose >= 2
992  UT_Vector2I myPolyCount; // Individual/Instances
993  UT_Vector2I myCurveCount; // Individual/Instances
994  UT_Vector2I myPointCount; // Individual/Instances
995  UT_Vector2I myPointMeshCount; // Individual/Instances
996  UT_Vector2I myVolumeCount; // Individual/Instances
997  UT_Vector2I myProceduralCount; // Individual/Instances
998  int64 myLightCount; // Total lights in the scene
999  int64 myLightTreeCount; // Lights in the light tree
1000  int64 myCameraCount; // Cameras in the scene
1001 
1002  /// Times
1003  fpreal myOctreeBuildTime; // Time to build octree
1004 
1005  /// Initialization times
1006  fpreal myLoadWallClock; // Wall clock time for load
1007  fpreal myLoadCPU; // CPU time for load
1008  fpreal myLoadSystem; // System time for load
1009  int64 myLoadMemory; // Memory after load
1010 
1011  /// Render times
1012  fpreal myTotalWallClock; // Wall clock time for render
1013  fpreal myTotalCPU; // CPU time for load
1014  fpreal myTotalSystem; // System time for load
1015  int64 myCurrentMemory; // Current memory
1016 
1017  int64 myPeakMemory; // Memory after load
1018 
1019  // Errors from image/pixel/sample filters
1021 
1022  // Internal stats
1024 
1025  /// Detailed times if verbose >= 4
1027 
1028  // Whether myPolyCount, myCurveCount etc. are set
1030  };
1031 
1032  RendererPtr() = default;
1034 
1035  /// Allocate renderer
1036  static RendererPtr allocRenderer(BRAY::ScenePtr &sceneptr);
1037 
1038  SYS_SAFE_BOOL operator bool() const { return myRenderer.get(); }
1039 
1040  /// @{
1041  /// Define image planes for rendering
1042  void clearOutputPlanes();
1043  AOVBufferPtr addOutputPlane(const ImagePlane &plane);
1044  int getAOVCount() const;
1045  /// @}
1046 
1047  /// Return stats about rendering
1048  const Stats &renderStats() const;
1049 
1050  /// Start rendering a scene
1051  void render(bool (*stopreq)(void *) = nullptr, void *data = nullptr);
1052 
1053  /// Test to see whether the current renderer is active
1054  bool isRendering() const;
1055 
1056  /// Test to see if there was an error rendering
1057  bool isError() const;
1058 
1059  /// Test to see if the renderer is paused
1060  bool isPaused() const;
1061 
1062  /// Tells the renderer to prepare to be stopped
1063  void prepareForStop();
1064 
1065  /// Pause rendering -- Returns true if the renderer is paused
1066  bool pauseRender();
1067 
1068  /// Restart rendering -- Returns true if @c isRendering();
1069  bool resumeRender();
1070 
1071  /// Set a point in the image to give priority to rendering
1072  void setPriority(int x, int y);
1073 
1074  /// Set a region in the image which should have priority
1075  void setPriority(const UT_DimRect &region);
1076 
1077  /// Clear the priority focus
1078  void clearPriority();
1079 
1080 private:
1081  UT_SharedPtr<BRAY_Renderer> myRenderer;
1082 };
1083 
1085 {
1086 public:
1088  : myGraph(graph)
1089  {}
1091 
1092  /// @{
1093  /// Access to the underlying object
1094  const BRAY_ShaderGraph *graphPtr() const { return myGraph.get(); }
1095  /// @}
1096 
1097  /// Make new node based on type and add to list of nodes in the current
1098  /// graph. Returns NULL if unknown type.
1099  /// Note that the root node (ie with surface/displace output) must be the
1100  /// first node added to the graph.
1101  BRAY_ShaderInstance *createNode(const UT_StringHolder &type,
1102  const UT_StringHolder &name);
1103 
1104  /// Returns OptionSet that contains input parameters for given shader node.
1105  /// Can be used to read and write values.
1106  OptionSet nodeParams(BRAY_ShaderInstance *node);
1107 
1108  /// Make connection between two nodes
1109  bool wireNodes(const UT_StringHolder &srcnode,
1110  const UT_StringHolder &srcoutput,
1111  const UT_StringHolder &dstnode,
1112  const UT_StringHolder &dstinput);
1113 
1114 private:
1116 };
1117 
1118 }; // End of namespace
1119 
1120 #endif
int64 myCameraRays
Ray counts.
GLdouble s
Definition: glew.h:1390
void cancel()
Cancel this output file for some reason.
BRAY_EventType
Types of events that can be sent as updates to the renderer.
Definition: BRAY_Types.h:39
UT_Vector2T< int64 > UT_Vector2I
AOV & appendAOV(const UT_StringHolder &name)
Add an AOV to this output file.
GT_Storage
Definition: GT_Types.h:18
UT_Matrix4T< fpreal64 > UT_Matrix4D
UT_StringHolder optionS(BRAY_SceneOption t) const
int64 propertyI(BRAY_SceneOption t) const
GT_API const UT_StringHolder filename
fpreal myOctreeBuildTime
Times.
GLsizeiptr size
Definition: glew.h:1681
GLenum src
Definition: glew.h:2410
GLuint const GLchar * name
Definition: glew.h:1814
Interface to scene materials.
const VPRM_SpacePtr & space() const
bool operator==(const AOVBufferPtr &aov) const
SYS_FORCE_INLINE const T * propertyImport(BRAY_ObjectProperty token, T *val, size_t n) const
const BRAY_Scene * scenePtr() const
bool commit()
Commit and add this output file to the render.
const BRAY_Camera * cameraPtr() const
bool isValid() const
Test validity.
const Args & args
Definition: printf.h:628
float BRAYtime
Consistent representation of time type within BRAY.
Definition: BRAY_Types.h:472
UT_Vector2I myPolyCount
Object counts – only defined if verbose >= 2.
const BRAY_ShaderGraph * graphPtr() const
VPRM_SpacePtr & space()
BRAY_Light * lightPtr()
BRAY_RayVisibility
Ray visibility flags.
Definition: BRAY_Types.h:510
bool operator!=(const AOVBufferPtr &aov) const
GLuint const GLfloat * val
Definition: glew.h:2794
SYS_FORCE_INLINE bool setProperty(BRAY_ObjectProperty token, const T &value)
Simple interface to set a scalar property.
AOV(const UT_StringHolder &name)
UT_SharedPtr< BRAY_Light > myLight
FacesetMaterial(const GT_DataArrayHandle &facelist=GT_DataArrayHandle(), const MaterialPtr &material=MaterialPtr())
int64 exint
Definition: SYS_Types.h:125
const UT_StringHolder & name() const
SYS_FORCE_INLINE const T * optionImport(BRAY_SceneOption token, T *val, size_t n) const
bool setOption(const UT_StringHolder &name, const T &value)
UT_StringHolder myGeometry
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:34
GLhandleARB obj
Definition: glew.h:6236
int64 optionI(BRAY_SceneOption t) const
SYS_FORCE_INLINE bool set(int token, const T &value)
Simple interface to set a scalar property.
const BRAY_Object * objectPtr() const
GLenum GLint GLuint mask
Definition: glew.h:1845
SYS_FORCE_INLINE exint propertySize(BRAY_ObjectProperty token) const
const BRAY_Light * lightPtr() const
OutputFile(BRAY::ScenePtr &scene, const UT_StringHolder &filename, const UT_StringHolder &type)
bool isValid() const
Test validity.
UT_Matrix4D myWorldToCamera
Transform matrices.
CameraPtr(const UT_SharedPtr< BRAY_Camera > &cp=UT_SharedPtr< BRAY_Camera >())
IFDmantra you can see code vm_image_mplay_direction endcode When SOHO starts a render
Definition: HDK_Image.dox:266
const BRAY_VexMaterial * materialPtr() const
SYS_FORCE_INLINE bool isEqual(int token, const T &value) const
Simple interface for equality of a scalar value.
UT_StringHolder propertyS(BRAY_SceneOption t) const
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:33
bool isValid() const
Test validity.
UT_StringHolder myParmName
double fpreal64
Definition: SYS_Types.h:201
bool propertyB(BRAY_SceneOption t) const
VPRM_OptionSetPtr & options()
BRAY_ObjectProperty
Definition: BRAY_Types.h:148
SYS_FORCE_INLINE GT_Storage propertyStorage(BRAY_ObjectProperty token) const
Return the storage class of an option.
UT_SharedPtr< BRAY_Camera > myCamera
GLint GLint GLint GLint GLint x
Definition: glew.h:1252
UT_SharedPtr< BRAY_Object > myObject
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1252
#define SYS_SAFE_BOOL
Definition: SYS_Compiler.h:55
BRAY_Camera * cameraPtr()
bool isValid() const
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:28
UT_IntrusivePtr< GT_DataArray > GT_DataArrayHandle
Definition: GT_DataArray.h:32
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
SYS_FORCE_INLINE exint optionSize(BRAY_SceneOption token) const
int setVolume(int speaker, float vol) override
ShaderGraphPtr(UT_SharedPtr< BRAY_ShaderGraph > graph)
bool isValid() const
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1890
GLsizei n
Definition: glew.h:4040
SYS_FORCE_INLINE bool optionIsVariadic(BRAY_SceneOption token) const
Return whether an option has variadic arguments.
PXL_Packing
Definition: PXL_Common.h:30
SYS_FORCE_INLINE bool setOption(BRAY_SceneOption token, const T *value, exint tuple_size)
Interface to set an option. This template class is specialized for:
long long int64
Definition: SYS_Types.h:116
SYS_FORCE_INLINE exint lockAllObjectProperties(bool state)
Lock or unlock all object properties.
int myFrameCount
Total number of frames rendered.
fpreal myLoadWallClock
Initialization times.
bool isValid() const
Test validity.
Class used to define image planes.
MaterialInput(const UT_StringHolder &primvar, const UT_StringHolder &shader_parm, Storage store, int tsize, bool is_array)
PXL_DataFormat
Definition: PXL_Common.h:20
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
const UT_Options & options() const
GT_DataArrayHandle myFaceList
GLsizei const GLchar *const * path
Definition: glew.h:6461
BRAY_LightType
Definition: BRAY_Types.h:437
SYS_FORCE_INLINE bool setOption(BRAY_SceneOption token, const T &value)
Simple interface to set a scalar option.
fpreal myPercentDone
Percent complete of current frame.
A map of string to various well defined value types.
Definition: UT_Options.h:84
cl_event event
Definition: glew.h:3695
A render product represents an output file.
BRAY_SceneOption
Definition: BRAY_Types.h:66
UT_StringHolder myDetailedTimes
Detailed times if verbose >= 4.
const void * ptr(const T *p)
Definition: format.h:3292
bool isValid() const
fpreal64 fpreal
Definition: SYS_Types.h:277
fpreal64 optionF(BRAY_SceneOption t) const
MaterialPtr(BRAY_VexMaterial *mat=nullptr)
FMT_CONSTEXPR bool find(Ptr first, Ptr last, T value, Ptr &out)
Definition: format.h:2104
SYS_FORCE_INLINE bool setProperty(BRAY_ObjectProperty token, const T *value, exint tuple_size)
Interface to set an property. This template class is specialized for:
AOVBufferPtr(const UT_SharedPtr< BRAY_AOVBuffer > &aov)
SYS_FORCE_INLINE bool propertyIsVariadic(BRAY_ObjectProperty token) const
Return whether an property has variadic arguments.
#define BRAY_API
Definition: BRAY_API.h:12
const GLuint * ids
Definition: glew.h:1684
BRAY_PropertyType
Definition: BRAY_Types.h:293
GLuint64EXT * result
Definition: glew.h:14007
getOption("OpenEXR.storage") storage
Definition: HDK_Image.dox:276
RenderStage myStage
Current state of rendering.
bool setOption(const UT_StringHolder &name, const T &value)
GLubyte * pattern
Definition: glew.h:5711
bool optionB(BRAY_SceneOption t) const
Interface to the renderer.
fpreal64 propertyF(BRAY_SceneOption t) const
GLsizei const GLfloat * value
Definition: glew.h:1849
GLdouble GLdouble t
Definition: glew.h:1398
GLfloat units
Definition: glew.h:10289
const VPRM_OptionSetPtr & options() const
BRAY_Object * objectPtr()
BRAY_Scene * scenePtr()
UT_StringArray myFilterErrors
LightPtr(const UT_SharedPtr< BRAY_Light > &lp=UT_SharedPtr< BRAY_Light >())
SYS_FORCE_INLINE GT_Storage optionStorage(BRAY_SceneOption token) const
Return the storage class of an option.
type
Definition: core.h:528
GLintptr GLsizeiptr GLboolean commit
Definition: glew.h:6520
fpreal myTotalWallClock
Render times.