renderSettings.h
1 //
2 // Copyright 2022 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_HD_RENDER_SETTINGS_H
25 #define PXR_IMAGING_HD_RENDER_SETTINGS_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hd/api.h"
29 #include "pxr/imaging/hd/bprim.h"
30 
31 #include "pxr/base/vt/dictionary.h"
32 #include "pxr/base/gf/vec2i.h"
33 #include "pxr/base/gf/vec2f.h"
34 #include "pxr/base/gf/range2f.h"
35 
36 #include <vector>
37 
38 PXR_NAMESPACE_OPEN_SCOPE
39 
65 class HdRenderSettings : public HdBprim
66 {
67 public:
68  // Change tracking for HdRenderSettings.
69  enum DirtyBits : HdDirtyBits {
70  Clean = 0,
71  DirtyActive = 1 << 1,
72  DirtyNamespacedSettings = 1 << 2,
73  DirtyRenderProducts = 1 << 3,
74  DirtyIncludedPurposes = 1 << 4,
75  DirtyMaterialBindingPurposes = 1 << 5,
76  DirtyRenderingColorSpace = 1 << 6,
77  AllDirty = DirtyActive
78  | DirtyNamespacedSettings
79  | DirtyRenderProducts
80  | DirtyIncludedPurposes
81  | DirtyMaterialBindingPurposes
82  | DirtyRenderingColorSpace
83  };
84 
85  // Parameters that may be queried and invalidated.
86  //
87  // \note This mirrors UsdRender except that the render products and vars
88  // are "flattened out" similar to UsdRenderSpec.
89  struct RenderProduct {
90  struct RenderVar {
91  SdfPath varPath;
92  TfToken dataType;
93  std::string sourceName;
94  TfToken sourceType;
95  VtDictionary namespacedSettings;
96  };
97 
99  //
100  // Path to product prim in scene description.
101  SdfPath productPath;
102  // The type of product, ex: "raster".
103  TfToken type;
104  // The name of the product, which uniquely identifies it.
105  TfToken name;
106  // The pixel resolution of the product.
107  GfVec2i resolution;
108  // The render vars that the product is comprised of.
109  std::vector<RenderVar> renderVars;
110 
112  //
113  // Path to the camera to use for this product.
114  SdfPath cameraPath;
115  // The pixel aspect ratio as adjusted by aspectRatioConformPolicy.
116  float pixelAspectRatio;
117  // The policy that was applied to conform aspect ratio
118  // mismatches between the aperture and image.
119  TfToken aspectRatioConformPolicy;
120  // The camera aperture size as adjusted by aspectRatioConformPolicy.
121  GfVec2f apertureSize;
122  // The data window, in NDC terms relative to the aperture.
123  // (0,0) corresponds to bottom-left and (1,1) corresponds to
124  // top-right. Note that the data window can partially cover
125  // or extend beyond the unit range, for representing overscan
126  // or cropped renders.
127  GfRange2f dataWindowNDC;
128 
130  //
131  bool disableMotionBlur;
132  VtDictionary namespacedSettings;
133  };
134 
135  using RenderProducts = std::vector<RenderProduct>;
137 
138  HD_API
139  ~HdRenderSettings() override;
140 
141  // ------------------------------------------------------------------------
142  // Public API
143  // ------------------------------------------------------------------------
144  HD_API
145  bool IsActive() const;
146 
147  HD_API
148  const NamespacedSettings& GetNamespacedSettings() const;
149 
150  HD_API
151  const RenderProducts& GetRenderProducts() const;
152 
153  HD_API
154  const TfTokenVector& GetIncludedPurposes() const;
155 
156  HD_API
157  const TfTokenVector& GetMaterialBindingPurposes() const;
158 
159  HD_API
160  const TfToken& GetRenderingColorSpace() const;
161 
162  // XXX Add API to query AOV bindings.
163 
164  // ------------------------------------------------------------------------
165  // Satisfying HdBprim
166  // ------------------------------------------------------------------------
167  HD_API
168  void
169  Sync(HdSceneDelegate *sceneDelegate,
170  HdRenderParam *renderParam,
171  HdDirtyBits *dirtyBits) override final;
172 
173  HD_API
174  HdDirtyBits
175  GetInitialDirtyBitsMask() const override;
176 
177 protected:
178  HD_API
179  HdRenderSettings(SdfPath const& id);
180 
181  // ------------------------------------------------------------------------
182  // Virtual API
183  // ------------------------------------------------------------------------
184  // This is called during Sync after dirty processing and before clearing the
185  // dirty bits.
186  virtual void
187  _Sync(HdSceneDelegate *sceneDelegate,
188  HdRenderParam *renderParam,
189  const HdDirtyBits *dirtyBits);
190 
191 
192 private:
193  // Class cannot be default constructed or copied.
194  HdRenderSettings() = delete;
195  HdRenderSettings(const HdRenderSettings &) = delete;
196  HdRenderSettings &operator =(const HdRenderSettings &) = delete;
197 
198  bool _active;
199  NamespacedSettings _namespacedSettings;
200  RenderProducts _products;
201  TfTokenVector _includedPurposes;
202  TfTokenVector _materialBindingPurposes;
203  TfToken _renderingColorSpace;
204 };
205 
206 // VtValue requirements
207 HD_API
208 size_t hash_value(HdRenderSettings::RenderProduct const &rp);
209 
210 HD_API
211 std::ostream& operator<<(
212  std::ostream& out, const HdRenderSettings::RenderProduct&);
213 
214 HD_API
215 bool operator==(const HdRenderSettings::RenderProduct& lhs,
216  const HdRenderSettings::RenderProduct& rhs);
217 HD_API
218 bool operator!=(const HdRenderSettings::RenderProduct& lhs,
219  const HdRenderSettings::RenderProduct& rhs);
220 HD_API
221 std::ostream& operator<<(
222  std::ostream& out, const HdRenderSettings::RenderProduct::RenderVar&);
223 
224 HD_API
225 bool operator==(const HdRenderSettings::RenderProduct::RenderVar& lhs,
226  const HdRenderSettings::RenderProduct::RenderVar& rhs);
227 HD_API
228 bool operator!=(const HdRenderSettings::RenderProduct::RenderVar& lhs,
229  const HdRenderSettings::RenderProduct::RenderVar& rhs);
230 
231 
232 PXR_NAMESPACE_CLOSE_SCOPE
233 
234 #endif // PXR_IMAGING_HD_RENDER_SETTINGS_H
HD_API HdDirtyBits GetInitialDirtyBitsMask() const override
Returns the minimal set of dirty bits to place in the change tracker for use in the first sync of thi...
HD_API void Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits) override final
Synchronizes state from the delegate to this object.
Basic type for a vector of 2 int components.
Definition: vec2i.h:60
A map with string keys and VtValue values.
Definition: dictionary.h:62
AR_API bool operator!=(const ArAssetInfo &lhs, const ArAssetInfo &rhs)
The HdRenderParam is an opaque (to core Hydra) handle, to an object that is obtained from the render ...
AR_API bool operator==(const ArAssetInfo &lhs, const ArAssetInfo &rhs)
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
Adapter class providing data exchange with the client scene graph.
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
Abstract hydra prim backing render settings scene description.
Basic type for a vector of 2 float components.
Definition: vec2f.h:62
Bprim (buffer prim) is a base class of managing a blob of data that is used to communicate between th...
Definition: bprim.h:56
Basic type: 2-dimensional floating point range.
Definition: range2f.h:63