HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
basisCurves.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_IMAGING_HD_ST_BASIS_CURVES_H
8 #define PXR_IMAGING_HD_ST_BASIS_CURVES_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hdSt/api.h"
12 #include "pxr/imaging/hd/version.h"
15 #include "pxr/imaging/hd/enums.h"
16 #include "pxr/imaging/hd/perfLog.h"
17 
18 #include "pxr/usd/sdf/path.h"
19 #include "pxr/base/vt/array.h"
20 
21 #include <memory>
22 
24 
25 class HdStDrawItem;
27  std::shared_ptr<class HdSt_BasisCurvesTopology>;
28 
29 /// \class HdStBasisCurves
30 ///
31 /// A collection of curves using a particular basis.
32 ///
33 /// Render mode is dependent on both the HdBasisCurvesGeomStyle, refinement
34 /// level, and the authored primvars.
35 ///
36 /// If style is set to HdBasisCurvesGeomStyleWire, the curves will always draw
37 /// as infinitely thin wires. Cubic curves will be refined if complexity is
38 /// above 0, otherwise they draw the unrefined control points. (This may
39 /// provide a misleading representation for Catmull-Rom and Bspline curves.)
40 ///
41 /// If style is set to HdBasisCurvesGeomStylePatch, the curves will draw as
42 /// patches ONLY if refinement level is above 0. Otherwise, they draw
43 /// as the unrefined control points (see notes on HdBasisCurvesGeomStyleWire).
44 ///
45 /// Curves rendered as patches may be rendered as ribbons or halftubes.
46 /// Curves with primvar authored normals will always render as ribbons.
47 /// Curves without primvar authored normals are assumed to be round and may be
48 /// rendered in one of three styles:
49 /// * if complexity is 1, a camera facing normal is used
50 /// * if complexity is 2, a fake "bumped" round normal is used
51 /// * if complexity is 3 or above, the patch is displaced into a half tube
52 /// We plan for future checkins will remove the need for the camera facing normal
53 /// mode, using the fake "bumped" round normal instead.
54 class HdStBasisCurves final: public HdBasisCurves
55 {
56 public:
57  HF_MALLOC_TAG_NEW("new HdStBasisCurves");
58 
59  HDST_API
60  HdStBasisCurves(SdfPath const& id);
61 
62  HDST_API
63  ~HdStBasisCurves() override;
64 
65  HDST_API
66  void UpdateRenderTag(HdSceneDelegate *delegate,
67  HdRenderParam *renderParam) override;
68 
69  HDST_API
70  void Sync(HdSceneDelegate *delegate,
71  HdRenderParam *renderParam,
72  HdDirtyBits *dirtyBits,
73  TfToken const &reprToken) override;
74 
75  HDST_API
76  void Finalize(HdRenderParam *renderParam) override;
77 
78  HDST_API
79  HdDirtyBits GetInitialDirtyBitsMask() const override;
80 
81  HDST_API
82  TfTokenVector const & GetBuiltinPrimvarNames() const override;
83 
84 protected:
85  HDST_API
86  void _InitRepr(TfToken const &reprToken, HdDirtyBits *dirtyBits) override;
87 
88  HDST_API
89  HdDirtyBits _PropagateDirtyBits(HdDirtyBits bits) const override;
90 
91  void _UpdateRepr(HdSceneDelegate *sceneDelegate,
92  HdRenderParam *renderParam,
93  TfToken const &reprToken,
94  HdDirtyBits *dirtyBitsState);
95 
96  void _PopulateTopology(HdSceneDelegate *sceneDelegate,
97  HdRenderParam *renderParam,
98  HdStDrawItem *drawItem,
99  HdDirtyBits *dirtyBits,
100  const HdBasisCurvesReprDesc &desc);
101 
102  void _PopulateVertexPrimvars(HdSceneDelegate *sceneDelegate,
103  HdRenderParam *renderParam,
104  HdStDrawItem *drawItem,
105  HdDirtyBits *dirtyBits);
106 
107  void _PopulateVaryingPrimvars(HdSceneDelegate *sceneDelegate,
108  HdRenderParam *renderParam,
109  HdStDrawItem *drawItem,
110  HdDirtyBits *dirtyBits);
111 
112  void _PopulateElementPrimvars(HdSceneDelegate *sceneDelegate,
113  HdRenderParam *renderParam,
114  HdStDrawItem *drawItem,
115  HdDirtyBits *dirtyBits);
116 
117 private:
118  enum DrawingCoord {
119  HullTopology = HdDrawingCoord::CustomSlotsBegin,
120  PointsTopology,
121  InstancePrimvar // has to be at the very end
122  };
123 
124  enum DirtyBits : HdDirtyBits {
125  DirtyIndices = HdChangeTracker::CustomBitsBegin,
126  DirtyHullIndices = (DirtyIndices << 1),
127  DirtyPointsIndices = (DirtyHullIndices << 1)
128  };
129 
130  // When processing primvars, these will get set to if we determine that
131  // we should do cubic basis interpolation on the normals and widths.
132  // NOTE: I worry that it may be possible for these to get out of sync.
133  // The right long term fix is likely to maintain proper separation between
134  // varying and vertex primvars throughout the HdSt rendering pipeline.
135  bool _basisWidthInterpolation = false;
136  bool _basisNormalInterpolation = false;
137 
138  bool _SupportsRefinement(int refineLevel);
139  bool _SupportsUserWidths(HdStDrawItem* drawItem);
140  bool _SupportsUserNormals(HdStDrawItem* drawItem);
141 
142  void _UpdateDrawItem(HdSceneDelegate *sceneDelegate,
143  HdRenderParam *renderParam,
144  HdStDrawItem *drawItem,
145  HdDirtyBits *dirtyBits,
146  const HdBasisCurvesReprDesc &desc);
147 
148  void _UpdateDrawItemGeometricShader(HdSceneDelegate *sceneDelegate,
149  HdRenderParam *renderParam,
150  HdStDrawItem *drawItem,
151  const HdBasisCurvesReprDesc &desc);
152 
153  void _UpdateShadersForAllReprs(HdSceneDelegate *sceneDelegate,
154  HdRenderParam *renderParam,
155  bool updateMaterialNetworkShader,
156  bool updateGeometricShader);
157 
158  void _UpdateMaterialTagsForAllReprs(HdSceneDelegate *sceneDelegate,
159  HdRenderParam *renderParam);
160 
162  HdTopology::ID _topologyId;
163  HdDirtyBits _customDirtyBitsInUse;
164  int _refineLevel; // XXX: could be moved into HdBasisCurveTopology.
165  bool _displayOpacity : 1;
166  bool _displayInOverlay : 1;
167  bool _occludedSelectionShowsThrough : 1;
168  bool _pointsShadingEnabled : 1;
169 };
170 
171 
173 
174 #endif // PXR_IMAGING_HD_ST_BASIS_CURVES_H
HF_MALLOC_TAG_NEW("new HdStBasisCurves")
HDST_API TfTokenVector const & GetBuiltinPrimvarNames() const override
static const int CustomSlotsBegin
Definition: drawingCoord.h:68
void _PopulateVaryingPrimvars(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdStDrawItem *drawItem, HdDirtyBits *dirtyBits)
std::shared_ptr< class HdSt_BasisCurvesTopology > HdSt_BasisCurvesTopologySharedPtr
Definition: basisCurves.h:27
uint64_t ID
Definition: topology.h:21
void _PopulateElementPrimvars(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdStDrawItem *drawItem, HdDirtyBits *dirtyBits)
uint32_t HdDirtyBits
Definition: types.h:143
void _PopulateVertexPrimvars(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdStDrawItem *drawItem, HdDirtyBits *dirtyBits)
HDST_API void UpdateRenderTag(HdSceneDelegate *delegate, HdRenderParam *renderParam) override
HDST_API HdDirtyBits GetInitialDirtyBitsMask() const override
HDST_API void _InitRepr(TfToken const &reprToken, HdDirtyBits *dirtyBits) override
Definition: token.h:70
HDST_API HdStBasisCurves(SdfPath const &id)
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
Definition: path.h:273
HDST_API void Finalize(HdRenderParam *renderParam) override
void _PopulateTopology(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdStDrawItem *drawItem, HdDirtyBits *dirtyBits, const HdBasisCurvesReprDesc &desc)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
HDST_API void Sync(HdSceneDelegate *delegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits, TfToken const &reprToken) override
#define HDST_API
Definition: api.h:23
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
void _UpdateRepr(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, TfToken const &reprToken, HdDirtyBits *dirtyBitsState)
HDST_API HdDirtyBits _PropagateDirtyBits(HdDirtyBits bits) const override
HDST_API ~HdStBasisCurves() override