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 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_GLF_TEXTURE_H
25 #define PXR_IMAGING_GLF_TEXTURE_H
26 
27 /// \file glf/texture.h
28 
29 #include "pxr/pxr.h"
30 #include "pxr/imaging/glf/api.h"
31 #include "pxr/imaging/hio/image.h"
33 #include "pxr/base/tf/refPtr.h"
35 #include "pxr/base/tf/weakPtr.h"
36 #include "pxr/base/vt/dictionary.h"
37 
39 
40 #include <map>
41 #include <string>
42 #include <vector>
43 
45 
46 
47 #define GLF_TEXTURE_TOKENS \
48  (texels) \
49  (layout)
50 
52 
54 
55 /// \class GlfTexture
56 ///
57 /// Represents a texture object in Glf.
58 ///
59 /// A texture is typically defined by reading texture image data from an image
60 /// file but a texture might also represent an attachment of a draw target.
61 ///
62 class GlfTexture : public TfRefBase, public TfWeakBase
63 {
64 public:
65  /// \class Binding
66  ///
67  /// A texture has one or more bindings which describe how the different
68  /// aspects of the texture should be bound in order to allow shader
69  /// access. Most textures will have a single binding for the role
70  /// "texels", but some textures might need multiple bindings, e.g. a
71  /// ptexTexture will have an additional binding for the role "layout".
72  ///
73  struct Binding {
76  : name(name)
77  , role(role)
78  , target(target)
79  , textureId(textureId)
80  , samplerId(samplerId) { }
81 
87  };
88  typedef std::vector<Binding> BindingVector;
89 
90  GLF_API
91  virtual ~GlfTexture() = 0;
92 
93  // Disallow copies
94  GlfTexture(const GlfTexture&) = delete;
95  GlfTexture& operator=(const GlfTexture&) = delete;
96 
97  /// Returns the bindings to use this texture for the shader resource
98  /// named \a identifier. If \a samplerId is specified, the bindings
99  /// returned will use this samplerId for resources which can be sampled.
100  virtual BindingVector GetBindings(TfToken const & identifier,
101  GLuint samplerId = 0) = 0;
102 
103  /// Returns the OpenGl texture name for the texture.
104  virtual GLuint GetGlTextureName() = 0;
105 
106  /// Amount of memory used to store the texture
107  GLF_API
108  size_t GetMemoryUsed() const;
109 
110  /// Amount of memory the user wishes to allocate to the texture
111  GLF_API
112  size_t GetMemoryRequested() const;
113 
114  /// Specify the amount of memory the user wishes to allocate to the texture
115  GLF_API
116  void SetMemoryRequested(size_t targetMemory);
117 
118  virtual VtDictionary GetTextureInfo(bool forceLoad) = 0;
119 
120  GLF_API
121  virtual bool IsMinFilterSupported(GLenum filter);
122 
123  GLF_API
124  virtual bool IsMagFilterSupported(GLenum filter);
125 
126  /// static reporting function
127  GLF_API
128  static size_t GetTextureMemoryAllocated();
129 
130  /// Returns an identifier that can be used to determine when the
131  /// contents of this texture (i.e. its image data) has changed.
132  ///
133  /// The contents of most textures will be immutable for the lifetime
134  /// of the texture. However, the contents of the texture attachments
135  /// of a draw target change when the draw target is updated.
136  GLF_API
137  size_t GetContentsID() const;
138 
139  GLF_API
141 
142  GLF_API
143  bool IsOriginLowerLeft() const;
144 
145 protected:
146  GLF_API
147  GlfTexture();
148 
149  GLF_API
151 
152  GLF_API
153  void _SetMemoryUsed(size_t size);
154 
155  GLF_API
156  virtual void _OnMemoryRequestedDirty();
157 
158  GLF_API
159  void _UpdateContentsID();
160 
161 private:
162  size_t _memoryUsed;
163  size_t _memoryRequested;
164  size_t _contentsID;
165  HioImage::ImageOriginLocation _originLocation;
166 };
167 
169 public:
170  virtual GlfTextureRefPtr New(const TfToken& texturePath,
171  HioImage::ImageOriginLocation originLocation) const = 0;
172 };
173 
175 
176 #endif // PXR_IMAGING_GLF_TEXTURE_H
ImageOriginLocation
Definition: image.h:58
GLF_API GlfTexture()
#define GLF_API
Definition: api.h:40
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:85
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:73
GLF_API void _UpdateContentsID()
virtual VtDictionary GetTextureInfo(bool forceLoad)=0
Definition: token.h:87
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:86
GlfTexture & operator=(const GlfTexture &)=delete
GLsizeiptr size
Definition: glcorearb.h:664
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
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:91
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:47
std::vector< Binding > BindingVector
Definition: texture.h:88
Binding(TfToken name, TfToken role, GLenum target, GLuint textureId, GLuint samplerId)
Definition: texture.h:74
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