HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
texture.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 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_GLF_TEXTURE_H
8 #define PXR_IMAGING_GLF_TEXTURE_H
9 
10 /// \file glf/texture.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/imaging/glf/api.h"
14 #include "pxr/imaging/hio/image.h"
16 #include "pxr/base/tf/refPtr.h"
18 #include "pxr/base/tf/weakPtr.h"
19 #include "pxr/base/vt/dictionary.h"
20 
22 
23 #include <map>
24 #include <string>
25 #include <vector>
26 
28 
29 
30 #define GLF_TEXTURE_TOKENS \
31  (texels) \
32  (layout)
33 
35 
37 
38 /// \class GlfTexture
39 ///
40 /// Represents a texture object in Glf.
41 ///
42 /// A texture is typically defined by reading texture image data from an image
43 /// file but a texture might also represent an attachment of a draw target.
44 ///
45 class GlfTexture : public TfRefBase, public TfWeakBase
46 {
47 public:
48  /// \class Binding
49  ///
50  /// A texture has one or more bindings which describe how the different
51  /// aspects of the texture should be bound in order to allow shader
52  /// access. Most textures will have a single binding for the role
53  /// "texels", but some textures might need multiple bindings, e.g. a
54  /// ptexTexture will have an additional binding for the role "layout".
55  ///
56  struct Binding {
59  : name(name)
60  , role(role)
61  , target(target)
62  , textureId(textureId)
63  , samplerId(samplerId) { }
64 
70  };
71  typedef std::vector<Binding> BindingVector;
72 
73  GLF_API
74  virtual ~GlfTexture() = 0;
75 
76  // Disallow copies
77  GlfTexture(const GlfTexture&) = delete;
78  GlfTexture& operator=(const GlfTexture&) = delete;
79 
80  /// Returns the bindings to use this texture for the shader resource
81  /// named \a identifier. If \a samplerId is specified, the bindings
82  /// returned will use this samplerId for resources which can be sampled.
83  virtual BindingVector GetBindings(TfToken const & identifier,
84  GLuint samplerId = 0) = 0;
85 
86  /// Returns the OpenGl texture name for the texture.
87  virtual GLuint GetGlTextureName() = 0;
88 
89  /// Amount of memory used to store the texture
90  GLF_API
91  size_t GetMemoryUsed() const;
92 
93  /// Amount of memory the user wishes to allocate to the texture
94  GLF_API
95  size_t GetMemoryRequested() const;
96 
97  /// Specify the amount of memory the user wishes to allocate to the texture
98  GLF_API
99  void SetMemoryRequested(size_t targetMemory);
100 
101  virtual VtDictionary GetTextureInfo(bool forceLoad) = 0;
102 
103  GLF_API
104  virtual bool IsMinFilterSupported(GLenum filter);
105 
106  GLF_API
107  virtual bool IsMagFilterSupported(GLenum filter);
108 
109  /// static reporting function
110  GLF_API
111  static size_t GetTextureMemoryAllocated();
112 
113  /// Returns an identifier that can be used to determine when the
114  /// contents of this texture (i.e. its image data) has changed.
115  ///
116  /// The contents of most textures will be immutable for the lifetime
117  /// of the texture. However, the contents of the texture attachments
118  /// of a draw target change when the draw target is updated.
119  GLF_API
120  size_t GetContentsID() const;
121 
122  GLF_API
124 
125  GLF_API
126  bool IsOriginLowerLeft() const;
127 
128 protected:
129  GLF_API
130  GlfTexture();
131 
132  GLF_API
134 
135  GLF_API
136  void _SetMemoryUsed(size_t size);
137 
138  GLF_API
139  virtual void _OnMemoryRequestedDirty();
140 
141  GLF_API
142  void _UpdateContentsID();
143 
144 private:
145  size_t _memoryUsed;
146  size_t _memoryRequested;
147  size_t _contentsID;
148  HioImage::ImageOriginLocation _originLocation;
149 };
150 
152 public:
153  virtual GlfTextureRefPtr New(const TfToken& texturePath,
154  HioImage::ImageOriginLocation originLocation) const = 0;
155 };
156 
158 
159 #endif // PXR_IMAGING_GLF_TEXTURE_H
ImageOriginLocation
Definition: image.h:43
GLF_API GlfTexture()
#define GLF_API
Definition: api.h:23
TF_DECLARE_PUBLIC_TOKENS(GlfTextureTokens, GLF_API, GLF_TEXTURE_TOKENS)
GLF_API size_t GetContentsID() const
virtual GLF_API void _OnMemoryRequestedDirty()
GLuint textureId
Definition: texture.h:68
GLF_API HioImage::ImageOriginLocation GetOriginLocation() const
unsigned int GLuint
Definition: cl.hpp:167
unsigned int GLenum
Definition: cl.hpp:166
virtual BindingVector GetBindings(TfToken const &identifier, GLuint samplerId=0)=0
Base class of all factory types.
Definition: type.h:56
GLF_API void _UpdateContentsID()
virtual VtDictionary GetTextureInfo(bool forceLoad)=0
Definition: token.h:70
static GLF_API size_t GetTextureMemoryAllocated()
static reporting function
TF_DECLARE_WEAK_AND_REF_PTRS(GlfTexture)
GLF_API size_t GetMemoryRequested() const
Amount of memory the user wishes to allocate to the texture.
GLenum target
Definition: glcorearb.h:1667
virtual GLF_API bool IsMinFilterSupported(GLenum filter)
GLuint const GLchar * name
Definition: glcorearb.h:786
GLuint samplerId
Definition: texture.h:69
GlfTexture & operator=(const GlfTexture &)=delete
GLsizeiptr size
Definition: glcorearb.h:664
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
virtual GLF_API bool IsMagFilterSupported(GLenum filter)
GLF_API size_t GetMemoryUsed() const
Amount of memory used to store the texture.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
virtual GLuint GetGlTextureName()=0
Returns the OpenGl texture name for the texture.
virtual GlfTextureRefPtr New(const TfToken &texturePath, HioImage::ImageOriginLocation originLocation) const =0
virtual GLF_API ~GlfTexture()=0
GLF_API void _SetMemoryUsed(size_t size)
GLF_API bool IsOriginLowerLeft() const
#define GLF_TEXTURE_TOKENS
Definition: texture.h:30
std::vector< Binding > BindingVector
Definition: texture.h:71
Binding(TfToken name, TfToken role, GLenum target, GLuint textureId, GLuint samplerId)
Definition: texture.h:57
GLF_API void SetMemoryRequested(size_t targetMemory)
Specify the amount of memory the user wishes to allocate to the texture.
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1297