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 {
73 public:
74  HF_MALLOC_TAG_NEW("new HdStBasisCurves");
75 
76  HDST_API
77  HdStBasisCurves(SdfPath const& id);
78 
79  HDST_API
80  ~HdStBasisCurves() override;
81 
82  HDST_API
83  void UpdateRenderTag(HdSceneDelegate *delegate,
84  HdRenderParam *renderParam) override;
85 
86  HDST_API
87  void Sync(HdSceneDelegate *delegate,
88  HdRenderParam *renderParam,
89  HdDirtyBits *dirtyBits,
90  TfToken const &reprToken) override;
91 
92  HDST_API
93  void Finalize(HdRenderParam *renderParam) override;
94 
95  HDST_API
96  HdDirtyBits GetInitialDirtyBitsMask() const override;
97 
98  HDST_API
99  TfTokenVector const & GetBuiltinPrimvarNames() const override;
100 
101 protected:
102  HDST_API
103  void _InitRepr(TfToken const &reprToken, HdDirtyBits *dirtyBits) override;
104 
105  HDST_API
106  HdDirtyBits _PropagateDirtyBits(HdDirtyBits bits) const override;
107 
108  void _UpdateRepr(HdSceneDelegate *sceneDelegate,
109  HdRenderParam *renderParam,
110  TfToken const &reprToken,
111  HdDirtyBits *dirtyBitsState);
112 
113  void _PopulateTopology(HdSceneDelegate *sceneDelegate,
114  HdRenderParam *renderParam,
115  HdStDrawItem *drawItem,
116  HdDirtyBits *dirtyBits,
117  const HdBasisCurvesReprDesc &desc);
118 
119  void _PopulateVertexPrimvars(HdSceneDelegate *sceneDelegate,
120  HdRenderParam *renderParam,
121  HdStDrawItem *drawItem,
122  HdDirtyBits *dirtyBits);
123 
124  void _PopulateVaryingPrimvars(HdSceneDelegate *sceneDelegate,
125  HdRenderParam *renderParam,
126  HdStDrawItem *drawItem,
127  HdDirtyBits *dirtyBits);
128 
129  void _PopulateElementPrimvars(HdSceneDelegate *sceneDelegate,
130  HdRenderParam *renderParam,
131  HdStDrawItem *drawItem,
132  HdDirtyBits *dirtyBits);
133 
134 private:
135  enum DrawingCoord {
136  HullTopology = HdDrawingCoord::CustomSlotsBegin,
137  PointsTopology,
138  InstancePrimvar // has to be at the very end
139  };
140 
141  enum DirtyBits : HdDirtyBits {
142  DirtyIndices = HdChangeTracker::CustomBitsBegin,
143  DirtyHullIndices = (DirtyIndices << 1),
144  DirtyPointsIndices = (DirtyHullIndices << 1)
145  };
146 
147  // When processing primvars, these will get set to if we determine that
148  // we should do cubic basis interpolation on the normals and widths.
149  // NOTE: I worry that it may be possible for these to get out of sync.
150  // The right long term fix is likely to maintain proper separation between
151  // varying and vertex primvars throughout the HdSt rendering pipeline.
152  bool _basisWidthInterpolation = false;
153  bool _basisNormalInterpolation = false;
154 
155  bool _SupportsRefinement(int refineLevel);
156  bool _SupportsUserWidths(HdStDrawItem* drawItem);
157  bool _SupportsUserNormals(HdStDrawItem* drawItem);
158 
159  void _UpdateDrawItem(HdSceneDelegate *sceneDelegate,
160  HdRenderParam *renderParam,
161  HdStDrawItem *drawItem,
162  HdDirtyBits *dirtyBits,
163  const HdBasisCurvesReprDesc &desc);
164 
165  void _UpdateDrawItemGeometricShader(HdSceneDelegate *sceneDelegate,
166  HdRenderParam *renderParam,
167  HdStDrawItem *drawItem,
168  const HdBasisCurvesReprDesc &desc);
169 
170  void _UpdateShadersForAllReprs(HdSceneDelegate *sceneDelegate,
171  HdRenderParam *renderParam,
172  bool updateMaterialNetworkShader,
173  bool updateGeometricShader);
174 
175  void _UpdateMaterialTagsForAllReprs(HdSceneDelegate *sceneDelegate,
176  HdRenderParam *renderParam);
177 
179  HdTopology::ID _topologyId;
180  HdDirtyBits _customDirtyBitsInUse;
181  int _refineLevel; // XXX: could be moved into HdBasisCurveTopology.
182  bool _displayOpacity : 1;
183  bool _occludedSelectionShowsThrough : 1;
184  bool _pointsShadingEnabled : 1;
185 };
186 
187 
189 
190 #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:85
void _PopulateVaryingPrimvars(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdStDrawItem *drawItem, HdDirtyBits *dirtyBits)
std::shared_ptr< class HdSt_BasisCurvesTopology > HdSt_BasisCurvesTopologySharedPtr
Definition: basisCurves.h:44
uint64_t ID
Definition: topology.h:38
void _PopulateElementPrimvars(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdStDrawItem *drawItem, HdDirtyBits *dirtyBits)
uint32_t HdDirtyBits
Definition: types.h:158
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:87
HDST_API HdStBasisCurves(SdfPath const &id)
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:457
Definition: path.h:290
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:1432
HDST_API void Sync(HdSceneDelegate *delegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits, TfToken const &reprToken) override
#define HDST_API
Definition: api.h:40
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
void _UpdateRepr(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, TfToken const &reprToken, HdDirtyBits *dirtyBitsState)
HDST_API HdDirtyBits _PropagateDirtyBits(HdDirtyBits bits) const override
HDST_API ~HdStBasisCurves() override