MCPcopy Create free account
hub / github.com/KhronosGroup/KTX-Software / ktxTexture1_constructFromStreamAndHeader

Function ktxTexture1_constructFromStreamAndHeader

lib/texture1.c:186–379  ·  view source on GitHub ↗

* @memberof ktxTexture1 @private * @brief Construct a ktxTexture1 from a ktxStream reading from a KTX source. * * The KTX header, that must have been read prior to calling this, is passed * to the function. * * The stream object is copied into the constructed ktxTexture1. * * The create flag KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT should not be set, * if the ktxTexture1 is ultimately to be

Source from the content-addressed store, hash-verified

184 * supported by OpenGL or Vulkan, e.g, a 3D array.
185 */
186KTX_error_code
187ktxTexture1_constructFromStreamAndHeader(ktxTexture1* This, ktxStream* pStream,
188 KTX_header* pHeader,
189 ktxTextureCreateFlags createFlags)
190{
191 ktxTexture1_private* private;
192 KTX_error_code result;
193 KTX_supplemental_info suppInfo;
194 ktxStream* stream;
195 ktx_off_t pos;
196 ktx_size_t size;
197 ktxFormatSize formatSize;
198
199 assert(pHeader != NULL && pStream != NULL);
200
201 memset(This, 0, sizeof(*This));
202 result = ktxTexture_constructFromStream(ktxTexture(This), pStream, createFlags);
203 if (result != KTX_SUCCESS)
204 return result;
205 result = ktxTexture1_constructCommon(This);
206 if (result != KTX_SUCCESS) {
207 ktxTexture_destruct(ktxTexture(This));
208 return result;
209 }
210
211 private = This->_private;
212 stream = ktxTexture1_getStream(This);
213
214 result = ktxCheckHeader1_(pHeader, &suppInfo);
215 if (result != KTX_SUCCESS)
216 goto cleanup;
217
218 /*
219 * Initialize from pHeader info.
220 */
221 This->glFormat = pHeader->glFormat;
222 This->glInternalformat = pHeader->glInternalformat;
223 This->glType = pHeader->glType;
224 glGetFormatSize(This->glInternalformat, &formatSize);
225 if (formatSize.blockSizeInBits == 0) {
226 // Most likely a deprecated legacy format.
227 result = KTX_UNSUPPORTED_TEXTURE_TYPE;
228 goto cleanup;
229 }
230 This->_protected->_formatSize = formatSize;
231 This->glBaseInternalformat = pHeader->glBaseInternalformat;
232 // Can these be done by a ktxTexture_constructFromStream?
233 This->numDimensions = suppInfo.textureDimension;
234 This->baseWidth = pHeader->pixelWidth;
235 assert(suppInfo.textureDimension > 0 && suppInfo.textureDimension < 4);
236 switch (suppInfo.textureDimension) {
237 case 1:
238 This->baseHeight = This->baseDepth = 1;
239 break;
240 case 2:
241 This->baseHeight = pHeader->pixelHeight;
242 This->baseDepth = 1;
243 break;

Callers 2

Calls 15

assertFunction · 0.85
ktxTexture_destructFunction · 0.85
ktxCheckHeader1_Function · 0.85
glGetFormatSizeFunction · 0.85
ktxHashList_ConstructFunction · 0.85
_ktxSwapEndian32Function · 0.85
ktxHashList_DeserializeFunction · 0.85
ktxHashList_FindValueFunction · 0.85
ktxTexture1_destructFunction · 0.85

Tested by

no test coverage detected