All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
67 {
68 public:
69  virtual ~HdStSamplerObject() = 0;
70 
71 protected:
72  explicit HdStSamplerObject(
73  HdSt_SamplerObjectRegistry * samplerObjectRegistry);
74 
75  Hgi* _GetHgi() const;
76  HdSt_SamplerObjectRegistry * const _samplerObjectRegistry;
77 };
78 
83 class HdStUvSamplerObject final : public HdStSamplerObject {
84 public:
85  HDST_API
87  HdStUvTextureObject const &uvTexture,
88  HdSamplerParameters const &samplerParameters,
89  bool createBindlessHandle,
90  HdSt_SamplerObjectRegistry * samplerObjectRegistry);
91 
92  HDST_API
93  ~HdStUvSamplerObject() override;
94 
97  const HgiSamplerHandle &GetSampler() const {
98  return _sampler;
99  }
100 
106  uint64_t GetGLTextureSamplerHandle() const {
107  return _glTextureSamplerHandle;
108  }
109 
110 private:
111  HgiSamplerHandle _sampler;
112  const uint64_t _glTextureSamplerHandle;
113 };
114 
120 public:
122  HdStFieldTextureObject const &uvTexture,
123  HdSamplerParameters const &samplerParameters,
124  bool createBindlessHandle,
125  HdSt_SamplerObjectRegistry * samplerObjectRegistry);
126 
127  ~HdStFieldSamplerObject() override;
128 
131  const HgiSamplerHandle &GetSampler() const {
132  return _sampler;
133  }
134 
140  uint64_t GetGLTextureSamplerHandle() const {
141  return _glTextureSamplerHandle;
142  }
143 
144 private:
145  HgiSamplerHandle _sampler;
146  const uint64_t _glTextureSamplerHandle;
147 };
148 
155 public:
157  HdStPtexTextureObject const &ptexTexture,
158  // samplerParameters are ignored by ptex
159  HdSamplerParameters const &samplerParameters,
160  bool createBindlessHandle,
161  HdSt_SamplerObjectRegistry * samplerObjectRegistry);
162 
163  ~HdStPtexSamplerObject() override;
164 
168  return _texelsSampler;
169  }
170 
176  uint64_t GetTexelsGLTextureHandle() const {
177  return _texelsGLTextureHandle;
178  }
179 
182  uint64_t GetLayoutGLTextureHandle() const {
183  return _layoutGLTextureHandle;
184  }
185 
186 private:
187  HgiSamplerHandle _texelsSampler;
188 
189  const uint64_t _texelsGLTextureHandle;
190  const uint64_t _layoutGLTextureHandle;
191 };
192 
199 public:
201  HdStUdimTextureObject const &ptexTexture,
202  // samplerParameters are ignored by udim (at least for now)
203  HdSamplerParameters const &samplerParameters,
204  bool createBindlessHandle,
205  HdSt_SamplerObjectRegistry * samplerObjectRegistry);
206 
207  ~HdStUdimSamplerObject() override;
208 
212  return _texelsSampler;
213  }
214 
220  uint64_t GetTexelsGLTextureHandle() const {
221  return _texelsGLTextureHandle;
222  }
223 
226  uint64_t GetLayoutGLTextureHandle() const {
227  return _layoutGLTextureHandle;
228  }
229 
230 private:
231  HgiSamplerHandle _texelsSampler;
232 
233  const uint64_t _texelsGLTextureHandle;
234  const uint64_t _layoutGLTextureHandle;
235 };
236 
237 template<HdTextureType textureType>
238 struct HdSt_TypedSamplerObjectHelper;
239 
245 template<HdTextureType textureType>
247  typename HdSt_TypedSamplerObjectHelper<textureType>::type;
248 
249 template<>
250 struct HdSt_TypedSamplerObjectHelper<HdTextureType::Uv> {
251  using type = HdStUvSamplerObject;
252 };
253 
254 template<>
255 struct HdSt_TypedSamplerObjectHelper<HdTextureType::Field> {
256  using type = HdStFieldSamplerObject;
257 };
258 
259 template<>
260 struct HdSt_TypedSamplerObjectHelper<HdTextureType::Ptex> {
261  using type = HdStPtexSamplerObject;
262 };
263 
264 template<>
265 struct HdSt_TypedSamplerObjectHelper<HdTextureType::Udim> {
266  using type = HdStUdimSamplerObject;
267 };
268 
269 PXR_NAMESPACE_CLOSE_SCOPE
270 
271 #endif
uint64_t GetTexelsGLTextureHandle() const
The GL texture handle for bindless textures (as returned by glGetTextureHandleARB).
const HgiSamplerHandle & GetSampler() const
The sampler.
A sampler suitable for Udim textures (wraps one GPU sampler for the texels texture).
Ptex doesn&#39;t bind samplers, so this class is just holding the texture handles for bindless textures...
A base class encapsulating a GPU sampler object and, optionally, a texture sampler handle (for bindle...
Definition: samplerObject.h:66
uint64_t GetGLTextureSamplerHandle() const
The GL sampler texture handle for bindless textures (as returned by glGetTextureSamplerHandleARB).
const HgiSamplerHandle & GetTexelsSampler() const
The GPU sampler object for the texels texture.
const HgiSamplerHandle & GetSampler() const
The sampler.
Definition: samplerObject.h:97
Hydra Graphics Interface.
Definition: hgi.h:106
A uvw texture with a bounding box describing how to transform it.
uint64_t GetLayoutGLTextureHandle() const
Similar to GetGLTexelsTextureHandle but for layout.
A sampler suitable for HdStFieldTextureObject.
Collection of standard parameters such as wrap modes to sample a texture.
Definition: types.h:109
A template alias such that, e.g., HdStUvSamplerObject can be accessed as HdStTypedSamplerObject&lt;HdTex...
const HgiSamplerHandle & GetTexelsSampler() const
The GPU sampler object for the texels texture.
A sampler suitable for HdStUvTextureObject.
Definition: samplerObject.h:83
uint64_t GetTexelsGLTextureHandle() const
The GL texture handle for bindless textures (as returned by glGetTextureHandleARB).
uint64_t GetGLTextureSamplerHandle() const
The GL sampler texture handle for bindless textures (as returned by glGetTextureSamplerHandleARB).
A base class for uv textures.
uint64_t GetLayoutGLTextureHandle() const
Similar to GetGLTexelsTextureHandle but for layout.