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 HD_DRAW_ITEM_H
25 #define 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 &GetFaceVaryingPrimvarRange() const {
159  return _sharedData->barContainer.Get(
160  _drawingCoord.GetFaceVaryingPrimvarIndex());
161  }
162 
163  HD_API
164  HdDrawingCoord *GetDrawingCoord() {
165  return &_drawingCoord;
166  }
167 
169  HD_API
170  bool GetVisible() const { return _sharedData->visible; }
171 
173  HD_API
174  bool HasInstancer() const {
175  TF_VERIFY(_sharedData->instancerLevels != -1);
176  return (_sharedData->instancerLevels > 0);
177  }
178 
184  HD_API
185  size_t GetBufferArraysHash() const;
186 
191  HD_API
192  bool IntersectsViewVolume(GfMatrix4d const &viewProjMatrix) const;
193 
194  HD_API
195  friend std::ostream &operator <<(std::ostream &out,
196  const HdDrawItem& self);
197 
198 protected:
199 
201  HD_API
202  HdRprimSharedData const *_GetSharedData() const {
203  return _sharedData;
204  }
205 
209  HD_API
210  virtual size_t _GetBufferArraysHash() const;
211 
212 private:
213  // configuration of how to bundle the drawing coordinate for this draw item
214  // out of BARs in sharedData
215  HdDrawingCoord _drawingCoord;
216 
217  // pointer to shared data across reprs, owned by rprim:
218  // bufferArrayRanges, bounds, visibility
219  HdRprimSharedData const *_sharedData;
220 };
221 
222 
223 PXR_NAMESPACE_CLOSE_SCOPE
224 
225 #endif //HD_DRAW_ITEM_H
Basic type: 3-dimensional floating point range.
Definition: range3d.h:64
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:174
HD_API HdBufferArrayRangeSharedPtr const & GetTopologyRange() const
Returns a BufferArrayRange of topology.
Definition: drawItem.h:138
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:289
A tiny set of integers, which provides an indirection mapping from the conceptual space of an HdRprim...
Definition: drawingCoord.h:81
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
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:202
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
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 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:158
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:170