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 
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 
38 #include "pxr/imaging/garch/glApi.h"
39 
40 #include <map>
41 #include <string>
42 #include <vector>
43 
44 PXR_NAMESPACE_OPEN_SCOPE
45 
46 
47 #define GLF_TEXTURE_TOKENS \
48  (texels) \
49  (layout)
50 
51 TF_DECLARE_PUBLIC_TOKENS(GlfTextureTokens, GLF_API, GLF_TEXTURE_TOKENS);
52 
54 
62 class GlfTexture : public TfRefBase, public TfWeakBase
63 {
64 public:
73  struct Binding {
74  Binding(TfToken name, TfToken role, GLenum target,
75  GLuint textureId, GLuint samplerId)
76  : name(name)
77  , role(role)
78  , target(target)
79  , textureId(textureId)
80  , samplerId(samplerId) { }
81 
82  TfToken name;
83  TfToken role;
84  GLenum target;
85  GLuint textureId;
86  GLuint samplerId;
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 
100  virtual BindingVector GetBindings(TfToken const & identifier,
101  GLuint samplerId = 0) = 0;
102 
104  virtual GLuint GetGlTextureName() = 0;
105 
107  GLF_API
108  size_t GetMemoryUsed() const;
109 
111  GLF_API
112  size_t GetMemoryRequested() const;
113 
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 
127  GLF_API
128  static size_t GetTextureMemoryAllocated();
129 
136  GLF_API
137  size_t GetContentsID() const;
138 
139  GLF_API
140  HioImage::ImageOriginLocation GetOriginLocation() const;
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 
168 class GlfTextureFactoryBase : public TfType::FactoryBase {
169 public:
170  virtual GlfTextureRefPtr New(const TfToken& texturePath,
171  HioImage::ImageOriginLocation originLocation) const = 0;
172 };
173 
174 PXR_NAMESPACE_CLOSE_SCOPE
175 
176 #endif // PXR_IMAGING_GLF_TEXTURE_H
GLF_API size_t GetMemoryRequested() const
Amount of memory the user wishes to allocate to the texture.
Standard pointer typedefs.
A map with string keys and VtValue values.
Definition: dictionary.h:63
Pointer storage with deletion detection.
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
Definition: declarePtrs.h:89
A texture has one or more bindings which describe how the different aspects of the texture should be ...
Definition: texture.h:73
Base class of all factory types.
Definition: type.h:73
Enable a concrete base class for use with TfRefPtr.
Definition: refBase.h:71
ImageOriginLocation
Specifies whether to treat the image origin as the upper-left corner or the lower left...
Definition: image.h:58
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
virtual GLuint GetGlTextureName()=0
Returns the OpenGl texture name for the texture.
GLF_API size_t GetContentsID() const
Returns an identifier that can be used to determine when the contents of this texture (i...
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:118
GLF_API size_t GetMemoryUsed() const
Amount of memory used to store the texture.
static GLF_API size_t GetTextureMemoryAllocated()
static reporting function
This file defines some macros that are useful for declaring and using static TfTokens.
Reference counting.
virtual BindingVector GetBindings(TfToken const &identifier, GLuint samplerId=0)=0
Returns the bindings to use this texture for the shader resource named identifier.
Represents a texture object in Glf.
Definition: texture.h:62
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:141
GLF_API void SetMemoryRequested(size_t targetMemory)
Specify the amount of memory the user wishes to allocate to the texture.