All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mesh.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 HDST_MESH_H
25 #define HDST_MESH_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/changeTracker.h"
31 #include "pxr/imaging/hd/drawingCoord.h"
32 #include "pxr/imaging/hd/mesh.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 <boost/shared_ptr.hpp>
39 
40 PXR_NAMESPACE_OPEN_SCOPE
41 
42 
43 class HdStDrawItem;
44 class HdSceneDelegate;
45 
46 typedef boost::shared_ptr<class Hd_VertexAdjacency> Hd_VertexAdjacencySharedPtr;
47 typedef boost::shared_ptr<class HdSt_MeshTopology> HdSt_MeshTopologySharedPtr;
48 typedef boost::shared_ptr<class HdBufferSource> HdBufferSourceSharedPtr;
49 typedef boost::shared_ptr<class HdStResourceRegistry>
50  HdStResourceRegistrySharedPtr;
51 typedef boost::shared_ptr<class HdStShaderCode> HdStShaderCodeSharedPtr;
52 
55 class HdStMesh final : public HdMesh {
56 public:
57  HF_MALLOC_TAG_NEW("new HdStMesh");
58 
61  HDST_API
62  HdStMesh(SdfPath const& id,
63  SdfPath const& instancerId = SdfPath());
64 
65  HDST_API
66  virtual ~HdStMesh();
67 
68  HDST_API
69  virtual void Sync(HdSceneDelegate *delegate,
70  HdRenderParam *renderParam,
71  HdDirtyBits *dirtyBits,
72  TfToken const &reprToken) override;
73 
74  HDST_API
75  virtual HdDirtyBits GetInitialDirtyBitsMask() const override;
76 
78  HDST_API
79  virtual HdMeshTopologySharedPtr GetTopology() const override;
80 
82  HDST_API
83  static bool IsEnabledPackedNormals();
84 
85 protected:
86  HDST_API
87  virtual void _InitRepr(TfToken const &reprToken,
88  HdDirtyBits *dirtyBits) override;
89 
90  HDST_API
91  virtual HdDirtyBits _PropagateDirtyBits(HdDirtyBits bits) const override;
92 
93  void _UpdateRepr(HdSceneDelegate *sceneDelegate,
94  TfToken const &reprToken,
95  HdDirtyBits *dirtyBitsState);
96 
97  HdBufferArrayRangeSharedPtr
98  _GetSharedPrimvarRange(uint64_t primvarId,
99  HdBufferSpecVector const &bufferSpecs,
100  HdBufferArrayRangeSharedPtr const &existing,
101  bool * isFirstInstance,
102  HdStResourceRegistrySharedPtr const &resourceRegistry) const;
103 
104  bool _UseQuadIndices(const HdRenderIndex &renderIndex,
105  HdSt_MeshTopologySharedPtr const & topology) const;
106 
107  bool _UseLimitRefinement(const HdRenderIndex &renderIndex) const;
108 
109  bool _UseSmoothNormals(HdSt_MeshTopologySharedPtr const& topology) const;
110 
111  bool _UseFlatNormals(const HdMeshReprDesc &desc) const;
112 
113  const TfToken& _GetMaterialTag(const HdRenderIndex &renderIndex) const;
114 
115  void _UpdateDrawItem(HdSceneDelegate *sceneDelegate,
116  HdStDrawItem *drawItem,
117  HdDirtyBits *dirtyBits,
118  const HdMeshReprDesc &desc,
119  bool requireSmoothNormals,
120  bool requireFlatNormals);
121 
122  void _UpdateDrawItemGeometricShader(HdSceneDelegate *sceneDelegate,
123  HdStDrawItem *drawItem,
124  const HdMeshReprDesc &desc,
125  size_t drawItemIdForDesc);
126 
127  void _UpdateShadersForAllReprs(HdSceneDelegate *sceneDelegate,
128  bool updateMaterialShader,
129  bool updateGeometricShader);
130 
131  void _PopulateTopology(HdSceneDelegate *sceneDelegate,
132  HdStDrawItem *drawItem,
133  HdDirtyBits *dirtyBits,
134  const HdMeshReprDesc &desc);
135 
136  void _PopulateTopologyVisibility(
137  HdStDrawItem *drawItem,
138  HdStResourceRegistrySharedPtr const &resourceRegistry,
139  HdChangeTracker *changeTracker,
140  HdMeshTopology const& meshTopology);
141 
142  void _PopulateAdjacency(HdStResourceRegistrySharedPtr const &resourceRegistry);
143 
144  void _PopulateVertexPrimvars(HdSceneDelegate *sceneDelegate,
145  HdStDrawItem *drawItem,
146  HdDirtyBits *dirtyBits,
147  bool requireSmoothNormals,
148  HdBufferSourceSharedPtr *outPoints);
149 
150  void _PopulateFaceVaryingPrimvars(HdSceneDelegate *sceneDelegate,
151  HdStDrawItem *drawItem,
152  HdDirtyBits *dirtyBits,
153  const HdMeshReprDesc &desc);
154 
155  void _PopulateElementPrimvars(HdSceneDelegate *sceneDelegate,
156  HdStDrawItem *drawItem,
157  HdDirtyBits *dirtyBits,
158  bool requireFlatNormals,
159  HdBufferSourceSharedPtr const &points);
160 
161  int _GetRefineLevelForDesc(const HdMeshReprDesc &desc) const;
162 
163  HdType _GetPointsDataTypeFromBar(HdStDrawItem *drawItem) const;
164 
165 private:
166  enum DrawingCoord {
167  HullTopology = HdDrawingCoord::CustomSlotsBegin,
168  PointsTopology,
169  InstancePrimvar // has to be at the very end
170  };
171 
172  enum DirtyBits : HdDirtyBits {
173  DirtySmoothNormals = HdChangeTracker::CustomBitsBegin,
174  DirtyFlatNormals = (DirtySmoothNormals << 1),
175  DirtyIndices = (DirtyFlatNormals << 1),
176  DirtyHullIndices = (DirtyIndices << 1),
177  DirtyPointsIndices = (DirtyHullIndices << 1)
178  };
179 
180  HdSt_MeshTopologySharedPtr _topology;
181  Hd_VertexAdjacencySharedPtr _vertexAdjacency;
182 
183  HdTopology::ID _topologyId;
184  HdTopology::ID _vertexPrimvarId;
185  HdDirtyBits _customDirtyBitsInUse;
186 
187  HdInterpolation _sceneNormalsInterpolation;
188  HdCullStyle _cullStyle;
189 
190  bool _doubleSided : 1;
191  bool _flatShadingEnabled : 1;
192  bool _displacementEnabled : 1;
193  bool _smoothNormals : 1;
194  bool _packedSmoothNormals : 1;
195  bool _limitNormals : 1;
196  bool _sceneNormals : 1;
197  bool _flatNormals : 1;
198  bool _hasVaryingTopology : 1; // The prim's topology has changed since
199  // the prim was created
200 };
201 
202 
203 PXR_NAMESPACE_CLOSE_SCOPE
204 
205 #endif // HDST_MESH_H
virtual HDST_API HdMeshTopologySharedPtr GetTopology() const override
Topology (member) getter.
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:119
Descriptor to configure the drawItem(s) for a repr.
Definition: mesh.h:54
Tracks changes from the HdSceneDelegate, providing invalidation cues to the render engine...
Definition: changeTracker.h:55
The HdRenderParam is an opaque (to core Hydra) handle, to an object that is obtained from the render ...
virtual HDST_API void _InitRepr(TfToken const &reprToken, HdDirtyBits *dirtyBits) override
Initialize the given representation of this Rprim.
virtual HDST_API HdDirtyBits GetInitialDirtyBitsMask() const override
Returns the set of dirty bits that should be added to the change tracker for this prim...
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
Adapter class providing data exchange with the client scene graph.
HDST_API HdStMesh(SdfPath const &id, SdfPath const &instancerId=SdfPath())
Constructor.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
A subdivision surface or poly-mesh object.
Definition: mesh.h:55
virtual 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...
Hydra Schema for a subdivision surface or poly-mesh object.
Definition: mesh.h:105
Topology data for meshes.
Definition: meshTopology.h:55
virtual HDST_API void Sync(HdSceneDelegate *delegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits, TfToken const &reprToken) override
Pull invalidated scene data and prepare/update the renderable representation.
static HDST_API bool IsEnabledPackedNormals()
Returns whether packed (10_10_10 bits) normals to be used.