basisCurves.h
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"
30 #include "pxr/imaging/hd/basisCurves.h"
31 #include "pxr/imaging/hd/drawingCoord.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 
40 PXR_NAMESPACE_OPEN_SCOPE
41 
42 class HdStDrawItem;
43 using HdSt_BasisCurvesTopologySharedPtr =
44  std::shared_ptr<class HdSt_BasisCurvesTopology>;
45 
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 
178  HdSt_BasisCurvesTopologySharedPtr _topology;
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 
188 PXR_NAMESPACE_CLOSE_SCOPE
189 
190 #endif // PXR_IMAGING_HD_ST_BASIS_CURVES_H
HDST_API HdDirtyBits GetInitialDirtyBitsMask() const override
Returns the set of dirty bits that should be added to the change tracker for this prim,...
The HdRenderParam is an opaque (to core Hydra) handle, to an object that is obtained from the render ...
HDST_API TfTokenVector const & GetBuiltinPrimvarNames() const override
Returns the names of built-in primvars, i.e.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
Adapter class providing data exchange with the client scene graph.
Descriptor to configure a drawItem for a repr.
Definition: basisCurves.h:47
A collection of curves using a particular basis.
Definition: basisCurves.h:71
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
HDST_API void Finalize(HdRenderParam *renderParam) override
Finalizes object resources.
HDST_API void Sync(HdSceneDelegate *delegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits, TfToken const &reprToken) override
Pull invalidated scene data and prepare/update the renderable representation.
HDST_API HdDirtyBits _PropagateDirtyBits(HdDirtyBits bits) const override
This callback from Rprim gives the prim an opportunity to set additional dirty bits based on those al...
HDST_API void _InitRepr(TfToken const &reprToken, HdDirtyBits *dirtyBits) override
Initialize the given representation of this Rprim.
Hydra Schema for a collection of curves using a particular basis.
Definition: basisCurves.h:68