All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
taskController.h
1 //
2 // Copyright 2017 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_TASK_CONTROLLER_H
25 #define PXR_IMAGING_HDX_TASK_CONTROLLER_H
26 
27 #include "pxr/pxr.h"
28 
29 #include "pxr/imaging/hdx/api.h"
30 #include "pxr/imaging/hdx/selectionTracker.h"
31 #include "pxr/imaging/hdx/renderSetupTask.h"
32 #include "pxr/imaging/hdx/shadowTask.h"
33 #include "pxr/imaging/hdx/colorCorrectionTask.h"
34 
35 #include "pxr/imaging/hd/aov.h"
36 #include "pxr/imaging/hd/renderIndex.h"
37 #include "pxr/imaging/hd/sceneDelegate.h"
38 #include "pxr/imaging/hd/task.h"
39 
40 #include "pxr/imaging/cameraUtil/framing.h"
42 #include "pxr/usd/sdf/path.h"
43 #include "pxr/base/gf/matrix4d.h"
44 
45 PXR_NAMESPACE_OPEN_SCOPE
46 
47 // XXX: This API is transitional. At the least, render/picking/selection
48 // APIs should be decoupled.
49 
50 class HdRenderBuffer;
51 
52 class HdxTaskController final
53 {
54 public:
55  HDX_API
56  HdxTaskController(HdRenderIndex *renderIndex,
57  SdfPath const& controllerId);
58  HDX_API
59  ~HdxTaskController();
60 
62  HdRenderIndex* GetRenderIndex() { return _index; }
63  HdRenderIndex const* GetRenderIndex() const { return _index; }
64 
67  SdfPath const& GetControllerId() const { return _controllerId; }
68 
71 
75  HDX_API
76  HdTaskSharedPtrVector const GetRenderingTasks() const;
77 
80  HDX_API
81  HdTaskSharedPtrVector const GetPickingTasks() const;
82 
85 
87  HDX_API
88  void SetCollection(HdRprimCollection const& collection);
89 
94  HDX_API
95  void SetRenderParams(HdxRenderTaskParams const& params);
96 
101  HDX_API
102  void SetRenderTags(TfTokenVector const& renderTags);
103 
106 
110  HDX_API
111  void SetRenderOutputs(TfTokenVector const& names);
112 
115  HDX_API
116  void SetViewportRenderOutput(TfToken const& name);
117 
121  HDX_API
122  HdRenderBuffer* GetRenderOutput(TfToken const& name);
123 
125  HDX_API
126  void SetRenderOutputSettings(TfToken const& name,
127  HdAovDescriptor const& desc);
128 
130  HDX_API
131  HdAovDescriptor GetRenderOutputSettings(TfToken const& name) const;
132 
138  HDX_API
139  void SetPresentationOutput(TfToken const &api, VtValue const &framebuffer);
140 
143 
147  HDX_API
148  void SetLightingState(GlfSimpleLightingContextPtr const& src);
149 
152 
156  HDX_API
157  void SetRenderBufferSize(const GfVec2i &size);
158 
162  HDX_API
163  void SetFraming(const CameraUtilFraming &framing);
164 
174  HDX_API
175  void SetOverrideWindowPolicy(
176  const std::pair<bool, CameraUtilConformWindowPolicy> &policy);
177 
180  HDX_API
181  void SetCameraPath(SdfPath const& id);
182 
186  HDX_API
187  void SetRenderViewport(GfVec4d const& viewport);
188 
192  HDX_API
193  void SetFreeCameraMatrices(GfMatrix4d const& viewMatrix,
194  GfMatrix4d const& projectionMatrix);
197  HDX_API
198  void SetFreeCameraClipPlanes(std::vector<GfVec4d> const& clipPlanes);
199 
202 
204  HDX_API
205  void SetEnableSelection(bool enable);
206 
208  HDX_API
209  void SetSelectionColor(GfVec4f const& color);
210 
213  HDX_API
214  void SetSelectionEnableOutline(bool enableOutline);
215 
219  HDX_API
220  void SetSelectionOutlineRadius(unsigned int radius);
221 
224 
226  HDX_API
227  void SetEnableShadows(bool enable);
228 
231  HDX_API
232  void SetShadowParams(HdxShadowTaskParams const& params);
233 
236 
238  HDX_API
239  bool IsConverged() const;
240 
243 
245  HDX_API
246  void SetColorCorrectionParams(HdxColorCorrectionTaskParams const& params);
247 
250 
254  HDX_API
255  void SetEnablePresentation(bool enabled);
256 
257 private:
261  HdxTaskController(HdxTaskController const&) = delete;
262  HdxTaskController &operator=(HdxTaskController const&) = delete;
263 
264  HdRenderIndex *_index;
265  SdfPath const _controllerId;
266 
267  // Create taskController objects. Since the camera is a parameter
268  // to the tasks, _CreateCamera() should be called first.
269  void _CreateRenderGraph();
270 
271  void _CreateLightingTask();
272  void _CreateShadowTask();
273  SdfPath _CreateRenderTask(TfToken const& materialTag);
274  void _CreateOitResolveTask();
275  void _CreateSelectionTask();
276  void _CreateColorizeSelectionTask();
277  void _CreateColorCorrectionTask();
278  void _CreateVisualizeAovTask();
279  void _CreatePickTask();
280  void _CreatePickFromRenderBufferTask();
281  void _CreateAovInputTask();
282  void _CreatePresentTask();
283 
284  void _SetCameraParamForTasks(SdfPath const& id);
285  void _SetCameraFramingForTasks();
286  void _UpdateAovDimensions(GfVec2i const& dimensions);
287 
288  void _SetBlendStateForMaterialTag(TfToken const& materialTag,
289  HdxRenderTaskParams *renderParams) const;
290 
291  // Render graph topology control.
292  bool _ShadowsEnabled() const;
293  bool _SelectionEnabled() const;
294  bool _ColorizeSelectionEnabled() const;
295  bool _ColorCorrectionEnabled() const;
296  bool _VisualizeAovEnabled() const;
297  bool _ColorizeQuantizationEnabled() const;
298  bool _AovsSupported() const;
299  bool _UsingAovs() const;
300 
301  // Helper function for renderbuffer management.
302  SdfPath _GetRenderTaskPath(TfToken const& materialTag) const;
303  SdfPath _GetAovPath(TfToken const& aov) const;
304  SdfPathVector _GetAovEnabledTasks() const;
305 
306  // Helper function to set the parameters of a light, get a particular light
307  // in the scene, replace and remove Sprims from the scene
308  void _SetParameters(SdfPath const& pathName, GlfSimpleLight const& light);
309  GlfSimpleLight _GetLightAtId(size_t const& pathIdx);
310  void _RemoveLightSprim(size_t const& pathIdx);
311  void _ReplaceLightSprim(size_t const& pathIdx, GlfSimpleLight const& light,
312  SdfPath const& pathName);
313 
314  // A private scene delegate member variable backs the tasks and the free cam
315  // this controller generates. To keep _Delegate simple, the containing class
316  // is responsible for marking things dirty.
317  class _Delegate : public HdSceneDelegate
318  {
319  public:
320  _Delegate(HdRenderIndex *parentIndex,
321  SdfPath const& delegateID)
322  : HdSceneDelegate(parentIndex, delegateID)
323  {}
324  ~_Delegate() override = default;
325 
326  // HdxTaskController set/get interface
327  template <typename T>
328  void SetParameter(SdfPath const& id, TfToken const& key,
329  T const& value) {
330  _valueCacheMap[id][key] = value;
331  }
332  template <typename T>
333  T GetParameter(SdfPath const& id, TfToken const& key) const {
334  VtValue vParams;
335  _ValueCache vCache;
336  TF_VERIFY(
337  TfMapLookup(_valueCacheMap, id, &vCache) &&
338  TfMapLookup(vCache, key, &vParams) &&
339  vParams.IsHolding<T>());
340  return vParams.Get<T>();
341  }
342  bool HasParameter(SdfPath const& id, TfToken const& key) const {
343  _ValueCache vCache;
344  if (TfMapLookup(_valueCacheMap, id, &vCache) &&
345  vCache.count(key) > 0) {
346  return true;
347  }
348  return false;
349  }
350 
351  // HdSceneDelegate interface
352  VtValue Get(SdfPath const& id, TfToken const& key) override;
353  GfMatrix4d GetTransform(SdfPath const& id) override;
354  VtValue GetLightParamValue(SdfPath const& id,
355  TfToken const& paramName) override;
356  bool IsEnabled(TfToken const& option) const override;
358  GetRenderBufferDescriptor(SdfPath const& id) override;
359  TfTokenVector GetTaskRenderTags(SdfPath const& taskId) override;
360 
361 
362  private:
363  using _ValueCache = TfHashMap<TfToken, VtValue, TfToken::HashFunctor>;
364  using _ValueCacheMap = TfHashMap<SdfPath, _ValueCache, SdfPath::Hash>;
365  _ValueCacheMap _valueCacheMap;
366  };
367  _Delegate _delegate;
368  std::unique_ptr<class HdxFreeCameraSceneDelegate> _freeCameraSceneDelegate;
369 
370  // Generated tasks.
371  SdfPath _simpleLightTaskId;
372  SdfPath _shadowTaskId;
373  SdfPathVector _renderTaskIds;
374  SdfPath _aovInputTaskId;
375  SdfPath _oitResolveTaskId;
376  SdfPath _selectionTaskId;
377  SdfPath _colorizeSelectionTaskId;
378  SdfPath _colorCorrectionTaskId;
379  SdfPath _visualizeAovTaskId;
380  SdfPath _pickTaskId;
381  SdfPath _pickFromRenderBufferTaskId;
382  SdfPath _presentTaskId;
383 
384  // Current active camera
385  SdfPath _activeCameraId;
386 
387  // Built-in lights
388  SdfPathVector _lightIds;
389 
390  // Generated renderbuffers
391  SdfPathVector _aovBufferIds;
392  TfTokenVector _aovOutputs;
393  TfToken _viewportAov;
394 
395  GfVec2i _renderBufferSize;
396  CameraUtilFraming _framing;
397  std::pair<bool, CameraUtilConformWindowPolicy> _overrideWindowPolicy;
398 
399  GfVec4d _viewport;
400 };
401 
402 PXR_NAMESPACE_CLOSE_SCOPE
403 
404 #endif // PXR_IMAGING_HDX_TASK_CONTROLLER_H
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:116
Basic type for a vector of 2 int components.
Definition: vec2i.h:61
Describes the allocation structure of a render buffer bprim.
Definition: aov.h:84
bool IsHolding() const
Return true if this value is holding an object of type T, false otherwise.
Definition: value.h:1062
Basic type for a vector of 4 double components.
Definition: vec4d.h:63
T const & Get() const
Returns a const reference to the held object if the held object is of type T.
Definition: value.h:1101
ColorCorrectionTask parameters.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
RenderTask parameters (renderpass state).
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
Definition: diagnostic.h:283
Adapter class providing data exchange with the client scene graph.
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
bool TfMapLookup(Container const &map, Key const &key, Result *valuePtr)
Checks if an item exists in a map or a TfHashMap.
Definition: stl.h:88
A named, semantic collection of objects.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:288
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:51
A bundle of state describing an AOV (&quot;Arbitrary Output Variable&quot;) display channel.
Definition: aov.h:46
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:168
Framing information.
Definition: framing.h:79