HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
boundingBoxTask.h
Go to the documentation of this file.
1 //
2 // Copyright 2022 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 HDX_BOUNDINGBOX_TASK_H
25 #define HDX_BOUNDINGBOX_TASK_H
26 
27 #include "pxr/pxr.h"
28 
29 #include "pxr/base/gf/matrix4f.h"
30 
31 #include "pxr/imaging/hdx/api.h"
32 #include "pxr/imaging/hdx/task.h"
33 #include "pxr/imaging/hdx/tokens.h"
34 
35 #include "pxr/imaging/hd/camera.h"
36 
38 #include "pxr/imaging/hgi/buffer.h"
44 
45 #include "pxr/usd/sdf/path.h"
46 
48 
50 
51 /// \class HdxBoundingBoxTaskParams
52 ///
53 /// BoundingBoxTask parameters.
54 ///
56 {
57  using BBoxVector = std::vector<GfBBox3d>;
58 
59  HDX_API
61  : aovName()
62  , bboxes()
63  , color(1)
64  , dashSize(3)
65  {}
66 
68 
69  // Data provided by the application
72  float dashSize;
73 };
74 
75 /// \class HdxBoundingBoxTask
76 ///
77 /// A task for rendering bounding boxes.
78 ///
80 {
81 public:
82  HDX_API
83  HdxBoundingBoxTask(HdSceneDelegate* delegate, const SdfPath& id);
84 
85  HDX_API
86  ~HdxBoundingBoxTask() override;
87 
88  /// Prepare the bounding box task resources
89  HDX_API
90  void Prepare(HdTaskContext* ctx,
91  HdRenderIndex* renderIndex) override;
92 
93  /// Execute the bounding box task
94  HDX_API
95  void Execute(HdTaskContext* ctx) override;
96 
97 protected:
98  /// Sync the render pass resources
99  HDX_API
100  void _Sync(HdSceneDelegate* delegate,
101  HdTaskContext* ctx,
102  HdDirtyBits* dirtyBits) override;
103 
104 private:
105  HdxBoundingBoxTask() = delete;
106  HdxBoundingBoxTask(const HdxBoundingBoxTask&) = delete;
107  HdxBoundingBoxTask &operator =(const HdxBoundingBoxTask&) = delete;
108 
109  // Utility function to create the shader for drawing dashed lines.
110  bool _CreateShaderResources();
111 
112  // Utility function to create buffer resources.
113  bool _CreateBufferResources();
114 
115  // Utility to create resource bindings
116  bool _CreateResourceBindings();
117 
118  // Utility to create a pipeline.
119  bool _CreatePipeline(
120  const HgiTextureHandle& colorTexture,
121  const HgiTextureHandle& depthTexture);
122 
123  // Utility to get the view and projection matrix from the camera.
124  GfMatrix4d _ComputeViewProjectionMatrix(
125  const HdStRenderPassState& hdStRenderPassState) const;
126 
127  // Utility to set the shader constants for drawing.
128  void _UpdateShaderConstants(
129  HgiGraphicsCmds* gfxCmds,
130  const GfVec4i& gfxViewport,
131  const HdStRenderPassState& hdStRenderPassState);
132 
133  // Create and submit the draw commands.
134  void _DrawBBoxes(
135  const HgiTextureHandle& colorTexture,
136  const HgiTextureHandle& depthTexture,
137  const HdStRenderPassState& hdStRenderPassState);
138 
139  // Destroy shader program and the shader functions it holds.
140  void _DestroyShaderProgram();
141 
142  // Print shader compile errors.
143  void _PrintCompileErrors();
144 
145  HgiAttachmentDesc _colorAttachment;
146  HgiAttachmentDesc _depthAttachment;
147 
148  HgiBufferHandle _vertexBuffer;
149  size_t _maxTransforms;
150  HgiBufferHandle _transformsBuffer;
151  HgiShaderProgramHandle _shaderProgram;
152  HgiResourceBindingsHandle _resourceBindings;
153  HgiGraphicsPipelineHandle _pipeline;
154 
155  HdxBoundingBoxTaskParams _params;
156 };
157 
158 // VtValue requirements
159 HDX_API
160 std::ostream& operator<<(std::ostream& out, const HdxBoundingBoxTaskParams& pv);
161 HDX_API
162 bool operator==(const HdxBoundingBoxTaskParams& lhs,
163  const HdxBoundingBoxTaskParams& rhs);
164 HDX_API
165 bool operator!=(const HdxBoundingBoxTaskParams& lhs,
166  const HdxBoundingBoxTaskParams& rhs);
167 
169 
170 #endif
Definition: vec4i.h:60
uint32_t HdDirtyBits
Definition: types.h:158
int HgiHandle< class HgiTexture > HgiTextureHandle
HDX_API std::ostream & operator<<(std::ostream &out, const HdxBoundingBoxTaskParams &pv)
#define HDX_API
Definition: api.h:40
HDX_API void Prepare(HdTaskContext *ctx, HdRenderIndex *renderIndex) override
Prepare the bounding box task resources.
Definition: token.h:87
bool operator!=(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Inequality operator, does exact floating point comparisons.
Definition: Mat3.h:556
HDX_API void Execute(HdTaskContext *ctx) override
Execute the bounding box task.
Definition: path.h:290
std::unordered_map< TfToken, VtValue, TfToken::HashFunctor > HdTaskContext
Definition: renderIndex.h:77
Definition: vec4f.h:62
Definition: task.h:44
std::vector< GfBBox3d > BBoxVector
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
GLuint color
Definition: glcorearb.h:1261
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
HDX_API ~HdxBoundingBoxTask() override
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
Definition: Mat3.h:542
HDX_API void _Sync(HdSceneDelegate *delegate, HdTaskContext *ctx, HdDirtyBits *dirtyBits) override
Sync the render pass resources.