HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
drawItem.h
Go to the documentation of this file.
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_ST_DRAW_ITEM_H
25 #define PXR_IMAGING_HD_ST_DRAW_ITEM_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdSt/api.h"
29 
31 
33 
34 
36  std::shared_ptr<class HdSt_GeometricShader>;
38  std::shared_ptr<class HdSt_MaterialNetworkShader>;
39 
40 class HdStDrawItem : public HdDrawItem
41 {
42 public:
43  HF_MALLOC_TAG_NEW("new HdStDrawItem");
44 
45  HDST_API
46  HdStDrawItem(HdRprimSharedData const *sharedData);
47 
48  HDST_API
49  ~HdStDrawItem() override;
50 
51  /// Returns true if the drawItem has an instancer.
52  bool HasInstancer() const {
53  TF_VERIFY(_GetSharedData()->instancerLevels != -1);
54  return (_GetSharedData()->instancerLevels > 0);
55  }
56 
57  /// Returns the number of nested levels of instance primvars.
59  TF_VERIFY(_GetSharedData()->instancerLevels != -1);
61  }
62 
63  /// Returns a BufferArrayRange of instance primvars at \p level
64  /// the level is assigned to nested instancers in a bottom-up manner.
65  ///
66  /// example: (numLevels = 2)
67  ///
68  /// instancerA (level = 1)
69  /// |
70  /// +-- instancerB (level = 0)
71  /// |
72  /// +-- mesh_prototype
73  ///
77  _GetDrawingCoord().GetInstancePrimvarIndex(level));
78  }
79 
80  /// Returns instance-index indirection BAR.
83  _GetDrawingCoord().GetInstanceIndexIndex());
84  }
85 
86  /// Returns constant primvar BAR.
89  _GetDrawingCoord().GetConstantPrimvarIndex());
90  }
91 
92  /// Returns element primvar BAR.
95  _GetDrawingCoord().GetElementPrimvarIndex());
96  }
97 
98  /// Returns vertex primvar BAR.
100  return _GetSharedData()->barContainer.Get(
101  _GetDrawingCoord().GetVertexPrimvarIndex());
102  }
103 
104  /// Returns varying primvar BAR.
106  return _GetSharedData()->barContainer.Get(
107  _GetDrawingCoord().GetVaryingPrimvarIndex());
108  }
109 
110  /// Returns face varying primvar BAR.
112  return _GetSharedData()->barContainer.Get(
113  _GetDrawingCoord().GetFaceVaryingPrimvarIndex());
114  }
115 
116  /// Returns topology BAR.
118  return _GetSharedData()->barContainer.Get(
119  _GetDrawingCoord().GetTopologyIndex());
120  }
121 
122  /// Returns topological visibility BAR (e.g. per-face, per-point, etc.)
124  return _GetSharedData()->barContainer.Get(
125  _GetDrawingCoord().GetTopologyVisibilityIndex());
126  }
127 
128  /// Returns mapping from refined fvar channels to named primvar.
131  }
132 
134  _geometricShader = shader;
135  }
136 
138  return _geometricShader;
139  }
140 
143  return _materialNetworkShader;
144  }
145 
148  _materialNetworkShader = shader;
149  }
150 
151  bool GetMaterialIsFinal() const {
152  return _materialIsFinal;
153  }
154 
155  void SetMaterialIsFinal(bool isFinal) {
156  _materialIsFinal = isFinal;
157  }
158 
159  /// Tests intersection with the specified view projection matrix.
160  /// Returns true if this drawItem is in the frustum.
161  ///
162  /// XXX: Currently if this drawitem uses instancing, always returns true.
163  HDST_API
164  bool IntersectsViewVolume(GfMatrix4d const &viewProjMatrix) const;
165 
166  /// Returns the hash of the versions of underlying buffers. When the
167  /// hash changes, it means the drawing coord might have been reassigned,
168  /// so any drawing coord caching buffer (e.g. indirect dispatch buffer)
169  /// has to be rebuilt at the moment.
170  /// Note that this value is a hash, not sequential.
171  HDST_API
172  size_t GetBufferArraysHash() const;
173 
174  /// Returns the hash of the element offsets of the underlying BARs.
175  /// When the hash changes, it means that any drawing coord caching
176  /// buffer (e.g. the indirect dispatch buffer) has to be rebuilt.
177  /// Note that this value is a hash, not sequential.
178  HDST_API
179  size_t GetElementOffsetsHash() const;
180 
181 private:
182  HdSt_GeometricShaderSharedPtr _geometricShader;
183  HdSt_MaterialNetworkShaderSharedPtr _materialNetworkShader;
184  bool _materialIsFinal;
185 };
186 
187 
189 
190 #endif //PXR_IMAGING_HD_ST_DRAW_ITEM_H
HDST_API bool IntersectsViewVolume(GfMatrix4d const &viewProjMatrix) const
TopologyToPrimvarVector const & GetFvarTopologyToPrimvarVector() const
Returns mapping from refined fvar channels to named primvar.
Definition: drawItem.h:129
HD_API HdBufferArrayRangeSharedPtr const & Get(int index) const
std::shared_ptr< class HdSt_MaterialNetworkShader > HdSt_MaterialNetworkShaderSharedPtr
Definition: drawItem.h:38
GLint level
Definition: glcorearb.h:108
std::shared_ptr< class HdSt_GeometricShader > HdSt_GeometricShaderSharedPtr
Definition: drawItem.h:36
HdDrawingCoord const & _GetDrawingCoord() const
Returns the drawingCoord.
Definition: drawItem.h:104
HdRprimSharedData const * _GetSharedData() const
Returns the shared data.
Definition: drawItem.h:109
HdBufferArrayRangeSharedPtr const & GetInstancePrimvarRange(int level) const
Definition: drawItem.h:75
void SetGeometricShader(HdSt_GeometricShaderSharedPtr const &shader)
Definition: drawItem.h:133
void SetMaterialNetworkShader(HdSt_MaterialNetworkShaderSharedPtr const &shader)
Definition: drawItem.h:146
HdBufferArrayRangeContainer barContainer
HdBufferArrayRangeSharedPtr const & GetVaryingPrimvarRange() const
Returns varying primvar BAR.
Definition: drawItem.h:105
HdBufferArrayRangeSharedPtr const & GetElementPrimvarRange() const
Returns element primvar BAR.
Definition: drawItem.h:93
void SetMaterialIsFinal(bool isFinal)
Definition: drawItem.h:155
TopologyToPrimvarVector fvarTopologyToPrimvarVector
HdBufferArrayRangeSharedPtr const & GetFaceVaryingPrimvarRange() const
Returns face varying primvar BAR.
Definition: drawItem.h:111
HdSt_MaterialNetworkShaderSharedPtr const & GetMaterialNetworkShader() const
Definition: drawItem.h:142
HDST_API ~HdStDrawItem() override
HdBufferArrayRangeSharedPtr const & GetVertexPrimvarRange() const
Returns vertex primvar BAR.
Definition: drawItem.h:99
int GetInstancePrimvarNumLevels() const
Returns the number of nested levels of instance primvars.
Definition: drawItem.h:58
HDST_API size_t GetBufferArraysHash() const
HF_MALLOC_TAG_NEW("new HdStDrawItem")
HdSt_GeometricShaderSharedPtr const & GetGeometricShader() const
Definition: drawItem.h:137
GLuint shader
Definition: glcorearb.h:785
std::vector< std::pair< VtIntArray, std::vector< TfToken >>> TopologyToPrimvarVector
HdBufferArrayRangeSharedPtr const & GetTopologyVisibilityRange() const
Returns topological visibility BAR (e.g. per-face, per-point, etc.)
Definition: drawItem.h:123
HDST_API size_t GetElementOffsetsHash() const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
#define HDST_API
Definition: api.h:40
HdBufferArrayRangeSharedPtr const & GetInstanceIndexRange() const
Returns instance-index indirection BAR.
Definition: drawItem.h:81
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
std::shared_ptr< HdBufferArrayRange > HdBufferArrayRangeSharedPtr
Definition: bufferArray.h:44
HDST_API HdStDrawItem(HdRprimSharedData const *sharedData)
HdBufferArrayRangeSharedPtr const & GetTopologyRange() const
Returns topology BAR.
Definition: drawItem.h:117
bool GetMaterialIsFinal() const
Definition: drawItem.h:151
bool HasInstancer() const
Returns true if the drawItem has an instancer.
Definition: drawItem.h:52
HdBufferArrayRangeSharedPtr const & GetConstantPrimvarRange() const
Returns constant primvar BAR.
Definition: drawItem.h:87