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:
65 HDX_API
66 HdxBoundingBoxTask(HdSceneDelegate* delegate, const SdfPath& id);
67
68 HDX_API
69 ~HdxBoundingBoxTask() override;
70
72 HDX_API
73 void Prepare(HdTaskContext* ctx,
74 HdRenderIndex* renderIndex) override;
75
77 HDX_API
78 void Execute(HdTaskContext* ctx) override;
79
80protected:
82 HDX_API
83 void _Sync(HdSceneDelegate* delegate,
84 HdTaskContext* ctx,
85 HdDirtyBits* dirtyBits) override;
86
87private:
88 HdxBoundingBoxTask() = delete;
90 HdxBoundingBoxTask &operator =(const HdxBoundingBoxTask&) = delete;
91
92 // Utility function to create the shader for drawing dashed lines.
93 bool _CreateShaderResources();
94
95 // Utility function to create buffer resources.
96 bool _CreateBufferResources();
97
98 // Utility to create resource bindings
99 bool _CreateResourceBindings();
100
101 // Utility to create a pipeline.
102 bool _CreatePipeline(
103 const HgiTextureHandle& colorTexture,
104 const HgiTextureHandle& depthTexture);
105
106 // Utility to get the view and projection matrix from the camera.
107 GfMatrix4d _ComputeViewProjectionMatrix(
108 const HdStRenderPassState& hdStRenderPassState) const;
109
110 // Utility to set the shader constants for drawing.
111 void _UpdateShaderConstants(
112 HgiGraphicsCmds* gfxCmds,
113 const GfVec4i& gfxViewport,
114 const HdStRenderPassState& hdStRenderPassState);
115
116 // Create and submit the draw commands.
117 void _DrawBBoxes(
118 const HgiTextureHandle& colorTexture,
119 const HgiTextureHandle& depthTexture,
120 const HdStRenderPassState& hdStRenderPassState);
121
122 // Destroy shader program and the shader functions it holds.
123 void _DestroyShaderProgram();
124
125 // Print shader compile errors.
126 void _PrintCompileErrors();
127
128 HgiAttachmentDesc _colorAttachment;
129 HgiAttachmentDesc _depthAttachment;
130
131 HgiBufferHandle _vertexBuffer;
132 size_t _maxTransforms;
133 HgiBufferHandle _transformsBuffer;
134 HgiShaderProgramHandle _shaderProgram;
135 HgiResourceBindingsHandle _resourceBindings;
137
139};
140
141// VtValue requirements
142HDX_API
143std::ostream& operator<<(std::ostream& out, const HdxBoundingBoxTaskParams& pv);
144HDX_API
145bool operator==(const HdxBoundingBoxTaskParams& lhs,
146 const HdxBoundingBoxTaskParams& rhs);
147HDX_API
148bool operator!=(const HdxBoundingBoxTaskParams& lhs,
149 const HdxBoundingBoxTaskParams& rhs);
150
151PXR_NAMESPACE_CLOSE_SCOPE
152
153#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:104
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.