HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
colorizeSelectionTask.h
Go to the documentation of this file.
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 
33 
35 
36 /// \class HdxColorizeSelectionTaskParams
37 ///
38 /// Input parameters for HdxColorizeSelectionTask
39 ///
41 {
44  , enableLocateHighlight(false)
45  , selectionColor(0)
46  , locateColor(0)
47  , enableOutline(false)
48  , outlineRadius(5)
52  {}
53 
59  unsigned int outlineRadius;
60 
64 };
65 
66 /// \class HdxColorizeSelectionTask
67 ///
68 /// A task for taking ID buffer data and turning it into a "selection overlay"
69 /// that can be composited on top of hydra's color output.
70 ///
71 /// If enableOutline is true then instead of overlaying the ID buffer as is, an
72 /// outline with thickness of outlineRadius pixels around the areas with IDs
73 /// will be overlaid. Otherwise, the ID buffer will be overlaid as is.
75 {
76 public:
77  HDX_API
78  HdxColorizeSelectionTask(HdSceneDelegate* delegate, SdfPath const& id);
79 
80  HDX_API
81  ~HdxColorizeSelectionTask() override;
82 
83  /// Hooks for progressive rendering.
84  bool IsConverged() const override;
85 
86  /// Prepare the render pass resources
87  HDX_API
88  void Prepare(HdTaskContext* ctx,
89  HdRenderIndex* renderIndex) override;
90 
91  /// Execute the task
92  HDX_API
93  void Execute(HdTaskContext* ctx) override;
94 
95 protected:
96  /// Sync the render pass resources
97  HDX_API
98  void _Sync(HdSceneDelegate* delegate,
99  HdTaskContext* ctx,
100  HdDirtyBits* dirtyBits) override;
101 
102 private:
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,
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
162 HDX_API
163 std::ostream& operator<<(std::ostream& out,
165 HDX_API
167  const HdxColorizeSelectionTaskParams& rhs);
168 HDX_API
170  const HdxColorizeSelectionTaskParams& rhs);
171 
173 
174 #endif // PXR_IMAGING_HDX_COLORIZE_SELECTION_TASK_H
HDX_API bool operator==(const HdxColorizeSelectionTaskParams &lhs, const HdxColorizeSelectionTaskParams &rhs)
HdFormat
Definition: types.h:423
HDX_API std::ostream & operator<<(std::ostream &out, const HdxColorizeSelectionTaskParams &pv)
uint32_t HdDirtyBits
Definition: types.h:158
int HgiHandle< class HgiTexture > HgiTextureHandle
#define HDX_API
Definition: api.h:40
GLint GLsizei GLsizei height
Definition: glcorearb.h:103
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
bool operator!=(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Inequality operator, does exact floating point comparisons.
Definition: Mat3.h:556
Definition: path.h:290
GLenum mode
Definition: glcorearb.h:99
std::unordered_map< TfToken, VtValue, TfToken::HashFunctor > HdTaskContext
Definition: renderIndex.h:77
HDX_API void Execute(HdTaskContext *ctx) override
Execute the task.
Definition: vec4f.h:62
Definition: task.h:44
HDX_API void Prepare(HdTaskContext *ctx, HdRenderIndex *renderIndex) override
Prepare the render pass resources.
HDX_API HdxColorizeSelectionTask(HdSceneDelegate *delegate, SdfPath const &id)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
Definition: vec2f.h:62
HDX_API ~HdxColorizeSelectionTask() override
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
bool IsConverged() const override
Hooks for progressive rendering.
GLint GLsizei width
Definition: glcorearb.h:103
HDX_API void _Sync(HdSceneDelegate *delegate, HdTaskContext *ctx, HdDirtyBits *dirtyBits) override
Sync the render pass resources.
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
Definition: Mat3.h:542
Definition: format.h:895