Loading...
Searching...
No Matches
boundingBoxTask.h
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
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
20#include "pxr/imaging/hgi/attachmentDesc.h"
21#include "pxr/imaging/hgi/buffer.h"
22#include "pxr/imaging/hgi/graphicsCmds.h"
23#include "pxr/imaging/hgi/graphicsPipeline.h"
24#include "pxr/imaging/hgi/resourceBindings.h"
25#include "pxr/imaging/hgi/shaderProgram.h"
26#include "pxr/imaging/hgi/texture.h"
27
28#include "pxr/usd/sdf/path.h"
29
30PXR_NAMESPACE_OPEN_SCOPE
31
33
39{
40 using BBoxVector = std::vector<GfBBox3d>;
41
42 HDX_API
44 : aovName()
45 , bboxes()
46 , color(1)
47 , dashSize(3)
48 {}
49
50 TfToken aovName;
51
52 // Data provided by the application
53 BBoxVector bboxes;
54 GfVec4f color;
55 float dashSize;
56};
57
63{
64public:
66
67 HDX_API
68 HdxBoundingBoxTask(HdSceneDelegate* delegate, const SdfPath& id);
69
70 HDX_API
71 ~HdxBoundingBoxTask() override;
72
74 HDX_API
75 void Prepare(HdTaskContext* ctx,
76 HdRenderIndex* renderIndex) override;
77
79 HDX_API
80 void Execute(HdTaskContext* ctx) override;
81
82protected:
84 HDX_API
85 void _Sync(HdSceneDelegate* delegate,
86 HdTaskContext* ctx,
87 HdDirtyBits* dirtyBits) override;
88
89private:
90 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;
139
141};
142
143// VtValue requirements
144HDX_API
145std::ostream& operator<<(std::ostream& out, const HdxBoundingBoxTaskParams& pv);
146HDX_API
147bool operator==(const HdxBoundingBoxTaskParams& lhs,
148 const HdxBoundingBoxTaskParams& rhs);
149HDX_API
150bool operator!=(const HdxBoundingBoxTaskParams& lhs,
151 const HdxBoundingBoxTaskParams& rhs);
152
153PXR_NAMESPACE_CLOSE_SCOPE
154
155#endif
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:71
Basic type for a vector of 4 float components.
Definition: vec4f.h:46
Basic type for a vector of 4 int components.
Definition: vec4i.h:44
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:105
Adapter class providing data exchange with the client scene graph.
A set of rendering parameters used among render passes.
A task for rendering bounding boxes.
HDX_API void _Sync(HdSceneDelegate *delegate, HdTaskContext *ctx, HdDirtyBits *dirtyBits) override
Sync the render pass resources.
HDX_API void Prepare(HdTaskContext *ctx, HdRenderIndex *renderIndex) override
Prepare the bounding box task resources.
HDX_API void Execute(HdTaskContext *ctx) override
Execute the bounding box task.
Base class for (some) tasks in Hdx that provides common progressive rendering and Hgi functionality.
Definition: task.h:28
A graphics API independent abstraction of graphics commands.
Definition: graphicsCmds.h:31
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
BoundingBoxTask parameters.
Describes the properties of a framebuffer attachment.