All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
textureUtils.h
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 
36 PXR_NAMESPACE_OPEN_SCOPE
37 
43 {
44 public:
49  using ConversionFunction =
50  void(*)(const void * src,
51  size_t numTexels,
52  void * dst);
53 
58  HDST_API
59  static
60  HgiFormat GetHgiFormat(
61  HioFormat hioFormat,
62  bool premultiplyAlpha);
63 
68  HDST_API
69  static
71  HioFormat hioFormat,
72  bool premultiplyAlpha);
73 
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
89  ComputeDimensionsFromTargetMemory(
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
106  ReadAndConvertImage(
107  HioImageSharedPtr const &image,
108  bool flipped,
109  bool premultiplyAlpha,
110  const HgiMipInfo &mipInfo,
111  size_t layer,
112  void * bufferStart);
113 };
114 
115 PXR_NAMESPACE_CLOSE_SCOPE
116 
117 #endif
static HDST_API HgiFormat GetHgiFormat(HioFormat hioFormat, bool premultiplyAlpha)
Get the Hgi format suitable for a given Hio format.
SourceColorSpace
Specifies the source color space in which the texture is encoded, with &quot;Auto&quot; indicating the texture ...
Definition: image.h:68
Helpers for loading textures.
Definition: textureUtils.h:42
static HDST_API ConversionFunction GetHioToHgiConversion(HioFormat hioFormat, bool premultiplyAlpha)
Returns the conversion function to return a HioFormat to the corresponding HgiFormat given by GetHgiF...
HgiMipInfo describes size and other info for a mip level.
Definition: types.h:132
Basic type for a vector of 3 int components.
Definition: vec3i.h:61
void(*)(const void *src, size_t numTexels, void *dst) ConversionFunction
Converts given number of texels.
Definition: textureUtils.h:52
static HDST_API std::vector< HioImageSharedPtr > GetAllMipImages(const std::string &filePath, HioImage::SourceColorSpace sourceColorSpace)
Get all mip levels from a file.