samplerObject.h
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 
36 PXR_NAMESPACE_OPEN_SCOPE
37 
38 class Hgi;
43 class HdSt_SamplerObjectRegistry;
45 
46 using HdStSamplerObjectSharedPtr =
47  std::shared_ptr<class HdStSamplerObject>;
48 
66 {
67 public:
68  virtual ~HdStSamplerObject() = 0;
69 
70 protected:
71  explicit HdStSamplerObject(
72  HdSt_SamplerObjectRegistry * samplerObjectRegistry);
73 
74  Hgi* _GetHgi() const;
75  HdSt_SamplerObjectRegistry * const _samplerObjectRegistry;
76 };
77 
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 
95  const HgiSamplerHandle &GetSampler() const {
96  return _sampler;
97  }
98 
99 private:
100  HgiSamplerHandle _sampler;
101 };
102 
108 public:
110  HdStFieldTextureObject const &uvTexture,
111  HdSamplerParameters const &samplerParameters,
112  HdSt_SamplerObjectRegistry * samplerObjectRegistry);
113 
114  ~HdStFieldSamplerObject() override;
115 
118  const HgiSamplerHandle &GetSampler() const {
119  return _sampler;
120  }
121 
122 private:
123  HgiSamplerHandle _sampler;
124 };
125 
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 
144  return _texelsSampler;
145  }
146 
150  return _layoutSampler;
151  }
152 
153 private:
154  HgiSamplerHandle _texelsSampler;
155  HgiSamplerHandle _layoutSampler;
156 };
157 
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 
176  return _texelsSampler;
177  }
178 
182  return _layoutSampler;
183  }
184 
185 private:
186  HgiSamplerHandle _texelsSampler;
187  HgiSamplerHandle _layoutSampler;
188 };
189 
190 template<HdTextureType textureType>
191 struct HdSt_TypedSamplerObjectHelper;
192 
198 template<HdTextureType textureType>
200  typename HdSt_TypedSamplerObjectHelper<textureType>::type;
201 
202 template<>
203 struct HdSt_TypedSamplerObjectHelper<HdTextureType::Uv> {
204  using type = HdStUvSamplerObject;
205 };
206 
207 template<>
208 struct HdSt_TypedSamplerObjectHelper<HdTextureType::Field> {
209  using type = HdStFieldSamplerObject;
210 };
211 
212 template<>
213 struct HdSt_TypedSamplerObjectHelper<HdTextureType::Ptex> {
214  using type = HdStPtexSamplerObject;
215 };
216 
217 template<>
218 struct HdSt_TypedSamplerObjectHelper<HdTextureType::Udim> {
219  using type = HdStUdimSamplerObject;
220 };
221 
222 PXR_NAMESPACE_CLOSE_SCOPE
223 
224 #endif
A sampler suitable for Udim textures (wraps one GPU sampler for the texels texture).
Ptex doesn't bind samplers, so this class is just holding a sampler to resolve handles for bindless t...
A base class encapsulating a GPU sampler object.
Definition: samplerObject.h:65
const HgiSamplerHandle & GetTexelsSampler() const
The GPU sampler object for the texels texture.
const HgiSamplerHandle & GetSampler() const
The sampler.
Definition: samplerObject.h:95
const HgiSamplerHandle & GetTexelsSampler() const
The GPU sampler object for the texels texture.
const HgiSamplerHandle & GetSampler() const
The sampler.
Hydra Graphics Interface.
Definition: hgi.h:110
A uvw texture with a bounding box describing how to transform it.
const HgiSamplerHandle & GetLayoutSampler() const
The GPU sampler object for the layout texture.
A sampler suitable for HdStFieldTextureObject.
Collection of standard parameters such as wrap modes to sample a texture.
Definition: types.h:127
A template alias such that, e.g., HdStUvSamplerObject can be accessed as HdStTypedSamplerObject<HdTex...
A sampler suitable for HdStUvTextureObject.
Definition: samplerObject.h:82
const HgiSamplerHandle & GetLayoutSampler() const
The GPU sampler object for the layout texture.
A base class for uv textures.