HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RV_TextureRef.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: RV_TextureRef.h ( RV Library, C++)
7  *
8  * COMMENTS:
9  */
10 #ifndef RV_TextureRef_h
11 #define RV_TextureRef_h
12 
13 #include "RV_Type.h"
14 #include "RV_VKImage.h"
15 
16 #include <UT/UT_UniquePtr.h>
17 
18 class RV_TextureCache;
19 
20 /// Opaque reference to a texture stored in the RV_TextureCache
22 {
23 public:
24  RV_TextureRef() = default;
25  RV_TextureRef(const RV_TextureRef& other) { *this = other; }
26  ~RV_TextureRef() { if(myRef) myRef->refCount.add(-1); }
27 
28  /// Reference to a valid texture
29  bool isValid() const
30  { return myTexID != -1 && !myIsMissingTex; }
31 
32  /// Texture is missing; a default color used instead
33  bool isPlaceholder() const
34  { return myIsPlaceholder; }
35  /// Texture couldn't be found or resolved
36  bool isMissingTex() const
37  { return myIsMissingTex; }
38  /// Texture is currently loading in the background
39  bool isLoading() const
40  { return myIsLoading; }
41  /// Texture has been changed since last check
42  bool isDirty() const
43  { return myIsDirty; }
44 
45  /// Reset the reference to a null handle.
46  void reset()
47  {
48  myTexID = -1;
49  myIsMissingTex = false;
50  myIsPlaceholder = false;
51  myIsDirty = true;
52  myIsLoading = false;
53  myCacheVersion = 0;
54  myCacheRefresh = 0;
55  mySampler.reset();
56  }
57 
58  /// Returns true if the reference is to a series of UDIM texture files
59  bool isUDIM() const { return myUDIMW > 0; }
60  /// Returns the UDIM range of the texture files (eg. (0,0) -> (3,2))
61  void getUDIMParms(int &x, int &y, int &w, int &h) const
62  {
63  x = myUDIMX;
64  y = myUDIMY;
65  w = myUDIMW;
66  h = myUDIMH;
67  }
68 
69  void getRes(int *w, int *h = nullptr, int *d = nullptr) const
70  {
71  if(w)
72  *w = myWidth;
73  if(h)
74  *h = myHeight;
75  if(d)
76  *d = myDepth;
77  }
78 
79  /// Returns texture dimension
80  RV_ImageDim getImageDim() const { return myTexType; }
81  fpreal getImageAspectRatio() const { return myAspectRatio; }
82 
83  exint id() const { return myTexID; }
84 
86  {
87  if (this == &other)
88  return *this;
89 
90  myTexID = other.myTexID;
91  myCacheVersion = other.myCacheVersion;
92  myCacheRefresh = other.myCacheRefresh;
93  myIsMissingTex = other.myIsMissingTex;
94  myIsPlaceholder = other.myIsPlaceholder;
95  myIsLoading = other.myIsLoading;
96  myIsDirty = other.myIsDirty;
97 
98  if (myRef)
99  myRef->refCount.add(-1);
100  myRef = other.myRef;
101  if (myRef)
102  myRef->refCount.add(1);
103 
104  myUDIMX = other.myUDIMX;
105  myUDIMY = other.myUDIMY;
106  myUDIMW = other.myUDIMW;
107  myUDIMH = other.myUDIMH;
108  myWidth = other.myWidth;
109  myHeight = other.myHeight;
110  myDepth = other.myDepth;
111  myAspectRatio = other.myAspectRatio;
112  myChannels = other.myChannels;
113  myTypeInfo = other.myTypeInfo;
114 
115  myTexType = other.myTexType;
116 
117  mySampler.reset();
118 
119  return *this;
120  }
121 
122  struct CacheData
123  {
124  CacheData() : refCount(0), isValid(false) {}
125 
127  bool isValid;
128  };
129 
130  int getChannels() const { return myChannels; }
131  int getTypeInfo() const { return myTypeInfo; }
132 
133 private:
134  exint myTexID = -1;
135  exint myCacheVersion = 0;
136  exint myCacheRefresh = 0;
137  bool myIsMissingTex = false;
138  bool myIsPlaceholder = false;
139  bool myIsLoading = false;
140  bool myIsDirty = false;
141 
143 
144  int8 myUDIMX = 0;
145  int8 myUDIMY = 0;
146  int8 myUDIMW = 0;
147  int8 myUDIMH = 0;
148  int myWidth = 1;
149  int myHeight = 1;
150  int myDepth = 1;
151  fpreal myAspectRatio = 1.0;
152  int myChannels = 4;
153  int myTypeInfo = 0;
154 
155  RV_ImageDim myTexType = RV_IMAGE_UNKNOWN;
156 
157  /// Sampler for when we need to use something different from the image's
158  /// built-in one.
159  UT_UniquePtr<RV_VKSampler> mySampler;
160 
161  friend class RV_TextureCache;
162 };
163 
164 #endif
165 
exint id() const
Definition: RV_TextureRef.h:83
fpreal getImageAspectRatio() const
Definition: RV_TextureRef.h:81
bool isDirty() const
Texture has been changed since last check.
Definition: RV_TextureRef.h:42
bool isValid() const
Reference to a valid texture.
Definition: RV_TextureRef.h:29
int64 exint
Definition: SYS_Types.h:125
Opaque reference to a texture stored in the RV_TextureCache.
Definition: RV_TextureRef.h:21
GLint y
Definition: glcorearb.h:103
void getUDIMParms(int &x, int &y, int &w, int &h) const
Returns the UDIM range of the texture files (eg. (0,0) -> (3,2))
Definition: RV_TextureRef.h:61
RV_TextureRef(const RV_TextureRef &other)
Definition: RV_TextureRef.h:25
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
int getTypeInfo() const
SYS_AtomicInt32 refCount
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
void reset()
Reset the reference to a null handle.
Definition: RV_TextureRef.h:46
bool isMissingTex() const
Texture couldn't be found or resolved.
Definition: RV_TextureRef.h:36
bool isUDIM() const
Returns true if the reference is to a series of UDIM texture files.
Definition: RV_TextureRef.h:59
RV_TextureRef()=default
signed char int8
Definition: SYS_Types.h:35
GLint GLenum GLint x
Definition: glcorearb.h:409
RV_ImageDim getImageDim() const
Returns texture dimension.
Definition: RV_TextureRef.h:80
void getRes(int *w, int *h=nullptr, int *d=nullptr) const
Definition: RV_TextureRef.h:69
bool isPlaceholder() const
Texture is missing; a default color used instead.
Definition: RV_TextureRef.h:33
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
Global cache of vulkan textures sourced from files.
bool isLoading() const
Texture is currently loading in the background.
Definition: RV_TextureRef.h:39
fpreal64 fpreal
Definition: SYS_Types.h:283
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
RV_TextureRef & operator=(const RV_TextureRef &other)
Definition: RV_TextureRef.h:85
RV_ImageDim
Definition: RV_Type.h:120
int getChannels() const