7#ifndef PXR_IMAGING_HD_ST_MESH_H
8#define PXR_IMAGING_HD_ST_MESH_H
11#include "pxr/imaging/hdSt/api.h"
12#include "pxr/imaging/hd/version.h"
13#include "pxr/imaging/hd/changeTracker.h"
14#include "pxr/imaging/hd/drawingCoord.h"
15#include "pxr/imaging/hd/mesh.h"
16#include "pxr/imaging/hd/perfLog.h"
18#include "pxr/usd/sdf/path.h"
23PXR_NAMESPACE_OPEN_SCOPE
29using HdSt_VertexAdjacencyBuilderSharedPtr =
30 std::shared_ptr<class HdSt_VertexAdjacencyBuilder>;
31using HdBufferSourceSharedPtr = std::shared_ptr<class HdBufferSource>;
32using HdSt_MeshTopologySharedPtr = std::shared_ptr<class HdSt_MeshTopology>;
34using HdStResourceRegistrySharedPtr =
35 std::shared_ptr<class HdStResourceRegistry>;
42 HF_MALLOC_TAG_NEW(
"new HdStMesh");
57 HdDirtyBits *dirtyBits,
58 TfToken const &reprToken)
override;
84 HdDirtyBits *dirtyBitsState);
86 HdBufferArrayRangeSharedPtr
87 _GetSharedPrimvarRange(uint64_t primvarId,
88 HdBufferSpecVector
const &updatedOrAddedSpecs,
89 HdBufferSpecVector
const &removedSpecs,
90 HdBufferArrayRangeSharedPtr
const &curRange,
91 bool * isFirstInstance,
92 HdStResourceRegistrySharedPtr
const &resourceRegistry)
const;
95 const SdfPath &materialId)
const;
98 const HdSt_MeshTopologySharedPtr &topology)
const;
100 bool _MaterialHasLimitSurface(
const HdRenderIndex &renderIndex,
101 const SdfPath &materialId)
const;
106 bool _UseSmoothNormals(HdSt_MeshTopologySharedPtr
const& topology)
const;
112 HdStDrawItem *drawItem,
113 HdDirtyBits *dirtyBits,
115 const HdReprSharedPtr &repr,
117 bool requireSmoothNormals,
118 bool requireFlatNormals,
119 int geomSubsetDescIndex);
123 HdStDrawItem *drawItem,
129 bool updateMaterialNetworkShader,
130 bool updateGeometricShader);
137 HdStDrawItem *drawItem,
138 HdDirtyBits *dirtyBits,
140 const HdReprSharedPtr &repr,
142 int geomSubsetDescIndex);
146 HdStDrawItem *drawItem,
148 const HdReprSharedPtr &repr,
149 const HdGeomSubsets &geomSubsets,
150 size_t oldNumGeomSubsets);
152 void _CreateTopologyRangeForGeomSubset(
153 HdStResourceRegistrySharedPtr resourceRegistry,
156 HdStDrawItem *drawItem,
158 HdBufferSourceSharedPtr indicesSource,
159 HdBufferSourceSharedPtr fvarIndicesSource,
160 HdBufferSourceSharedPtr geomSubsetFaceIndicesHelperSource,
161 const VtIntArray &faceIndices,
165 const HdReprSharedPtr &repr,
167 HdStDrawItem *drawItem,
168 int geomSubsetDescIndex,
169 HdDirtyBits *dirtyBits,
171 HdSt_MeshTopologySharedPtr topology);
173 void _PopulateAdjacency(
174 HdStResourceRegistrySharedPtr
const &resourceRegistry);
178 const HdReprSharedPtr &repr,
180 HdStDrawItem *drawItem,
181 int geomSubsetDescIndex,
182 HdDirtyBits *dirtyBits,
183 bool requireSmoothNormals);
187 const HdReprSharedPtr &repr,
189 HdStDrawItem *drawItem,
190 int geomSubsetDescIndex,
191 HdDirtyBits *dirtyBits);
195 const HdReprSharedPtr &repr,
197 HdStDrawItem *drawItem,
198 int geomSubsetDescIndex,
199 HdDirtyBits *dirtyBits,
200 bool requireFlatNormals);
209 class _FvarTopologyTracker
212 const TopologyToPrimvarVector & GetTopologyToPrimvarVector()
const {
217 void AddOrUpdateTopology(
const TfToken &primvar,
218 const VtIntArray &topology) {
219 for (
size_t i = 0; i < _topologies.size(); ++i) {
221 if (_topologies[i].first == topology) {
223 if (std::find(_topologies[i].second.begin(),
224 _topologies[i].second.end(),
225 primvar) == _topologies[i].second.end()) {
227 RemovePrimvar(primvar);
228 _topologies[i].second.push_back(primvar);
235 RemovePrimvar(primvar);
236 _topologies.push_back(
237 std::pair<VtIntArray, std::vector<TfToken>>(
238 topology, {primvar}));
242 void RemovePrimvar(
const TfToken &primvar) {
243 for (
size_t i = 0; i < _topologies.size(); ++i) {
244 _topologies[i].second.erase(std::find(
245 _topologies[i].second.begin(),
246 _topologies[i].second.end(),
247 primvar), _topologies[i].second.end());
254 void RemoveUnusedTopologies() {
255 _topologies.erase(std::remove_if(
256 _topologies.begin(), _topologies.end(), NoPrimvars),
262 int GetChannelFromPrimvar(
const TfToken &primvar)
const {
263 for (
size_t i = 0; i < _topologies.size(); ++i) {
264 if (std::find(_topologies[i].second.begin(),
265 _topologies[i].second.end(),
267 _topologies[i].second.end()) {
275 std::vector<VtIntArray> GetFvarTopologies()
const {
276 std::vector<VtIntArray> fvarTopologies;
277 for (
const auto& it : _topologies) {
278 fvarTopologies.push_back(it.first);
280 return fvarTopologies;
283 size_t GetNumTopologies()
const {
284 return _topologies.size();
290 static bool NoPrimvars(
const std::pair<VtIntArray, std::vector<TfToken>>
292 return topology.second.empty();
295 TopologyToPrimvarVector _topologies;
300 HullTopology = HdDrawingCoord::CustomSlotsBegin,
308 enum DirtyBits : HdDirtyBits {
309 DirtySmoothNormals = HdChangeTracker::CustomBitsBegin,
310 DirtyFlatNormals = (DirtySmoothNormals << 1),
311 DirtyIndices = (DirtyFlatNormals << 1),
312 DirtyHullIndices = (DirtyIndices << 1),
313 DirtyPointsIndices = (DirtyHullIndices << 1)
316 HdSt_MeshTopologySharedPtr _topology;
317 HdSt_VertexAdjacencyBuilderSharedPtr _vertexAdjacencyBuilder;
319 HdTopology::ID _topologyId;
320 HdTopology::ID _vertexPrimvarId;
321 HdDirtyBits _customDirtyBitsInUse;
323 HdType _pointsDataType;
324 HdInterpolation _sceneNormalsInterpolation;
325 HdCullStyle _cullStyle;
326 bool _hasMirroredTransform : 1;
327 bool _doubleSided : 1;
328 bool _flatShadingEnabled : 1;
329 bool _displacementEnabled : 1;
330 bool _limitNormals : 1;
331 bool _sceneNormals : 1;
332 bool _hasVaryingTopology : 1;
334 bool _displayOpacity : 1;
335 bool _occludedSelectionShowsThrough : 1;
336 bool _pointsShadingEnabled : 1;
338 std::unique_ptr<_FvarTopologyTracker> _fvarTopologyTracker;
342PXR_NAMESPACE_CLOSE_SCOPE
Tracks changes from the HdSceneDelegate, providing invalidation cues to the render engine.
Hydra Schema for a subdivision surface or poly-mesh object.
Topology data for meshes.
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
The HdRenderParam is an opaque (to core Hydra) handle, to an object that is obtained from the render ...
Adapter class providing data exchange with the client scene graph.
A subdivision surface or poly-mesh object.
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.
HDST_API HdDirtyBits GetInitialDirtyBitsMask() const override
Returns the set of dirty bits that should be added to the change tracker for this prim,...
HDST_API HdMeshTopologySharedPtr GetTopology() const override
Topology (member) getter.
static HDST_API bool IsEnabledPackedNormals()
Returns whether packed (10_10_10 bits) normals to be used.
HDST_API void Finalize(HdRenderParam *renderParam) override
Finalizes object resources.
A path value used to locate objects in layers or scenegraphs.
Token for efficient comparison, assignment, and hashing of known strings.
Descriptor to configure the drawItem(s) for a repr.