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 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 
16 
18 
19 /// \class HdxColorizeSelectionTaskParams
20 ///
21 /// Input parameters for HdxColorizeSelectionTask
22 ///
24 {
27  , enableLocateHighlight(false)
28  , selectionColor(0)
29  , locateColor(0)
30  , enableOutline(false)
31  , outlineRadius(5)
35  {}
36 
42  unsigned int outlineRadius;
43 
47 };
48 
49 /// \class HdxColorizeSelectionTask
50 ///
51 /// A task for taking ID buffer data and turning it into a "selection overlay"
52 /// that can be composited on top of hydra's color output.
53 ///
54 /// If enableOutline is true then instead of overlaying the ID buffer as is, an
55 /// outline with thickness of outlineRadius pixels around the areas with IDs
56 /// will be overlaid. Otherwise, the ID buffer will be overlaid as is.
58 {
59 public:
61 
62  HDX_API
63  HdxColorizeSelectionTask(HdSceneDelegate* delegate, SdfPath const& id);
64 
65  HDX_API
66  ~HdxColorizeSelectionTask() override;
67 
68  /// Hooks for progressive rendering.
69  bool IsConverged() const override;
70 
71  /// Prepare the render pass resources
72  HDX_API
73  void Prepare(HdTaskContext* ctx,
74  HdRenderIndex* renderIndex) override;
75 
76  /// Execute the task
77  HDX_API
78  void Execute(HdTaskContext* ctx) override;
79 
80 protected:
81  /// Sync the render pass resources
82  HDX_API
83  void _Sync(HdSceneDelegate* delegate,
84  HdTaskContext* ctx,
85  HdDirtyBits* dirtyBits) override;
86 
87 private:
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,
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
147 HDX_API
148 std::ostream& operator<<(std::ostream& out,
150 HDX_API
152  const HdxColorizeSelectionTaskParams& rhs);
153 HDX_API
155  const HdxColorizeSelectionTaskParams& rhs);
156 
158 
159 #endif // PXR_IMAGING_HDX_COLORIZE_SELECTION_TASK_H
HDX_API bool operator==(const HdxColorizeSelectionTaskParams &lhs, const HdxColorizeSelectionTaskParams &rhs)
HdFormat
Definition: types.h:408
HDX_API std::ostream & operator<<(std::ostream &out, const HdxColorizeSelectionTaskParams &pv)
uint32_t HdDirtyBits
Definition: types.h:143
int HgiHandle< class HgiTexture > HgiTextureHandle
#define HDX_API
Definition: api.h:23
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:273
GLenum mode
Definition: glcorearb.h:99
std::unordered_map< TfToken, VtValue, TfToken::HashFunctor > HdTaskContext
Definition: renderIndex.h:61
HDX_API void Execute(HdTaskContext *ctx) override
Execute the task.
Definition: vec4f.h:45
Definition: task.h:27
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:1425
Definition: vec2f.h:45
HDX_API ~HdxColorizeSelectionTask() override
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
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:1821