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 terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef HDX_BOUNDINGBOX_TASK_H
8 #define HDX_BOUNDINGBOX_TASK_H
9 
10 #include "pxr/pxr.h"
11 
12 #include "pxr/base/gf/matrix4f.h"
13 
14 #include "pxr/imaging/hdx/api.h"
15 #include "pxr/imaging/hdx/task.h"
16 #include "pxr/imaging/hdx/tokens.h"
17 
18 #include "pxr/imaging/hd/camera.h"
19 
21 #include "pxr/imaging/hgi/buffer.h"
27 
28 #include "pxr/usd/sdf/path.h"
29 
31 
33 
34 /// \class HdxBoundingBoxTaskParams
35 ///
36 /// BoundingBoxTask parameters.
37 ///
39 {
40  using BBoxVector = std::vector<GfBBox3d>;
41 
42  HDX_API
44  : aovName()
45  , bboxes()
46  , color(1)
47  , dashSize(3)
48  {}
49 
51 
52  // Data provided by the application
55  float dashSize;
56 };
57 
58 /// \class HdxBoundingBoxTask
59 ///
60 /// A task for rendering bounding boxes.
61 ///
63 {
64 public:
66 
67  HDX_API
68  HdxBoundingBoxTask(HdSceneDelegate* delegate, const SdfPath& id);
69 
70  HDX_API
71  ~HdxBoundingBoxTask() override;
72 
73  /// Prepare the bounding box task resources
74  HDX_API
75  void Prepare(HdTaskContext* ctx,
76  HdRenderIndex* renderIndex) override;
77 
78  /// Execute the bounding box task
79  HDX_API
80  void Execute(HdTaskContext* ctx) override;
81 
82 protected:
83  /// Sync the render pass resources
84  HDX_API
85  void _Sync(HdSceneDelegate* delegate,
86  HdTaskContext* ctx,
87  HdDirtyBits* dirtyBits) override;
88 
89 private:
90  HdxBoundingBoxTask() = delete;
91  HdxBoundingBoxTask(const HdxBoundingBoxTask&) = delete;
92  HdxBoundingBoxTask &operator =(const HdxBoundingBoxTask&) = delete;
93 
94  // Utility function to create the shader for drawing dashed lines.
95  bool _CreateShaderResources();
96 
97  // Utility function to create buffer resources.
98  bool _CreateBufferResources();
99 
100  // Utility to create resource bindings
101  bool _CreateResourceBindings();
102 
103  // Utility to create a pipeline.
104  bool _CreatePipeline(
105  const HgiTextureHandle& colorTexture,
106  const HgiTextureHandle& depthTexture);
107 
108  // Utility to get the view and projection matrix from the camera.
109  GfMatrix4d _ComputeViewProjectionMatrix(
110  const HdStRenderPassState& hdStRenderPassState) const;
111 
112  // Utility to set the shader constants for drawing.
113  void _UpdateShaderConstants(
114  HgiGraphicsCmds* gfxCmds,
115  const GfVec4i& gfxViewport,
116  const HdStRenderPassState& hdStRenderPassState);
117 
118  // Create and submit the draw commands.
119  void _DrawBBoxes(
120  const HgiTextureHandle& colorTexture,
121  const HgiTextureHandle& depthTexture,
122  const HdStRenderPassState& hdStRenderPassState);
123 
124  // Destroy shader program and the shader functions it holds.
125  void _DestroyShaderProgram();
126 
127  // Print shader compile errors.
128  void _PrintCompileErrors();
129 
130  HgiAttachmentDesc _colorAttachment;
131  HgiAttachmentDesc _depthAttachment;
132 
133  HgiBufferHandle _vertexBuffer;
134  size_t _maxTransforms;
135  HgiBufferHandle _transformsBuffer;
136  HgiShaderProgramHandle _shaderProgram;
137  HgiResourceBindingsHandle _resourceBindings;
138  HgiGraphicsPipelineHandle _pipeline;
139 
140  HdxBoundingBoxTaskParams _params;
141 };
142 
143 // VtValue requirements
144 HDX_API
145 std::ostream& operator<<(std::ostream& out, const HdxBoundingBoxTaskParams& pv);
146 HDX_API
147 bool operator==(const HdxBoundingBoxTaskParams& lhs,
148  const HdxBoundingBoxTaskParams& rhs);
149 HDX_API
150 bool operator!=(const HdxBoundingBoxTaskParams& lhs,
151  const HdxBoundingBoxTaskParams& rhs);
152 
154 
155 #endif
Definition: vec4i.h:43
uint32_t HdDirtyBits
Definition: types.h:143
int HgiHandle< class HgiTexture > HgiTextureHandle
HDX_API std::ostream & operator<<(std::ostream &out, const HdxBoundingBoxTaskParams &pv)
#define HDX_API
Definition: api.h:23
HDX_API void Prepare(HdTaskContext *ctx, HdRenderIndex *renderIndex) override
Prepare the bounding box task resources.
Definition: token.h:70
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:273
std::unordered_map< TfToken, VtValue, TfToken::HashFunctor > HdTaskContext
Definition: renderIndex.h:61
Definition: vec4f.h:45
Definition: task.h:27
std::vector< GfBBox3d > BBoxVector
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
GLuint color
Definition: glcorearb.h:1261
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
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.