All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
baseTexture.h
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 GLF_BASETEXTURE_H
25 #define GLF_BASETEXTURE_H
26 
28 
29 #include "pxr/pxr.h"
30 #include "pxr/imaging/glf/api.h"
31 #include "pxr/imaging/glf/image.h"
32 #include "pxr/imaging/glf/texture.h"
33 
34 #include "pxr/base/tf/declarePtrs.h"
35 #include "pxr/base/tf/refPtr.h"
36 #include "pxr/base/tf/weakPtr.h"
37 
38 #include "pxr/imaging/garch/gl.h"
39 
40 #include <string>
41 
42 PXR_NAMESPACE_OPEN_SCOPE
43 
44 
46 TF_DECLARE_WEAK_AND_REF_PTRS(GlfBaseTextureData);
47 
52 class GlfBaseTexture : public GlfTexture {
53 public:
54  GLF_API
55  ~GlfBaseTexture() override;
56 
58  GLF_API
59  GLuint GetGlTextureName() override;
60 
62  GLF_API
63  virtual int GetNumDimensions() const = 0;
64 
65  GLF_API
66  int GetWidth();
67 
68  GLF_API
69  int GetHeight();
70 
71  GLF_API
72  int GetDepth();
73 
74  GLF_API
75  int GetFormat();
76 
77  // GlfTexture overrides
78  GLF_API
79  BindingVector GetBindings(TfToken const & identifier,
80  GLuint samplerName) override;
81  GLF_API
82  VtDictionary GetTextureInfo(bool forceLoad) override;
83 
84 
85 protected:
86 
87  GLF_API
89 
90  GLF_API
91  GlfBaseTexture(GlfImage::ImageOriginLocation originLocation);
92 
93  GLF_API
94  void _OnMemoryRequestedDirty() override final;
95 
96  GLF_API
97  virtual void _ReadTexture() = 0;
98 
99  void _ReadTextureIfNotLoaded();
100 
101  GLF_API
102  void _UpdateTexture(GlfBaseTextureDataConstPtr texData);
103  GLF_API
104  void _CreateTexture(GlfBaseTextureDataConstPtr texData,
105  bool useMipmaps,
106  int unpackCropTop = 0,
107  int unpackCropBottom = 0,
108  int unpackCropLeft = 0,
109  int unpackCropRight = 0,
110  int unpackCropFront = 0,
111  int unpackCropBack = 0);
112 
113  GLF_API
114  void _SetLoaded();
115 
116 private:
117 
118  // GL texture object
119  const GLuint _textureName;
120 
121  // required for stats/tracking
122  bool _loaded;
123  int _currentWidth, _currentHeight, _currentDepth;
124  int _format;
125  bool _hasWrapModeS;
126  bool _hasWrapModeT;
127  bool _hasWrapModeR;
128  GLenum _wrapModeS;
129  GLenum _wrapModeT;
130  GLenum _wrapModeR;
131 };
132 
133 
134 PXR_NAMESPACE_CLOSE_SCOPE
135 
136 #endif // GLF_BASETEXTURE_H
GLF_API GLuint GetGlTextureName() override
Returns the OpenGl texture name for the texture.
A map with string keys and VtValue values.
Definition: dictionary.h:61
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
Definition: declarePtrs.h:89
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
ImageOriginLocation
Specifies whether to treat the image origin as the upper-left corner or the lower left...
Definition: image.h:60
Represents a texture object in Glf.
Definition: texture.h:63
virtual GLF_API int GetNumDimensions() const =0
Is this a 1-, 2- or 3-dimensional texture.
Represents a texture object in Glf.
Definition: baseTexture.h:52
GLF_API BindingVector GetBindings(TfToken const &identifier, GLuint samplerName) override
Returns the bindings to use this texture for the shader resource named identifier.