HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
renderPass.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 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_HD_RENDER_PASS_H
8 #define PXR_IMAGING_HD_RENDER_PASS_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hd/api.h"
12 #include "pxr/imaging/hd/version.h"
14 #include "pxr/imaging/hd/task.h"
15 
16 #include <memory>
17 
19 
20 class HdRenderIndex;
21 class HdSceneDelegate;
22 
23 using HdRenderPassSharedPtr = std::shared_ptr<class HdRenderPass>;
24 using HdRenderPassStateSharedPtr = std::shared_ptr<class HdRenderPassState>;
25 
26 /// \class HdRenderPass
27 ///
28 /// An abstract class representing a single render iteration over a set of prims
29 /// (the HdRprimCollection), for the camera/viewport parameters in
30 /// HdRenderPassState.
31 ///
32 /// Conceptually, a rendering task may be broken down into one or more
33 /// HdRenderPass(es).
34 ///
35 /// An HdRenderPass has two phases, Sync() and Execute(), in line with Hydra's
36 /// execution phases (See HdEngine::Execute)
37 ///
38 /// The base class implementation of Sync() takes care of syncing collection
39 /// changes with the HdRenderIndex via HdDirtyList, and allows derived classes
40 /// to track collection changes (via _MarkCollectionDirty) and sync additional
41 /// resources (via _Sync)
42 ///
43 /// Renderer backends implement _Execute, wherein the HdDrawItem(s) for the
44 /// collection may be consumed via HdRenderIndex::GetDrawItems.
45 /// Typically, the HdRenderPassState argument of _Execute is made available via
46 /// the HdTaskContext.
47 ///
48 /// \note
49 /// Rendering backends are expected to specialize this abstract class, and
50 /// return the specialized object via HdRenderDelegate::CreateRenderPass
51 ///
53 {
54 public:
55  HD_API
57  HD_API
58  virtual ~HdRenderPass();
59 
60  /// Returns the HdRprimCollection to be drawn by this RenderPass.
61  HdRprimCollection const& GetRprimCollection() const { return _collection; }
62 
63  /// Sets the HdRprimCollection, note that this may invalidate internal
64  /// caches used to accelerate drawing.
65  HD_API
66  void SetRprimCollection(HdRprimCollection const& col);
67 
68  /// Return the render index
69  HdRenderIndex* GetRenderIndex() const { return _renderIndex; }
70 
71  // ---------------------------------------------------------------------- //
72  /// \name Synchronization
73  // ---------------------------------------------------------------------- //
74 
75  /// Sync the render pass resources
76  HD_API
77  void Sync();
78 
79  // ---------------------------------------------------------------------- //
80  /// \name Execution
81  // ---------------------------------------------------------------------- //
82 
83  /// Execute a subset of buckets of this renderpass.
84  HD_API
85  void Execute(HdRenderPassStateSharedPtr const &renderPassState,
86  TfTokenVector const &renderTags);
87 
88  // ---------------------------------------------------------------------- //
89  /// \name Optional API hooks for progressive rendering
90  // ---------------------------------------------------------------------- //
91 
92  virtual bool IsConverged() const { return true; }
93 
94 protected:
95  /// Virtual API: Execute the buckets corresponding to renderTags;
96  /// renderTags.empty() implies execute everything.
97  virtual void _Execute(HdRenderPassStateSharedPtr const &renderPassState,
98  TfTokenVector const &renderTags) = 0;
99 
100  /// Optional API: let derived classes mark their collection tracking as dirty.
101  virtual void _MarkCollectionDirty() {}
102 
103  /// Optional API: let derived classes sync data.
104  virtual void _Sync() {}
105 
106 private:
107 
108  // Don't allow copies
109  HdRenderPass(const HdRenderPass &) = delete;
110  HdRenderPass &operator=(const HdRenderPass &) = delete;
111 
112  // ---------------------------------------------------------------------- //
113  // \name Change Tracking State
114  // ---------------------------------------------------------------------- //
115  // The renderIndex to which this renderPass belongs
116  // (can't change after construction)
117  HdRenderIndex * const _renderIndex;
118 
119  // ---------------------------------------------------------------------- //
120  // \name Core RenderPass State
121  // ---------------------------------------------------------------------- //
122  HdRprimCollection _collection;
123 };
124 
126 
127 #endif //PXR_IMAGING_HD_RENDER_PASS_H
HdRenderIndex * GetRenderIndex() const
Return the render index.
Definition: renderPass.h:69
std::shared_ptr< class HdRenderPassState > HdRenderPassStateSharedPtr
Definition: engine.h:25
HD_API void Execute(HdRenderPassStateSharedPtr const &renderPassState, TfTokenVector const &renderTags)
Execute a subset of buckets of this renderpass.
std::shared_ptr< class HdRenderPass > HdRenderPassSharedPtr
Definition: engine.h:24
virtual void _Sync()
Optional API: let derived classes sync data.
Definition: renderPass.h:104
#define HD_API
Definition: api.h:23
virtual void _MarkCollectionDirty()
Optional API: let derived classes mark their collection tracking as dirty.
Definition: renderPass.h:101
HD_API HdRenderPass(HdRenderIndex *index, HdRprimCollection const &collection)
virtual HD_API ~HdRenderPass()
HdRprimCollection const & GetRprimCollection() const
Returns the HdRprimCollection to be drawn by this RenderPass.
Definition: renderPass.h:61
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
HD_API void Sync()
Sync the render pass resources.
HD_API void SetRprimCollection(HdRprimCollection const &col)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
GLuint index
Definition: glcorearb.h:786
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
virtual bool IsConverged() const
Definition: renderPass.h:92
virtual void _Execute(HdRenderPassStateSharedPtr const &renderPassState, TfTokenVector const &renderTags)=0