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 Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_IMAGING_HD_ST_BASIS_CURVES_H
25 #define PXR_IMAGING_HD_ST_BASIS_CURVES_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdSt/api.h"
29 #include "pxr/imaging/hd/version.h"
32 #include "pxr/imaging/hd/enums.h"
33 #include "pxr/imaging/hd/perfLog.h"
34 
35 #include "pxr/usd/sdf/path.h"
36 #include "pxr/base/vt/array.h"
37 
38 #include <memory>
39 
41 
42 class HdStDrawItem;
44  std::shared_ptr<class HdSt_BasisCurvesTopology>;
45 
46 /// \class HdStBasisCurves
47 ///
48 /// A collection of curves using a particular basis.
49 ///
50 /// Render mode is dependent on both the HdBasisCurvesGeomStyle, refinement
51 /// level, and the authored primvars.
52 ///
53 /// If style is set to HdBasisCurvesGeomStyleWire, the curves will always draw
54 /// as infinitely thin wires. Cubic curves will be refined if complexity is
55 /// above 0, otherwise they draw the unrefined control points. (This may
56 /// provide a misleading representation for Catmull-Rom and Bspline curves.)
57 ///
58 /// If style is set to HdBasisCurvesGeomStylePatch, the curves will draw as
59 /// patches ONLY if refinement level is above 0. Otherwise, they draw
60 /// as the unrefined control points (see notes on HdBasisCurvesGeomStyleWire).
61 ///
62 /// Curves rendered as patches may be rendered as ribbons or halftubes.
63 /// Curves with primvar authored normals will always render as ribbons.
64 /// Curves without primvar authored normals are assumed to be round and may be
65 /// rendered in one of three styles:
66 /// * if complexity is 1, a camera facing normal is used
67 /// * if complexity is 2, a fake "bumped" round normal is used
68 /// * if complexity is 3 or above, the patch is displaced into a half tube
69 /// We plan for future checkins will remove the need for the camera facing normal
70 /// mode, using the fake "bumped" round normal instead.
71 class HdStBasisCurves final: public HdBasisCurves {
72 public:
73  HF_MALLOC_TAG_NEW("new HdStBasisCurves");
74 
75  HDST_API
76  HdStBasisCurves(SdfPath const& id,
77  SdfPath const& instancerId = SdfPath());
78  HDST_API
79  virtual ~HdStBasisCurves();
80 
81  HDST_API
82  virtual void Sync(HdSceneDelegate *delegate,
83  HdRenderParam *renderParam,
84  HdDirtyBits *dirtyBits,
85  TfToken const &reprToken) override;
86 
87  HDST_API
88  virtual HdDirtyBits GetInitialDirtyBitsMask() const override;
89 
90 protected:
91  HDST_API
92  virtual void _InitRepr(TfToken const &reprToken,
93  HdDirtyBits *dirtyBits) override;
94 
95  HDST_API
96  virtual HdDirtyBits _PropagateDirtyBits(HdDirtyBits bits) const override;
97 
98  void _UpdateRepr(HdSceneDelegate *sceneDelegate,
99  TfToken const &reprToken,
100  HdDirtyBits *dirtyBitsState);
101 
102  void _PopulateTopology(HdSceneDelegate *sceneDelegate,
103  HdStDrawItem *drawItem,
104  HdDirtyBits *dirtyBits,
105  const HdBasisCurvesReprDesc &desc);
106 
107  void _PopulateVertexPrimvars(HdSceneDelegate *sceneDelegate,
108  HdStDrawItem *drawItem,
109  HdDirtyBits *dirtyBits);
110 
111  void _PopulateElementPrimvars(HdSceneDelegate *sceneDelegate,
112  HdStDrawItem *drawItem,
113  HdDirtyBits *dirtyBits);
114 
115 
116 private:
117  enum DrawingCoord {
118  HullTopology = HdDrawingCoord::CustomSlotsBegin,
119  PointsTopology,
120  InstancePrimvar // has to be at the very end
121  };
122 
123  enum DirtyBits : HdDirtyBits {
124  DirtyIndices = HdChangeTracker::CustomBitsBegin,
125  DirtyHullIndices = (DirtyIndices << 1),
126  DirtyPointsIndices = (DirtyHullIndices << 1)
127  };
128 
129  // When processing primvars, these will get set to if we determine that
130  // we should do cubic basis interpolation on the normals and widths.
131  // NOTE: I worry that it may be possible for these to get out of sync.
132  // The right long term fix is likely to maintain proper separation between
133  // varying and vertex primvars throughout the HdSt rendering pipeline.
134  bool _basisWidthInterpolation = false;
135  bool _basisNormalInterpolation = false;
136 
137  bool _SupportsRefinement(int refineLevel);
138  bool _SupportsUserWidths(HdStDrawItem* drawItem);
139  bool _SupportsUserNormals(HdStDrawItem* drawItem);
140 
141  const TfToken& _GetMaterialTag(const HdRenderIndex &renderIndex) const;
142 
143  void _UpdateDrawItem(HdSceneDelegate *sceneDelegate,
144  HdStDrawItem *drawItem,
145  HdDirtyBits *dirtyBits,
146  const HdBasisCurvesReprDesc &desc);
147 
148  void _UpdateDrawItemGeometricShader(HdSceneDelegate *sceneDelegate,
149  HdStDrawItem *drawItem,
150  const HdBasisCurvesReprDesc &desc);
151 
152  void _UpdateShadersForAllReprs(HdSceneDelegate *sceneDelegate,
153  bool updateMaterialShader,
154  bool updateGeometricShader);
155 
156 
158  HdTopology::ID _topologyId;
159  HdDirtyBits _customDirtyBitsInUse;
160  int _refineLevel; // XXX: could be moved into HdBasisCurveTopology.
161 };
162 
163 
165 
166 #endif // PXR_IMAGING_HD_ST_BASIS_CURVES_H
HF_MALLOC_TAG_NEW("new HdStBasisCurves")
virtual HDST_API HdDirtyBits GetInitialDirtyBitsMask() const override
static const int CustomSlotsBegin
Definition: drawingCoord.h:83
std::shared_ptr< class HdSt_BasisCurvesTopology > HdSt_BasisCurvesTopologySharedPtr
Definition: basisCurves.h:44
virtual HDST_API void _InitRepr(TfToken const &reprToken, HdDirtyBits *dirtyBits) override
uint64_t ID
Definition: topology.h:38
uint32_t HdDirtyBits
Definition: types.h:127
Definition: token.h:87
virtual HDST_API void Sync(HdSceneDelegate *delegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits, TfToken const &reprToken) override
void _UpdateRepr(HdSceneDelegate *sceneDelegate, TfToken const &reprToken, HdDirtyBits *dirtyBitsState)
Definition: path.h:288
virtual HDST_API HdDirtyBits _PropagateDirtyBits(HdDirtyBits bits) const override
void _PopulateElementPrimvars(HdSceneDelegate *sceneDelegate, HdStDrawItem *drawItem, HdDirtyBits *dirtyBits)
void _PopulateVertexPrimvars(HdSceneDelegate *sceneDelegate, HdStDrawItem *drawItem, HdDirtyBits *dirtyBits)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
#define HDST_API
Definition: api.h:40
void _PopulateTopology(HdSceneDelegate *sceneDelegate, HdStDrawItem *drawItem, HdDirtyBits *dirtyBits, const HdBasisCurvesReprDesc &desc)
HDST_API HdStBasisCurves(SdfPath const &id, SdfPath const &instancerId=SdfPath())
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
virtual HDST_API ~HdStBasisCurves()