HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
textureIdentifier.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_TEXTURE_IDENTIFIER_H
8 #define PXR_IMAGING_HD_ST_TEXTURE_IDENTIFIER_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hdSt/api.h"
12 
13 #include "pxr/base/tf/token.h"
14 #include "pxr/base/vt/value.h"
15 
16 #include <memory>
17 
19 
21 
22 ///
23 /// \class HdStTextureIdentifier
24 ///
25 /// Class to identify a texture file or a texture within the texture file
26 /// (e.g., a frame in a movie).
27 ///
28 /// The class has value semantics and uses HdStSubtextureIdentifier in a
29 /// polymorphic way.
30 ///
32 {
33 public:
34  using ID = size_t;
35 
36  HDST_API
38 
39  /// C'tor for files that can contain only one texture.
40  ///
41  HDST_API
42  explicit HdStTextureIdentifier(
43  const TfToken &filePath,
44  const VtValue &fallback = VtValue(),
45  bool defaultToFallback = false);
46 
47  /// C'tor for files that can contain more than one texture (e.g.,
48  /// frames in a movie, grids in a VDB file).
49  ///
50  HDST_API
52  const TfToken &filePath,
53  std::unique_ptr<const HdStSubtextureIdentifier> &&subtextureId,
54  const VtValue &fallback = VtValue(),
55  bool defaultToFallback = false);
56 
57  HDST_API
59 
60  HDST_API
62 
63  HDST_API
65 
66  HDST_API
68 
69  /// Get file path of texture file.
70  ///
71  const TfToken &GetFilePath() const {
72  return _filePath;
73  }
74 
75  /// Get fallback value that's used if loading from _filePath fails
76  ///
77  const VtValue &GetFallback() const {
78  return _fallback;
79  }
80 
81  /// Get if reading from _filePath should be skipped
82  ///
83  bool ShouldDefaultToFallback() const {
84  return _defaultToFallback;
85  }
86 
87  /// Get additional information identifying a texture in a file that
88  /// can contain more than one texture (e.g., a frame in a movie or
89  /// a grid in a VDB file).
90  ///
91  /// nullptr for files (e.g., png) that can contain only one texture.
92  ///
94  return _subtextureId.get();
95  }
96 
97  HDST_API
98  bool operator==(const HdStTextureIdentifier &other) const;
99  HDST_API
100  bool operator!=(const HdStTextureIdentifier &other) const;
101 
102 private:
103  TfToken _filePath;
104  VtValue _fallback;
105  bool _defaultToFallback = false;
106  std::unique_ptr<const HdStSubtextureIdentifier> _subtextureId;
107 };
108 
109 HDST_API
110 size_t hash_value(const HdStTextureIdentifier &);
111 
113 
114 #endif
HDST_API bool operator!=(const HdStTextureIdentifier &other) const
bool ShouldDefaultToFallback() const
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
const VtValue & GetFallback() const
HDST_API HdStTextureIdentifier()
Definition: token.h:70
const TfToken & GetFilePath() const
HDST_API HdStTextureIdentifier & operator=(HdStTextureIdentifier &&textureId)
HDST_API ~HdStTextureIdentifier()
HDST_API size_t hash_value(const HdStTextureIdentifier &)
HDST_API bool operator==(const HdStTextureIdentifier &other) const
const HdStSubtextureIdentifier * GetSubtextureIdentifier() const
#define HDST_API
Definition: api.h:23
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
Definition: value.h:89