HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ptexTexture.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_PTEX_TEXTURE_H
25 #define PXR_IMAGING_GLF_PTEX_TEXTURE_H
26 
27 /// \file glf/ptexTexture.h
28 
29 #include "pxr/pxr.h"
30 #include "pxr/imaging/glf/api.h"
31 
32 #include <string>
33 
35 
36 
37 /// Returns true if the file given by \p imageFilePath represents a ptex file,
38 /// and false otherwise.
39 ///
40 /// This function simply checks the extension of the file name and does not
41 /// otherwise guarantee that the file is in any way valid for reading.
42 ///
43 /// If ptex support is disabled, this function will always return false.
44 ///
45 GLF_API bool GlfIsSupportedPtexTexture(std::string const & imageFilePath);
46 
47 
49 
50 
51 #if defined(PXR_PTEX_SUPPORT_ENABLED) || defined(doxygen)
52 
54 
56 #include "pxr/base/tf/token.h"
57 #include "pxr/base/tf/refPtr.h"
58 #include "pxr/base/tf/weakPtr.h"
59 
61 
62 TF_DECLARE_WEAK_AND_REF_PTRS(GlfPtexTexture);
63 
64 /// \class GlfPtexTexture
65 ///
66 /// Represents a Ptex (per-face texture) object in Glf.
67 ///
68 /// A GlfPtexTexture is currently defined by a file path to a valid Ptex file.
69 /// The current implementation declares _texels as a GL_TEXTURE_2D_ARRAY of n
70 /// pages of a resolution that matches that of the largest face in the Ptex
71 /// file.
72 ///
73 /// Two GL_TEXTURE_BUFFER constructs are used as lookup tables:
74 /// * _pages stores the array index in which a given face is located
75 /// * _layout stores 4 float coordinates : top-left corner and width/height for each face
76 ///
77 /// GLSL fragments use gl_PrimitiveID and gl_TessCoords to access the _pages and _layout
78 /// indirection tables, which provide then texture coordinates for the texels stored in
79 /// the _texels texture array.
80 ///
81 
82 class GlfPtexTexture : public GlfTexture {
83 public:
84  GLF_API
85  ~GlfPtexTexture() override;
86 
87  /// Creates a new instance.
88  GLF_API
89  static GlfPtexTextureRefPtr New(const TfToken &imageFilePath);
90 
91  /// GlfTexture overrides
92  GLF_API
93  BindingVector GetBindings(TfToken const & identifier,
94  GLuint samplerName) override;
95 
96  GLF_API
97  VtDictionary GetTextureInfo(bool forceLoad) override;
98 
99  GLF_API
100  bool IsMinFilterSupported(GLenum filter) override;
101 
102  GLF_API
103  bool IsMagFilterSupported(GLenum filter) override;
104 
105  // get/set guttering control variables
106  static int GetGutterWidth() { return _gutterWidth; }
107 
108  static int GetPageMargin() { return _pageMargin; }
109 
110  // return GL texture for layout texture buffer
111  GLF_API
112  GLuint GetLayoutTextureName();
113 
114  // return GL texture for texels data texture
115  GLF_API
116  GLuint GetGlTextureName() override;
117 
118 protected:
119  GLF_API
120  GlfPtexTexture(const TfToken &imageFilePath);
121 
122  GLF_API
123  void _FreePtexTextureObject();
124 
125  GLF_API
126  void _OnMemoryRequestedDirty() override;
127 
128 private:
129  bool _ReadImage();
130 
131  bool _loaded;
132 
133  GLuint _layout; // per-face lookup table
134  GLuint _texels; // texel data
135 
136  GLsizei _width, _height, _depth;
137  GLint _format;
138 
139  static int _gutterWidth, _pageMargin;
140 
141  const TfToken _imageFilePath;
142 };
143 
145 
146 #endif // PXR_PTEX_SUPPORT_ENABLED
147 
148 #endif // GLF_TEXTURE_H
int GLint
Definition: cl.hpp:165
#define GLF_API
Definition: api.h:40
virtual GLF_API void _OnMemoryRequestedDirty()
unsigned int GLuint
Definition: cl.hpp:167
unsigned int GLenum
Definition: cl.hpp:166
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Definition: declarePtrs.h:89
virtual BindingVector GetBindings(TfToken const &identifier, GLuint samplerId=0)=0
virtual VtDictionary GetTextureInfo(bool forceLoad)=0
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glew.h:2981
Definition: token.h:87
int GLsizei
Definition: glew.h:279
virtual GLF_API bool IsMinFilterSupported(GLenum filter)
PXR_NAMESPACE_OPEN_SCOPE GLF_API bool GlfIsSupportedPtexTexture(std::string const &imageFilePath)
GLsizei const GLchar *const * string
Definition: glew.h:1844
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
virtual GLF_API bool IsMagFilterSupported(GLenum filter)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
virtual GLuint GetGlTextureName()=0
Returns the OpenGl texture name for the texture.