HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
samplerObject.h
Go to the documentation of this file.
1 //
2 // Copyright 2020 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_ST_SAMPLER_OBJECT_H
8 #define PXR_IMAGING_HD_ST_SAMPLER_OBJECT_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hdSt/api.h"
12 #include "pxr/imaging/hdSt/enums.h"
13 
14 #include "pxr/imaging/hgi/handle.h"
15 #include "pxr/imaging/hd/types.h"
16 
17 #include <memory>
18 
20 
21 class Hgi;
22 class HdStCubemapTextureObject;
29 
31  std::shared_ptr<class HdStSamplerObject>;
32 
33 /// \class HdStSamplerObject
34 ///
35 /// A base class encapsulating a GPU sampler object.
36 ///
37 /// The subclasses of HdStSamplerObject mirror the subclasses of
38 /// HdStTextureObject with the intention that they will be used in
39 /// conjunction (e.g., the not yet existing HdStPtexSamplerObject will
40 /// have two samplers and texture sampler handles for the texels and
41 /// layout texture in a HdStPtexTextureObject).
42 ///
43 /// The GPU resources is con-/destructed immediately in the
44 /// c'tor/d'tor. By going through the HdSt_SamplerObjectRegistry, we
45 /// can obtain a shared pointer that can safely be dropped in a
46 /// different thread. The HdSt_SamplerObjectRegistry is also dispatching
47 /// by texture type to construct the corresponding sampler type.
48 ///
50 {
51 public:
52  virtual ~HdStSamplerObject() = 0;
53 
54 protected:
55  explicit HdStSamplerObject(
56  HdSt_SamplerObjectRegistry * samplerObjectRegistry);
57 
58  Hgi* _GetHgi() const;
60 };
61 
62 /// \class HdStUvSamplerObject
63 ///
64 /// A sampler suitable for HdStUvTextureObject.
65 ///
66 /// Note that when this sampler is used with an HdStUvTextureObject referring
67 /// to a cubemap, the wrap modes in the sampler parameters will be ignored
68 /// because we default to using seamless cubemap sampling.
69 ///
70 class HdStUvSamplerObject final : public HdStSamplerObject {
71 public:
72  HDST_API
74  HdStUvTextureObject const &uvTexture,
75  HdSamplerParameters const &samplerParameters,
76  HdSt_SamplerObjectRegistry * samplerObjectRegistry);
77 
78  HDST_API
79  ~HdStUvSamplerObject() override;
80 
81  /// The sampler.
82  ///
83  const HgiSamplerHandle &GetSampler() const {
84  return _sampler;
85  }
86 
87 private:
88  HgiSamplerHandle _sampler;
89 };
90 
91 /// \class HdStFieldSamplerObject
92 ///
93 /// A sampler suitable for HdStFieldTextureObject.
94 ///
96 public:
98  HdStFieldTextureObject const &uvTexture,
99  HdSamplerParameters const &samplerParameters,
100  HdSt_SamplerObjectRegistry * samplerObjectRegistry);
101 
102  ~HdStFieldSamplerObject() override;
103 
104  /// The sampler.
105  ///
106  const HgiSamplerHandle &GetSampler() const {
107  return _sampler;
108  }
109 
110 private:
111  HgiSamplerHandle _sampler;
112 };
113 
114 /// \class HdStPtexSamplerObject
115 ///
116 /// Ptex doesn't bind samplers, so this class is just holding a
117 /// sampler to resolve handles for bindless textures.
118 ///
120 public:
122  HdStPtexTextureObject const &ptexTexture,
123  // samplerParameters are ignored by ptex
124  HdSamplerParameters const &samplerParameters,
125  HdSt_SamplerObjectRegistry * samplerObjectRegistry);
126 
127  ~HdStPtexSamplerObject() override;
128 
129  /// The GPU sampler object for the texels texture.
130  ///
132  return _texelsSampler;
133  }
134 
135  /// The GPU sampler object for the layout texture.
136  ///
138  return _layoutSampler;
139  }
140 
141 private:
142  HgiSamplerHandle _texelsSampler;
143  HgiSamplerHandle _layoutSampler;
144 };
145 
146 /// \class HdStUdimSamplerObject
147 ///
148 /// A sampler suitable for Udim textures (wraps one GPU sampler
149 /// for the texels texture).
150 ///
152 public:
154  HdStUdimTextureObject const &ptexTexture,
155  // samplerParameters are ignored by udim (at least for now)
156  HdSamplerParameters const &samplerParameters,
157  HdSt_SamplerObjectRegistry * samplerObjectRegistry);
158 
159  ~HdStUdimSamplerObject() override;
160 
161  /// The GPU sampler object for the texels texture.
162  ///
164  return _texelsSampler;
165  }
166 
167  /// The GPU sampler object for the layout texture.
168  ///
170  return _layoutSampler;
171  }
172 
173 private:
174  HgiSamplerHandle _texelsSampler;
175  HgiSamplerHandle _layoutSampler;
176 };
177 
178 template<HdStTextureType textureType>
180 
181 /// \class HdStTypedSamplerObject
182 ///
183 /// A template alias such that, e.g., HdStUvSamplerObject can be
184 /// accessed as HdStTypedSamplerObject<HdStTextureType::Uv>.
185 ///
186 template<HdStTextureType textureType>
189 
190 template<>
193 };
194 
195 template<>
198 };
199 
200 template<>
203 };
204 
205 template<>
208 };
209 
210 template<>
213 };
214 
216 
217 #endif
~HdStUdimSamplerObject() override
const HgiSamplerHandle & GetSampler() const
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
HdSt_SamplerObjectRegistry *const _samplerObjectRegistry
Definition: samplerObject.h:59
HDST_API ~HdStUvSamplerObject() override
HDST_API HdStUvSamplerObject(HdStUvTextureObject const &uvTexture, HdSamplerParameters const &samplerParameters, HdSt_SamplerObjectRegistry *samplerObjectRegistry)
HdStUdimSamplerObject(HdStUdimTextureObject const &ptexTexture, HdSamplerParameters const &samplerParameters, HdSt_SamplerObjectRegistry *samplerObjectRegistry)
const HgiSamplerHandle & GetTexelsSampler() const
HdStPtexSamplerObject(HdStPtexTextureObject const &ptexTexture, HdSamplerParameters const &samplerParameters, HdSt_SamplerObjectRegistry *samplerObjectRegistry)
Definition: hgi.h:94
HdStFieldSamplerObject(HdStFieldTextureObject const &uvTexture, HdSamplerParameters const &samplerParameters, HdSt_SamplerObjectRegistry *samplerObjectRegistry)
#define HDST_API
Definition: api.h:23
const HgiSamplerHandle & GetLayoutSampler() const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HdStTextureType
Definition: enums.h:32
virtual ~HdStSamplerObject()=0
const HgiSamplerHandle & GetSampler() const
Definition: samplerObject.h:83
std::shared_ptr< class HdStSamplerObject > HdStSamplerObjectSharedPtr
Definition: samplerObject.h:31
const HgiSamplerHandle & GetLayoutSampler() const
const HgiSamplerHandle & GetTexelsSampler() const
~HdStPtexSamplerObject() override
Hgi * _GetHgi() const
HdStSamplerObject(HdSt_SamplerObjectRegistry *samplerObjectRegistry)
~HdStFieldSamplerObject() override