All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
34 PXR_NAMESPACE_OPEN_SCOPE
35 
41 {
43  : enableSelection(false)
44  , selectionColor(0)
45  , locateColor(0)
46  , enableOutline(false)
47  , outlineRadius(5)
48  , primIdBufferPath()
49  , instanceIdBufferPath()
50  , elementIdBufferPath()
51  {}
52 
53  bool enableSelection;
54  GfVec4f selectionColor;
55  GfVec4f locateColor;
56  bool enableOutline;
57  unsigned int outlineRadius;
58 
59  SdfPath primIdBufferPath;
60  SdfPath instanceIdBufferPath;
61  SdfPath elementIdBufferPath;
62 };
63 
73 {
74 public:
75  HDX_API
76  HdxColorizeSelectionTask(HdSceneDelegate* delegate, SdfPath const& id);
77 
78  HDX_API
79  ~HdxColorizeSelectionTask() override;
80 
82  bool IsConverged() const override;
83 
85  HDX_API
86  void Prepare(HdTaskContext* ctx,
87  HdRenderIndex* renderIndex) override;
88 
90  HDX_API
91  void Execute(HdTaskContext* ctx) override;
92 
93 protected:
95  HDX_API
96  void _Sync(HdSceneDelegate* delegate,
97  HdTaskContext* ctx,
98  HdDirtyBits* dirtyBits) override;
99 
100 private:
101  // The core colorizing logic of this task: given the ID buffers and the
102  // selection buffer, produce a color output at each pixel.
103  void _ColorizeSelection();
104 
105  GfVec4f _GetColorForMode(int mode) const;
106 
107  // Utility function to update the shader uniform parameters.
108  // Returns true if the values were updated. False if unchanged.
109  bool _UpdateParameterBuffer();
110 
111  // Create a new GPU texture for the provided format and pixel data.
112  // If an old texture exists it will be destroyed first.
113  void _CreateTexture(
114  int width,
115  int height,
116  HdFormat format,
117  void *data);
118 
119  // This struct must match ParameterBuffer in outline.glslfx.
120  // Be careful to remember the std430 rules.
121  struct _ParameterBuffer
122  {
123  // Size of a colorIn texel - to iterate adjacent texels.
124  GfVec2f texelSize;
125  // Draws outline when enabled, or color overlay when disabled.
126  int enableOutline = 0;
127  // The outline radius (thickness).
128  int radius = 5;
129 
130  bool operator==(const _ParameterBuffer& other) const {
131  return texelSize == other.texelSize &&
132  enableOutline == other.enableOutline &&
133  radius == other.radius;
134  }
135  };
136 
137  // Incoming data
139 
140  int _lastVersion;
141  bool _hasSelection;
142  VtIntArray _selectionOffsets;
143 
144  HdRenderBuffer *_primId;
145  HdRenderBuffer *_instanceId;
146  HdRenderBuffer *_elementId;
147 
148  uint8_t *_outputBuffer;
149  size_t _outputBufferSize;
150  bool _converged;
151 
152  std::unique_ptr<class HdxFullscreenShader> _compositor;
153 
154  _ParameterBuffer _parameterData;
155  HgiTextureHandle _texture;
156  bool _pipelineCreated;
157 };
158 
159 // VtValue requirements
160 HDX_API
161 std::ostream& operator<<(std::ostream& out,
163 HDX_API
165  const HdxColorizeSelectionTaskParams& rhs);
166 HDX_API
168  const HdxColorizeSelectionTaskParams& rhs);
169 
170 PXR_NAMESPACE_CLOSE_SCOPE
171 
172 #endif // PXR_IMAGING_HDX_COLORIZE_SELECTION_TASK_H
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:116
A task for taking ID buffer data and turning it into a &quot;selection overlay&quot; that can be composited o...
bool IsConverged() const override
Hooks for progressive rendering.
AR_API bool operator!=(const ArAssetInfo &lhs, const ArAssetInfo &rhs)
AR_API bool operator==(const ArAssetInfo &lhs, const ArAssetInfo &rhs)
HDX_API void Prepare(HdTaskContext *ctx, HdRenderIndex *renderIndex) override
Prepare the render pass resources.
Adapter class providing data exchange with the client scene graph.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:288
HDX_API void _Sync(HdSceneDelegate *delegate, HdTaskContext *ctx, HdDirtyBits *dirtyBits) override
Sync the render pass resources.
Basic type for a vector of 4 float components.
Definition: vec4f.h:63
Base class for (some) tasks in Hdx that provides common progressive rendering and Hgi functionality...
Definition: task.h:44
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
HDX_API void Execute(HdTaskContext *ctx) override
Execute the task.
Basic type for a vector of 2 float components.
Definition: vec2f.h:63
Input parameters for HdxColorizeSelectionTask.
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:51
VT_API bool operator==(VtDictionary const &, VtDictionary const &)
Equality comparison.