All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 _sharedData->materialTag;
183  }
184 
185  TopologyToPrimvarVector const& GetFvarTopologyToPrimvarVector() const {
186  return _sharedData->fvarTopologyToPrimvarVector;
187  }
188 
190  HD_API
191  bool HasInstancer() const {
192  TF_VERIFY(_sharedData->instancerLevels != -1);
193  return (_sharedData->instancerLevels > 0);
194  }
195 
201  HD_API
202  size_t GetBufferArraysHash() const;
203 
208  HD_API
209  size_t GetElementOffsetsHash() const;
210 
215  HD_API
216  bool IntersectsViewVolume(GfMatrix4d const &viewProjMatrix) const;
217 
218  HD_API
219  friend std::ostream &operator <<(std::ostream &out,
220  const HdDrawItem& self);
221 
222 protected:
223  // TfHash support.
224  template <class HashState>
225  friend void TfHashAppend(HashState &h, HdDrawItem const &di);
226 
228  HD_API
229  HdRprimSharedData const *_GetSharedData() const {
230  return _sharedData;
231  }
232 
236  HD_API
237  virtual size_t _GetBufferArraysHash() const;
238 
242  HD_API
243  virtual size_t _GetElementOffsetsHash() const;
244 
245 private:
246  // configuration of how to bundle the drawing coordinate for this draw item
247  // out of BARs in sharedData
248  HdDrawingCoord _drawingCoord;
249 
250  // pointer to shared data across reprs, owned by rprim:
251  // bufferArrayRanges, bounds, visibility
252  HdRprimSharedData const *_sharedData;
253 };
254 
255 
256 PXR_NAMESPACE_CLOSE_SCOPE
257 
258 #endif //PXR_IMAGING_HD_DRAW_ITEM_H
Basic type: 3-dimensional floating point range.
Definition: range3d.h:64
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 bool IntersectsViewVolume(GfMatrix4d const &viewProjMatrix) const
Tests the intersection with the view projection matrix.
HD_API HdBufferArrayRangeSharedPtr const & GetElementPrimvarRange() const
Returns a BufferRange of element-Primvars.
Definition: drawItem.h:131
HD_API HdBufferArrayRangeSharedPtr const & GetConstantPrimvarRange() const
Returns a BufferRange of constant-Primvar.
Definition: drawItem.h:93
HD_API HdBufferArrayRangeSharedPtr const & GetVertexPrimvarRange() const
Returns a BufferArrayRange of vertex-primvars.
Definition: drawItem.h:151
HD_API bool HasInstancer() const
Returns true if the drawItem has instancer.
Definition: drawItem.h:191
HD_API HdBufferArrayRangeSharedPtr const & GetTopologyRange() const
Returns a BufferArrayRange of topology.
Definition: drawItem.h:138
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
#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:288
HD_API HdBufferArrayRangeSharedPtr const & GetInstanceIndexRange() const
Returns a BufferRange of instance-index indirection.
Definition: drawItem.h:124
HD_API HdRprimSharedData const * _GetSharedData() const
Returns the shared data.
Definition: drawItem.h:229
HD_API int GetInstancePrimvarNumLevels() const
Returns the number of nested levels of instance primvars.
Definition: drawItem.h:100
A draw item is a light-weight representation of an HdRprim&#39;s resources and material to be used for re...
Definition: drawItem.h:66
HD_API size_t GetElementOffsetsHash() const
Returns the hash of the element offsets of the underlying BARs.
virtual HD_API size_t _GetBufferArraysHash() const
Allows derived classes to return a hash of the versions of buffers they manage.
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
HD_API HdBufferArrayRangeSharedPtr const & GetVaryingPrimvarRange() const
Returns a BufferArrayRange of varying primvars.
Definition: drawItem.h:158
HD_API size_t GetBufferArraysHash() const
Returns the hash of the versions of underlying buffers.
HD_API HdBufferArrayRangeSharedPtr const & GetFaceVaryingPrimvarRange() const
Returns a BufferArrayRange of face-varying primvars.
Definition: drawItem.h:166
Basic type: arbitrarily oriented 3D bounding box.
Definition: bbox3d.h:84
HD_API bool GetVisible() const
Returns the authored visibility, expressed by the delegate.
Definition: drawItem.h:178