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 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_ST_SAMPLER_OBJECT_H
25 #define PXR_IMAGING_HD_ST_SAMPLER_OBJECT_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdSt/api.h"
29 
30 #include "pxr/imaging/hgi/handle.h"
31 #include "pxr/imaging/hd/enums.h"
32 #include "pxr/imaging/hd/types.h"
33 
34 #include <memory>
35 
37 
38 class Hgi;
45 
47  std::shared_ptr<class HdStSamplerObject>;
48 
49 /// \class HdStSamplerObject
50 ///
51 /// A base class encapsulating a GPU sampler object.
52 ///
53 /// The subclasses of HdStSamplerObject mirror the subclasses of
54 /// HdStTextureObject with the intention that they will be used in
55 /// conjunction (e.g., the not yet existing HdStPtexSamplerObject will
56 /// have two samplers and texture sampler handles for the texels and
57 /// layout texture in a HdStPtexTextureObject).
58 ///
59 /// The GPU resources is con-/destructed immediately in the
60 /// c'tor/d'tor. By going through the HdSt_SamplerObjectRegistry, we
61 /// can obtain a shared pointer that can safely be dropped in a
62 /// different thread. The HdSt_SamplerObjectRegistry is also dispatching
63 /// by texture type to construct the corresponding sampler type.
64 ///
66 {
67 public:
68  virtual ~HdStSamplerObject() = 0;
69 
70 protected:
71  explicit HdStSamplerObject(
72  HdSt_SamplerObjectRegistry * samplerObjectRegistry);
73 
74  Hgi* _GetHgi() const;
76 };
77 
78 /// \class HdStUvSamplerObject
79 ///
80 /// A sampler suitable for HdStUvTextureObject.
81 ///
82 class HdStUvSamplerObject final : public HdStSamplerObject {
83 public:
84  HDST_API
86  HdStUvTextureObject const &uvTexture,
87  HdSamplerParameters const &samplerParameters,
88  HdSt_SamplerObjectRegistry * samplerObjectRegistry);
89 
90  HDST_API
91  ~HdStUvSamplerObject() override;
92 
93  /// The sampler.
94  ///
95  const HgiSamplerHandle &GetSampler() const {
96  return _sampler;
97  }
98 
99 private:
100  HgiSamplerHandle _sampler;
101 };
102 
103 /// \class HdStFieldSamplerObject
104 ///
105 /// A sampler suitable for HdStFieldTextureObject.
106 ///
108 public:
110  HdStFieldTextureObject const &uvTexture,
111  HdSamplerParameters const &samplerParameters,
112  HdSt_SamplerObjectRegistry * samplerObjectRegistry);
113 
114  ~HdStFieldSamplerObject() override;
115 
116  /// The sampler.
117  ///
118  const HgiSamplerHandle &GetSampler() const {
119  return _sampler;
120  }
121 
122 private:
123  HgiSamplerHandle _sampler;
124 };
125 
126 /// \class HdStPtexSamplerObject
127 ///
128 /// Ptex doesn't bind samplers, so this class is just holding a
129 /// sampler to resolve handles for bindless textures.
130 ///
132 public:
134  HdStPtexTextureObject const &ptexTexture,
135  // samplerParameters are ignored by ptex
136  HdSamplerParameters const &samplerParameters,
137  HdSt_SamplerObjectRegistry * samplerObjectRegistry);
138 
139  ~HdStPtexSamplerObject() override;
140 
141  /// The GPU sampler object for the texels texture.
142  ///
144  return _texelsSampler;
145  }
146 
147  /// The GPU sampler object for the layout texture.
148  ///
150  return _layoutSampler;
151  }
152 
153 private:
154  HgiSamplerHandle _texelsSampler;
155  HgiSamplerHandle _layoutSampler;
156 };
157 
158 /// \class HdStUdimSamplerObject
159 ///
160 /// A sampler suitable for Udim textures (wraps one GPU sampler
161 /// for the texels texture).
162 ///
164 public:
166  HdStUdimTextureObject const &ptexTexture,
167  // samplerParameters are ignored by udim (at least for now)
168  HdSamplerParameters const &samplerParameters,
169  HdSt_SamplerObjectRegistry * samplerObjectRegistry);
170 
171  ~HdStUdimSamplerObject() override;
172 
173  /// The GPU sampler object for the texels texture.
174  ///
176  return _texelsSampler;
177  }
178 
179  /// The GPU sampler object for the layout texture.
180  ///
182  return _layoutSampler;
183  }
184 
185 private:
186  HgiSamplerHandle _texelsSampler;
187  HgiSamplerHandle _layoutSampler;
188 };
189 
190 template<HdTextureType textureType>
192 
193 /// \class HdStTypedSamplerObject
194 ///
195 /// A template alias such that, e.g., HdStUvSamplerObject can be
196 /// accessed as HdStTypedSamplerObject<HdTextureType::Uv>.
197 ///
198 template<HdTextureType textureType>
201 
202 template<>
205 };
206 
207 template<>
210 };
211 
212 template<>
215 };
216 
217 template<>
220 };
221 
223 
224 #endif
~HdStUdimSamplerObject() override
const HgiSamplerHandle & GetSampler() const
HdSt_SamplerObjectRegistry *const _samplerObjectRegistry
Definition: samplerObject.h:75
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
HdTextureType
Definition: enums.h:221
HdStPtexSamplerObject(HdStPtexTextureObject const &ptexTexture, HdSamplerParameters const &samplerParameters, HdSt_SamplerObjectRegistry *samplerObjectRegistry)
Definition: hgi.h:110
HdStFieldSamplerObject(HdStFieldTextureObject const &uvTexture, HdSamplerParameters const &samplerParameters, HdSt_SamplerObjectRegistry *samplerObjectRegistry)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
#define HDST_API
Definition: api.h:40
const HgiSamplerHandle & GetLayoutSampler() const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
virtual ~HdStSamplerObject()=0
const HgiSamplerHandle & GetSampler() const
Definition: samplerObject.h:95
std::shared_ptr< class HdStSamplerObject > HdStSamplerObjectSharedPtr
Definition: samplerObject.h:47
const HgiSamplerHandle & GetLayoutSampler() const
const HgiSamplerHandle & GetTexelsSampler() const
~HdStPtexSamplerObject() override
Hgi * _GetHgi() const
HdStSamplerObject(HdSt_SamplerObjectRegistry *samplerObjectRegistry)
~HdStFieldSamplerObject() override