drawItem.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_DRAW_ITEM_H
25 #define PXR_IMAGING_HD_DRAW_ITEM_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hd/api.h"
29 #include "pxr/imaging/hd/version.h"
30 #include "pxr/imaging/hd/perfLog.h"
31 #include "pxr/imaging/hd/drawingCoord.h"
32 #include "pxr/imaging/hd/rprimSharedData.h"
33 
34 #include "pxr/imaging/hf/perfLog.h"
35 
36 #include "pxr/base/gf/matrix4d.h"
37 #include "pxr/base/gf/bbox3d.h"
38 #include "pxr/base/gf/vec2i.h"
39 #include "pxr/base/gf/vec4f.h"
40 
41 #include <iosfwd>
42 
43 PXR_NAMESPACE_OPEN_SCOPE
44 
66 class HdDrawItem {
67 public:
68  HF_MALLOC_TAG_NEW("new HdDrawItem");
69 
70  HD_API
71  HdDrawItem(HdRprimSharedData const *sharedData);
72  HD_API
73  virtual ~HdDrawItem();
74 
75  HD_API
76  SdfPath const &GetRprimID() const { return _sharedData->rprimID; }
77 
78  HD_API
79  GfBBox3d const & GetBounds() const { return _sharedData->bounds; }
80 
81  HD_API
82  GfRange3d const& GetExtent() const {
83  return _sharedData->bounds.GetRange();
84  }
85 
86  HD_API
87  GfMatrix4d const& GetMatrix() const {
88  return _sharedData->bounds.GetMatrix();
89  }
90 
92  HD_API
93  HdBufferArrayRangeSharedPtr const &GetConstantPrimvarRange() const {
94  return _sharedData->barContainer.Get(
95  _drawingCoord.GetConstantPrimvarIndex());
96  }
97 
99  HD_API
101  TF_VERIFY(_sharedData->instancerLevels != -1);
102  return _sharedData->instancerLevels;
103  }
104 
116  HD_API
117  HdBufferArrayRangeSharedPtr const &GetInstancePrimvarRange(int level) const {
118  return _sharedData->barContainer.Get(
119  _drawingCoord.GetInstancePrimvarIndex(level));
120  }
121 
123  HD_API
124  HdBufferArrayRangeSharedPtr const &GetInstanceIndexRange() const {
125  return _sharedData->barContainer.Get(
126  _drawingCoord.GetInstanceIndexIndex());
127  }
128 
130  HD_API
131  HdBufferArrayRangeSharedPtr const &GetElementPrimvarRange() const {
132  return _sharedData->barContainer.Get(
133  _drawingCoord.GetElementPrimvarIndex());
134  }
135 
137  HD_API
138  HdBufferArrayRangeSharedPtr const &GetTopologyRange() const {
139  return _sharedData->barContainer.Get(
140  _drawingCoord.GetTopologyIndex());
141  }
142 
143  HD_API
144  HdBufferArrayRangeSharedPtr const &GetTopologyVisibilityRange() const {
145  return _sharedData->barContainer.Get(
146  _drawingCoord.GetTopologyVisibilityIndex());
147  }
148 
150  HD_API
151  HdBufferArrayRangeSharedPtr const &GetVertexPrimvarRange() const {
152  return _sharedData->barContainer.Get(
153  _drawingCoord.GetVertexPrimvarIndex());
154  }
155 
157  HD_API
158  HdBufferArrayRangeSharedPtr const &GetVaryingPrimvarRange() const {
159  return _sharedData->barContainer.Get(
160  _drawingCoord.GetVaryingPrimvarIndex());
161  }
162 
163 
165  HD_API
166  HdBufferArrayRangeSharedPtr const &GetFaceVaryingPrimvarRange() const {
167  return _sharedData->barContainer.Get(
168  _drawingCoord.GetFaceVaryingPrimvarIndex());
169  }
170 
171  HD_API
172  HdDrawingCoord *GetDrawingCoord() {
173  return &_drawingCoord;
174  }
175 
177  HD_API
178  bool GetVisible() const { return _sharedData->visible; }
179 
180  HD_API
181  TfToken const& GetMaterialTag() const {
182  return _materialTag;
183  }
184 
185  HD_API
186  void SetMaterialTag(TfToken const &materialTag) {
187  _materialTag = materialTag;
188  }
189 
190  TopologyToPrimvarVector const &GetFvarTopologyToPrimvarVector() const {
191  return _sharedData->fvarTopologyToPrimvarVector;
192  }
193 
195  HD_API
196  bool HasInstancer() const {
197  TF_VERIFY(_sharedData->instancerLevels != -1);
198  return (_sharedData->instancerLevels > 0);
199  }
200 
206  HD_API
207  size_t GetBufferArraysHash() const;
208 
213  HD_API
214  size_t GetElementOffsetsHash() const;
215 
220  HD_API
221  bool IntersectsViewVolume(GfMatrix4d const &viewProjMatrix) const;
222 
223  HD_API
224  friend std::ostream &operator <<(std::ostream &out,
225  const HdDrawItem& self);
226 
227 protected:
228  // TfHash support.
229  template <class HashState>
230  friend void TfHashAppend(HashState &h, HdDrawItem const &di);
231 
233  HD_API
234  HdRprimSharedData const *_GetSharedData() const {
235  return _sharedData;
236  }
237 
241  HD_API
242  virtual size_t _GetBufferArraysHash() const;
243 
247  HD_API
248  virtual size_t _GetElementOffsetsHash() const;
249 
250 private:
251  // configuration of how to bundle the drawing coordinate for this draw item
252  // out of BARs in sharedData
253  HdDrawingCoord _drawingCoord;
254 
255  // pointer to shared data across reprs, owned by rprim:
256  // bufferArrayRanges, bounds, visibility
257  HdRprimSharedData const *_sharedData;
258 
263  TfToken _materialTag;
264 };
265 
266 
267 PXR_NAMESPACE_CLOSE_SCOPE
268 
269 #endif //PXR_IMAGING_HD_DRAW_ITEM_H
HD_API bool GetVisible() const
Returns the authored visibility, expressed by the delegate.
Definition: drawItem.h:178
HD_API HdBufferArrayRangeSharedPtr const & GetInstanceIndexRange() const
Returns a BufferRange of instance-index indirection.
Definition: drawItem.h:124
HD_API HdBufferArrayRangeSharedPtr const & GetElementPrimvarRange() const
Returns a BufferRange of element-Primvars.
Definition: drawItem.h:131
Basic type: 3-dimensional floating point range.
Definition: range3d.h:63
virtual HD_API size_t _GetElementOffsetsHash() const
Allows derived classes to return a hash of the element offsets of the underlying BARs they manage.
HD_API size_t GetElementOffsetsHash() const
Returns the hash of the element offsets of the underlying BARs.
HD_API int GetInstancePrimvarNumLevels() const
Returns the number of nested levels of instance primvars.
Definition: drawItem.h:100
HD_API HdBufferArrayRangeSharedPtr const & GetTopologyRange() const
Returns a BufferArrayRange of topology.
Definition: drawItem.h:138
HD_API HdRprimSharedData const * _GetSharedData() const
Returns the shared data.
Definition: drawItem.h:234
HD_API size_t GetBufferArraysHash() const
Returns the hash of the versions of underlying buffers.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
HD_API HdBufferArrayRangeSharedPtr const & GetConstantPrimvarRange() const
Returns a BufferRange of constant-Primvar.
Definition: drawItem.h:93
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:87
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
Definition: diagnostic.h:283
A tiny set of integers, which provides an indirection mapping from the conceptual space of an HdRprim...
Definition: drawingCoord.h:83
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
HD_API HdBufferArrayRangeSharedPtr const & GetVertexPrimvarRange() const
Returns a BufferArrayRange of vertex-primvars.
Definition: drawItem.h:151
virtual HD_API size_t _GetBufferArraysHash() const
Allows derived classes to return a hash of the versions of buffers they manage.
A draw item is a light-weight representation of an HdRprim's resources and material to be used for re...
Definition: drawItem.h:66
HD_API bool IntersectsViewVolume(GfMatrix4d const &viewProjMatrix) const
Tests the intersection with the view projection matrix.
HD_API HdBufferArrayRangeSharedPtr const & GetFaceVaryingPrimvarRange() const
Returns a BufferArrayRange of face-varying primvars.
Definition: drawItem.h:166
HD_API HdBufferArrayRangeSharedPtr const & GetVaryingPrimvarRange() const
Returns a BufferArrayRange of varying primvars.
Definition: drawItem.h:158
HD_API HdBufferArrayRangeSharedPtr const & GetInstancePrimvarRange(int level) const
Returns a BufferRange of instance-Primvars at level the level is assigned to nested instancers in a b...
Definition: drawItem.h:117
Basic type: arbitrarily oriented 3D bounding box.
Definition: bbox3d.h:84
HD_API bool HasInstancer() const
Returns true if the drawItem has instancer.
Definition: drawItem.h:196