All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ptexTextureObject.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_PTEX_TEXTURE_OBJECT_H
25 #define PXR_IMAGING_HD_ST_PTEX_TEXTURE_OBJECT_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdSt/api.h"
29 #include "pxr/imaging/hdSt/textureObject.h"
30 
31 #include "pxr/imaging/hgi/handle.h"
32 
33 #include "pxr/base/gf/vec2i.h"
34 #include "pxr/base/gf/vec3i.h"
35 
36 #ifdef PXR_PTEX_SUPPORT_ENABLED
37 #include "pxr/imaging/hdSt/ptexMipmapTextureLoader.h"
38 #endif
39 
40 PXR_NAMESPACE_OPEN_SCOPE
41 
50 HDST_API bool HdStIsSupportedPtexTexture(std::string const & imageFilePath);
51 
52 enum HgiFormat : int;
53 using HgiTextureHandle = HgiHandle<class HgiTexture>;
54 
60 {
61 public:
62  HDST_API
64  const HdStTextureIdentifier &textureId,
65  HdSt_TextureObjectRegistry *textureObjectRegistry);
66 
67  HDST_API
68  ~HdStPtexTextureObject() override;
69 
74  HgiTextureHandle GetTexelTexture() const { return _texelTexture; }
75 
80  HgiTextureHandle GetLayoutTexture() const { return _layoutTexture; }
81 
82  HDST_API
83  bool IsValid() const override;
84 
85  HDST_API
86  HdTextureType GetTextureType() const override;
87 
88 protected:
89  HDST_API
90  void _Load() override;
91 
92  HDST_API
93  void _Commit() override;
94 
95 private:
96  HgiFormat _format;
97  GfVec3i _texelDimensions;
98  int _texelLayers;
99  size_t _texelDataSize;
100  GfVec2i _layoutDimensions;
101  size_t _layoutDataSize;
102 
103  std::unique_ptr<uint8_t[]> _texelData;
104  std::unique_ptr<uint8_t[]> _layoutData;
105 
106  HgiTextureHandle _texelTexture;
107  HgiTextureHandle _layoutTexture;
108 
109  void _DestroyTextures();
110 };
111 
112 template<>
113 struct HdSt_TypedTextureObjectHelper<HdTextureType::Ptex> {
114  using type = HdStPtexTextureObject;
115 };
116 
117 PXR_NAMESPACE_CLOSE_SCOPE
118 
119 #endif
HDST_API void _Commit() override
Commit texture to GPU (not thread-safe)
Basic type for a vector of 2 int components.
Definition: vec2i.h:61
HgiTextureHandle GetTexelTexture() const
Get the GPU texture handle for the texels.
Base class for a texture object.
Definition: textureObject.h:58
HgiTextureHandle GetLayoutTexture() const
Get the GPU texture handle for the layout.
Class to identify a texture file or a texture within the texture file (e.g., a frame in a movie)...
HDST_API HdTextureType GetTextureType() const override
Get texture type.
Basic type for a vector of 3 int components.
Definition: vec3i.h:61
HDST_API bool IsValid() const override
Is texture valid? Only correct after commit phase.
HDST_API void _Load() override
Load texture to CPU (thread-safe)