HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
textureUtils.h
Go to the documentation of this file.
1 //
2 // Copyright 2020 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_HD_ST_TEXTURE_UTILS_H
25 #define PXR_IMAGING_HD_ST_TEXTURE_UTILS_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdSt/api.h"
29 
30 #include "pxr/imaging/hio/types.h"
31 #include "pxr/imaging/hio/image.h"
32 #include "pxr/imaging/hgi/types.h"
33 
34 #include <memory>
35 
37 
38 /// \class HdStTextureUtils
39 ///
40 /// Helpers for loading textures.
41 ///
43 {
44 public:
45  /// Converts given number of texels.
46  ///
47  /// Conversion can be in-place if the ends of the source and destination
48  /// buffers align.
49  using ConversionFunction =
50  void(*)(const void * src,
51  size_t numTexels,
52  void * dst);
53 
54  /// Get the Hgi format suitable for a given Hio format.
55  ///
56  /// Premultiply alpha indicates whether a conversion function
57  /// multiplying RGB with alpha should be created.
58  HDST_API
59  static
61  HioFormat hioFormat,
62  bool premultiplyAlpha);
63 
64  /// Returns the conversion function to return a HioFormat
65  /// to the corresponding HgiFormat given by GetHgiFormat.
66  ///
67  /// Returns nullptr if no conversion necessary.
68  HDST_API
69  static
71  HioFormat hioFormat,
72  bool premultiplyAlpha);
73 
74  /// Get all mip levels from a file.
75  HDST_API
76  static
77  std::vector<HioImageSharedPtr> GetAllMipImages(
78  const std::string &filePath,
79  HioImage::SourceColorSpace sourceColorSpace);
80 
81  // Compute dimensions so that all tiles fit into the given target memory.
82  // First by traversing the given images and then by computing a mip chain
83  // starting with the lowest resolution image.
84  // Optionally, can also give the index of the image in mips that was used
85  // to compute the dimensions.
86  HDST_API
87  static
88  GfVec3i
90  const std::vector<HioImageSharedPtr> &mips,
91  HgiFormat targetFormat,
92  size_t tileCount,
93  size_t targetMemory,
94  size_t * mipIndex = nullptr);
95 
96  // Read given HioImage and convert it to corresponding Hgi format.
97  // Returns false if reading the HioImage failed.
98  //
99  // bufferStart is assumed to point at the beginning of a mip chain
100  // with mipInfo describing what mip level of the mip chain to be
101  // filled. layer gives the layer number if the mip chain is for an
102  // array texture.
103  HDST_API
104  static
105  bool
107  HioImageSharedPtr const &image,
108  bool flipped,
109  bool premultiplyAlpha,
110  const HgiMipInfo &mipInfo,
111  size_t layer,
112  void * bufferStart);
113 };
114 
116 
117 #endif
static HDST_API HgiFormat GetHgiFormat(HioFormat hioFormat, bool premultiplyAlpha)
GLenum GLuint GLint GLint layer
Definition: glcorearb.h:1298
void
Definition: png.h:1083
GLenum GLsizei GLenum GLenum const void * image
Definition: glew.h:4973
void(*)(const void *src, size_t numTexels, void *dst) ConversionFunction
Definition: textureUtils.h:52
GLenum src
Definition: glcorearb.h:1792
HgiFormat
Definition: types.h:45
static HDST_API ConversionFunction GetHioToHgiConversion(HioFormat hioFormat, bool premultiplyAlpha)
static HDST_API bool ReadAndConvertImage(HioImageSharedPtr const &image, bool flipped, bool premultiplyAlpha, const HgiMipInfo &mipInfo, size_t layer, void *bufferStart)
static HDST_API GfVec3i ComputeDimensionsFromTargetMemory(const std::vector< HioImageSharedPtr > &mips, HgiFormat targetFormat, size_t tileCount, size_t targetMemory, size_t *mipIndex=nullptr)
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
Definition: vec3i.h:61
HioFormat
Definition: types.h:42
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1375
std::shared_ptr< class HioImage > HioImageSharedPtr
Definition: image.h:44
#define HDST_API
Definition: api.h:40
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
SourceColorSpace
Definition: image.h:68
GLenum GLenum dst
Definition: glcorearb.h:1792
static HDST_API std::vector< HioImageSharedPtr > GetAllMipImages(const std::string &filePath, HioImage::SourceColorSpace sourceColorSpace)
Get all mip levels from a file.