HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GR_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: GR_TextureRef.h ( GR Library, C++)
7  *
8  * COMMENTS:
9  * texture ref that could be from different rendering backends
10  */
11 
12 #ifndef GR_TextureRef_h
13 #define GR_TextureRef_h
14 
15 #include "GR_API.h"
16 
17 #include <RE/RE_Texture.h>
18 #include <UT/UT_Array.h>
19 #include <UT/UT_SharedPtr.h>
20 #include <UT/UT_VectorTypes.h>
21 
22 #include "GR_Defines.h"
23 
25 class RV_VKImage;
26 
27 // Reference to a texture created by one of the underlying
28 // renderer, to be passed back during a draw
29 // Can be backed by OpenGL, Vulkan, or interop texture.
30 // Renders should check that the type matches their own
31 // before using
33 {
34 public:
35  void clear() { *this = GR_TextureRef(); }
36 
37  bool isValid() { return isGL() || isVulkan();}
38  bool isGL() const { return myInterop || myRE; }
39  bool isVulkan() const { return myInterop || myRV; }
40 
41  // NOTE: will be nullptr if `isGL` is false
42  RE_Texture* getGL() const;
43  // NOTE: will be NULL if `isVulkan` is false
44  RV_VKImage* getVulkan() const;
45 
46  operator RE_Texture* () const { return this->getGL(); }
47  RE_Texture* operator*() const { return this->getGL(); }
48  RE_Texture* operator->() const { UT_ASSERT(isGL()); return getGL(); }
49 
50  explicit operator RV_VKImage* () const { return getVulkan(); }
51 
52  GR_TextureRef() = default;
53 
54  GR_TextureRef(std::nullptr_t)
55  : GR_TextureRef()
56  {}
57 
59  : myInterop(i), myRE(nullptr), myRV(nullptr)
60  {}
61 
63  : myInterop(nullptr), myRE(re), myRV(nullptr)
64  {}
65 
67  : myInterop(nullptr), myRE(nullptr), myRV(rv)
68  {}
69 
71  : myInterop(nullptr), myRE(re), myRV(rv)
72  {}
73 
74 
75  bool operator==(const GR_TextureRef &rhs) const
76  { return myInterop == rhs.myInterop
77  && myRE == rhs.myRE
78  && myRV == rhs.myRV; }
79  bool operator!=(const GR_TextureRef &rhs) const
80  { return !(*this == rhs); }
81 
82  bool operator==(const RE_Texture *rhs) const
83  { return rhs == getGL(); }
84  bool operator!=(const RE_Texture *rhs) const
85  { return rhs != getGL(); }
86 
87  bool operator==(const RV_VKImage *rhs) const
88  { return rhs == getVulkan(); }
89  bool operator!=(const RV_VKImage *rhs) const
90  { return rhs != getVulkan(); }
91 
92 private:
93  RV_OGLInteropTextureBase* myInterop = nullptr;
94  RE_Texture* myRE = nullptr;
95  RV_VKImage* myRV = nullptr;
96 };
97 
98 #endif
GR_TextureRef(RV_OGLInteropTextureBase *i)
Definition: GR_TextureRef.h:58
bool operator!=(const GR_TextureRef &rhs) const
Definition: GR_TextureRef.h:79
RE_Texture * operator->() const
Definition: GR_TextureRef.h:48
GR_TextureRef(RE_Texture *re)
Definition: GR_TextureRef.h:62
bool isGL() const
Definition: GR_TextureRef.h:38
bool operator==(const RV_VKImage *rhs) const
Definition: GR_TextureRef.h:87
bool operator==(const RE_Texture *rhs) const
Definition: GR_TextureRef.h:82
#define GR_API
Definition: GR_API.h:10
GR_TextureRef(RV_VKImage *rv)
Definition: GR_TextureRef.h:66
bool isVulkan() const
Definition: GR_TextureRef.h:39
GR_TextureRef(std::nullptr_t)
Definition: GR_TextureRef.h:54
bool operator!=(const RE_Texture *rhs) const
Definition: GR_TextureRef.h:84
RE_Texture * operator*() const
Definition: GR_TextureRef.h:47
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
bool operator!=(const RV_VKImage *rhs) const
Definition: GR_TextureRef.h:89
GR_TextureRef(RE_Texture *re, RV_VKImage *rv)
Definition: GR_TextureRef.h:70
bool operator==(const GR_TextureRef &rhs) const
Definition: GR_TextureRef.h:75