Loading...
Searching...
No Matches
colorizeSelectionTask.h
1//
2// Copyright 2019 Pixar
3//
4// Licensed under the Apache License, Version 2.0 (the "Apache License")
5// with the following modification; you may not use this file except in
6// compliance with the Apache License and the following modification to it:
7// Section 6. Trademarks. is deleted and replaced with:
8//
9// 6. Trademarks. This License does not grant permission to use the trade
10// names, trademarks, service marks, or product names of the Licensor
11// and its affiliates, except as required to comply with Section 4(c) of
12// the License and to reproduce the content of the NOTICE file.
13//
14// You may obtain a copy of the Apache License at
15//
16// http://www.apache.org/licenses/LICENSE-2.0
17//
18// Unless required by applicable law or agreed to in writing, software
19// distributed under the Apache License with the above modification is
20// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21// KIND, either express or implied. See the Apache License for the specific
22// language governing permissions and limitations under the Apache License.
23//
24#ifndef PXR_IMAGING_HDX_COLORIZE_SELECTION_TASK_H
25#define PXR_IMAGING_HDX_COLORIZE_SELECTION_TASK_H
26
27#include "pxr/pxr.h"
28#include "pxr/base/gf/vec2f.h"
29#include "pxr/imaging/hdx/api.h"
30#include "pxr/imaging/hdx/task.h"
31
32#include "pxr/imaging/hgi/texture.h"
33
34PXR_NAMESPACE_OPEN_SCOPE
35
41{
43 : enableSelectionHighlight(false)
44 , enableLocateHighlight(false)
45 , selectionColor(0)
46 , locateColor(0)
47 , enableOutline(false)
48 , outlineRadius(5)
49 , primIdBufferPath()
50 , instanceIdBufferPath()
51 , elementIdBufferPath()
52 {}
53
54 bool enableSelectionHighlight;
55 bool enableLocateHighlight;
56 GfVec4f selectionColor;
57 GfVec4f locateColor;
58 bool enableOutline;
59 unsigned int outlineRadius;
60
61 SdfPath primIdBufferPath;
62 SdfPath instanceIdBufferPath;
63 SdfPath elementIdBufferPath;
64};
65
75{
76public:
77 HDX_API
79
80 HDX_API
82
84 bool IsConverged() const override;
85
87 HDX_API
88 void Prepare(HdTaskContext* ctx,
89 HdRenderIndex* renderIndex) override;
90
92 HDX_API
93 void Execute(HdTaskContext* ctx) override;
94
95protected:
97 HDX_API
98 void _Sync(HdSceneDelegate* delegate,
99 HdTaskContext* ctx,
100 HdDirtyBits* dirtyBits) override;
101
102private:
103 // The core colorizing logic of this task: given the ID buffers and the
104 // selection buffer, produce a color output at each pixel.
105 void _ColorizeSelection();
106
107 GfVec4f _GetColorForMode(int mode) const;
108
109 // Utility function to update the shader uniform parameters.
110 // Returns true if the values were updated. False if unchanged.
111 bool _UpdateParameterBuffer();
112
113 // Create a new GPU texture for the provided format and pixel data.
114 // If an old texture exists it will be destroyed first.
115 void _CreateTexture(
116 int width,
117 int height,
118 HdFormat format,
119 void *data);
120
121 // This struct must match ParameterBuffer in outline.glslfx.
122 // Be careful to remember the std430 rules.
123 struct _ParameterBuffer
124 {
125 // Size of a colorIn texel - to iterate adjacent texels.
126 GfVec2f texelSize;
127 // Draws outline when enabled, or color overlay when disabled.
128 int enableOutline = 0;
129 // The outline radius (thickness).
130 int radius = 5;
131
132 bool operator==(const _ParameterBuffer& other) const {
133 return texelSize == other.texelSize &&
134 enableOutline == other.enableOutline &&
135 radius == other.radius;
136 }
137 };
138
139 // Incoming data
141
142 int _lastVersion;
143 bool _hasSelection;
144 VtIntArray _selectionOffsets;
145
146 HdRenderBuffer *_primId;
147 HdRenderBuffer *_instanceId;
148 HdRenderBuffer *_elementId;
149
150 uint8_t *_outputBuffer;
151 size_t _outputBufferSize;
152 bool _converged;
153
154 std::unique_ptr<class HdxFullscreenShader> _compositor;
155
156 _ParameterBuffer _parameterData;
157 HgiTextureHandle _texture;
158 bool _pipelineCreated;
159};
160
161// VtValue requirements
162HDX_API
163std::ostream& operator<<(std::ostream& out,
165HDX_API
166bool operator==(const HdxColorizeSelectionTaskParams& lhs,
168HDX_API
169bool operator!=(const HdxColorizeSelectionTaskParams& lhs,
171
172PXR_NAMESPACE_CLOSE_SCOPE
173
174#endif // PXR_IMAGING_HDX_COLORIZE_SELECTION_TASK_H
Basic type for a vector of 2 float components.
Definition: vec2f.h:63
Basic type for a vector of 4 float components.
Definition: vec4f.h:63
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:50
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:121
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:45
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
Input parameters for HdxColorizeSelectionTask.