cesium-native  0.41.0
TextureView.h
1 #pragma once
2 
3 #include <CesiumGltf/ImageAsset.h>
4 #include <CesiumGltf/KhrTextureTransform.h>
5 #include <CesiumGltf/Sampler.h>
6 #include <CesiumGltf/TextureInfo.h>
7 #include <CesiumUtility/IntrusivePointer.h>
8 
9 #include <vector>
10 
11 namespace CesiumGltf {
12 
13 struct Model;
14 
38 
47  bool makeImageCopy = false;
48 };
49 
57 enum class TextureViewStatus {
61  Valid,
62 
67 
72 
77 
82 
87 
93 };
94 
95 class TextureView {
96 public:
100  TextureView() noexcept;
101 
110  const Model& model,
111  const TextureInfo& textureInfo,
112  const TextureViewOptions& options = TextureViewOptions()) noexcept;
113 
127  const Sampler& sampler,
128  const ImageAsset& image,
129  int64_t textureCoordinateSetIndex,
130  const ExtensionKhrTextureTransform* pKhrTextureTransformExtension =
131  nullptr,
132  const TextureViewOptions& options = TextureViewOptions()) noexcept;
133 
140  return this->_textureViewStatus;
141  }
142 
151  int64_t getTexCoordSetIndex() const noexcept {
152  if (this->_applyTextureTransform && this->_textureTransform) {
153  return this->_textureTransform->getTexCoordSetIndex().value_or(
154  this->_texCoordSetIndex);
155  }
156  return this->_texCoordSetIndex;
157  }
158 
166  const Sampler* getSampler() const noexcept { return this->_pSampler; }
167 
176  const ImageAsset* getImage() const noexcept {
177  if (this->_pImageCopy) {
178  return this->_pImageCopy.get();
179  }
180  return this->_pImage.get();
181  }
182 
195  std::optional<KhrTextureTransform> getTextureTransform() const noexcept {
196  return this->_textureTransform;
197  }
198 
205  std::vector<uint8_t> sampleNearestPixel(
206  double u,
207  double v,
208  const std::vector<int64_t>& channels) const noexcept;
209 
210 private:
211  TextureViewStatus _textureViewStatus;
212 
213  const Sampler* _pSampler;
215  int64_t _texCoordSetIndex;
216 
217  bool _applyTextureTransform;
218  std::optional<KhrTextureTransform> _textureTransform;
219 
221 };
222 } // namespace CesiumGltf
std::vector< uint8_t > sampleNearestPixel(double u, double v, const std::vector< int64_t > &channels) const noexcept
Samples the image at the specified texture coordinates using NEAREST pixel filtering,...
const ImageAsset * getImage() const noexcept
Get the image containing this property's data. If this view was constructed with options....
Definition: TextureView.h:176
TextureViewStatus getTextureViewStatus() const noexcept
Get the status of this texture view.
Definition: TextureView.h:139
const Sampler * getSampler() const noexcept
Get the sampler describing how to sample the data from the property's texture.
Definition: TextureView.h:166
TextureView() noexcept
Constructs an empty, uninitialized texture view.
int64_t getTexCoordSetIndex() const noexcept
Get the texture coordinate set index for this view. If this view was constructed with options....
Definition: TextureView.h:151
std::optional< KhrTextureTransform > getTextureTransform() const noexcept
Get the KHR_texture_transform for this texture if it exists.
Definition: TextureView.h:195
A smart pointer that calls addReference and releaseReference on the controlled object.
Classes for working with glTF models.
TextureViewStatus
Indicates the status of a texture view.
Definition: TextureView.h:57
@ ErrorEmptyImage
This texture is viewing an empty image.
@ ErrorUninitialized
This texture view has not yet been initialized.
@ Valid
This texture view is valid and ready to use.
@ ErrorInvalidSampler
This texture view does not have a valid sampler index.
@ ErrorInvalidImage
This texture view does not have a valid image index.
@ ErrorInvalidBytesPerChannel
The image for this texture has channels that take up more than a byte. Only single-byte channels are ...
@ ErrorInvalidTexture
This texture view does not have a valid texture index.
glTF extension that enables shifting and scaling UV coordinates on a per-texture basis
A 2D image asset, including its pixel data. The image may have mipmaps, and it may be encoded in a GP...
Definition: ImageAsset.h:34
The root object for a glTF asset.
Definition: Model.h:14
Texture sampler properties for filtering and wrapping modes.
Definition: Sampler.h:14
Reference to a texture.
Definition: TextureInfo.h:15
Describes options for constructing a view on a glTF texture.
Definition: TextureView.h:18
bool makeImageCopy
Whether to copy the input image.
Definition: TextureView.h:47
bool applyKhrTextureTransformExtension
Whether to automatically apply the KHR_texture_transform extension to the texture view,...
Definition: TextureView.h:37