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:
60 HDX_API
62
63 HDX_API
65
67 bool IsConverged() const override;
68
70 HDX_API
71 void Prepare(HdTaskContext* ctx,
72 HdRenderIndex* renderIndex) override;
73
75 HDX_API
76 void Execute(HdTaskContext* ctx) override;
77
78protected:
80 HDX_API
81 void _Sync(HdSceneDelegate* delegate,
82 HdTaskContext* ctx,
83 HdDirtyBits* dirtyBits) override;
84
85private:
86 // The core colorizing logic of this task: given the ID buffers and the
87 // selection buffer, produce a color output at each pixel.
88 void _ColorizeSelection();
89
90 GfVec4f _GetColorForMode(int mode) const;
91
92 // Utility function to update the shader uniform parameters.
93 // Returns true if the values were updated. False if unchanged.
94 bool _UpdateParameterBuffer();
95
96 // Create a new GPU texture for the provided format and pixel data.
97 // If an old texture exists it will be destroyed first.
98 void _CreateTexture(
99 int width,
100 int height,
101 HdFormat format,
102 void *data);
103
104 // This struct must match ParameterBuffer in outline.glslfx.
105 // Be careful to remember the std430 rules.
106 struct _ParameterBuffer
107 {
108 // Size of a colorIn texel - to iterate adjacent texels.
109 GfVec2f texelSize;
110 // Draws outline when enabled, or color overlay when disabled.
111 int enableOutline = 0;
112 // The outline radius (thickness).
113 int radius = 5;
114
115 bool operator==(const _ParameterBuffer& other) const {
116 return texelSize == other.texelSize &&
117 enableOutline == other.enableOutline &&
118 radius == other.radius;
119 }
120 };
121
122 // Incoming data
124
125 int _lastVersion;
126 bool _hasSelection;
127 VtIntArray _selectionOffsets;
128
129 HdRenderBuffer *_primId;
130 HdRenderBuffer *_instanceId;
131 HdRenderBuffer *_elementId;
132
133 uint8_t *_outputBuffer;
134 size_t _outputBufferSize;
135 bool _converged;
136
137 std::unique_ptr<class HdxFullscreenShader> _compositor;
138
139 _ParameterBuffer _parameterData;
140 HgiTextureHandle _texture;
141 bool _pipelineCreated;
142};
143
144// VtValue requirements
145HDX_API
146std::ostream& operator<<(std::ostream& out,
148HDX_API
149bool operator==(const HdxColorizeSelectionTaskParams& lhs,
151HDX_API
152bool operator!=(const HdxColorizeSelectionTaskParams& lhs,
154
155PXR_NAMESPACE_CLOSE_SCOPE
156
157#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:104
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.