Loading...
Searching...
No Matches
colorizeSelectionTask.h
1//
2// Copyright 2019 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_IMAGING_HDX_COLORIZE_SELECTION_TASK_H
8#define PXR_IMAGING_HDX_COLORIZE_SELECTION_TASK_H
9
10#include "pxr/pxr.h"
11#include "pxr/base/gf/vec2f.h"
12#include "pxr/imaging/hdx/api.h"
13#include "pxr/imaging/hdx/task.h"
14
15#include "pxr/imaging/hgi/texture.h"
16
17PXR_NAMESPACE_OPEN_SCOPE
18
24{
26 : enableSelectionHighlight(false)
27 , enableLocateHighlight(false)
28 , selectionColor(0)
29 , locateColor(0)
30 , enableOutline(false)
31 , outlineRadius(5)
32 , primIdBufferPath()
33 , instanceIdBufferPath()
34 , elementIdBufferPath()
35 {}
36
37 bool enableSelectionHighlight;
38 bool enableLocateHighlight;
39 GfVec4f selectionColor;
40 GfVec4f locateColor;
41 bool enableOutline;
42 unsigned int outlineRadius;
43
44 SdfPath primIdBufferPath;
45 SdfPath instanceIdBufferPath;
46 SdfPath elementIdBufferPath;
47};
48
58{
59public:
61
62 HDX_API
64
65 HDX_API
67
69 bool IsConverged() const 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 // The core colorizing logic of this task: given the ID buffers and the
89 // selection buffer, produce a color output at each pixel.
90 void _ColorizeSelection();
91
92 GfVec4f _GetColorForMode(int mode) const;
93
94 // Utility function to update the shader uniform parameters.
95 // Returns true if the values were updated. False if unchanged.
96 bool _UpdateParameterBuffer();
97
98 // Create a new GPU texture for the provided format and pixel data.
99 // If an old texture exists it will be destroyed first.
100 void _CreateTexture(
101 int width,
102 int height,
103 HdFormat format,
104 void *data);
105
106 // This struct must match ParameterBuffer in outline.glslfx.
107 // Be careful to remember the std430 rules.
108 struct _ParameterBuffer
109 {
110 // Size of a colorIn texel - to iterate adjacent texels.
111 GfVec2f texelSize;
112 // Draws outline when enabled, or color overlay when disabled.
113 int enableOutline = 0;
114 // The outline radius (thickness).
115 int radius = 5;
116
117 bool operator==(const _ParameterBuffer& other) const {
118 return texelSize == other.texelSize &&
119 enableOutline == other.enableOutline &&
120 radius == other.radius;
121 }
122 };
123
124 // Incoming data
126
127 int _lastVersion;
128 bool _hasSelection;
129 VtIntArray _selectionOffsets;
130
131 HdRenderBuffer *_primId;
132 HdRenderBuffer *_instanceId;
133 HdRenderBuffer *_elementId;
134
135 uint8_t *_outputBuffer;
136 size_t _outputBufferSize;
137 bool _converged;
138
139 std::unique_ptr<class HdxFullscreenShader> _compositor;
140
141 _ParameterBuffer _parameterData;
142 HgiTextureHandle _texture;
143 bool _pipelineCreated;
144};
145
146// VtValue requirements
147HDX_API
148std::ostream& operator<<(std::ostream& out,
150HDX_API
151bool operator==(const HdxColorizeSelectionTaskParams& lhs,
153HDX_API
154bool operator!=(const HdxColorizeSelectionTaskParams& lhs,
156
157PXR_NAMESPACE_CLOSE_SCOPE
158
159#endif // PXR_IMAGING_HDX_COLORIZE_SELECTION_TASK_H
Basic type for a vector of 2 float components.
Definition: vec2f.h:46
Basic type for a vector of 4 float components.
Definition: vec4f.h:46
A render buffer is a handle to a data resource that can be rendered into, such as a 2d image for a dr...
Definition: renderBuffer.h:33
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 task for taking ID buffer data and turning it into a "selection overlay" that can be composited on ...
bool IsConverged() const override
Hooks for progressive rendering.
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 render pass resources.
HDX_API void Execute(HdTaskContext *ctx) override
Execute the task.
Base class for (some) tasks in Hdx that provides common progressive rendering and Hgi functionality.
Definition: task.h:28
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
Input parameters for HdxColorizeSelectionTask.