Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/libktx/include/ktx.h
9905 views
1
/* -*- tab-width: 4; -*- */
2
/* vi: set sw=2 ts=4 expandtab: */
3
4
#ifndef KTX_H_A55A6F00956F42F3A137C11929827FE1
5
#define KTX_H_A55A6F00956F42F3A137C11929827FE1
6
7
/*
8
* Copyright 2010-2018 The Khronos Group, Inc.
9
* SPDX-License-Identifier: Apache-2.0
10
*
11
* See the accompanying LICENSE.md for licensing details for all files in
12
* the KTX library and KTX loader tests.
13
*/
14
15
/**
16
* @file
17
* @~English
18
*
19
* @brief Declares the public functions and structures of the
20
* KTX API.
21
*
22
* @author Mark Callow, Edgewise Consulting and while at HI Corporation
23
* @author Based on original work by Georg Kolling, Imagination Technology
24
*
25
* @snippet{doc} version.h API version
26
*/
27
28
#include <limits.h>
29
#include <stdio.h>
30
#include <stdbool.h>
31
#include <sys/types.h>
32
33
#include <KHR/khr_df.h>
34
35
/*
36
* Don't use khrplatform.h in order not to break apps existing
37
* before these definitions were needed.
38
*/
39
#if defined(KHRONOS_STATIC)
40
#define KTX_API
41
#elif defined(_WIN32) || defined(__CYGWIN__)
42
#if !defined(KTX_API)
43
#if __GNUC__
44
#define KTX_API __attribute__ ((dllimport))
45
#elif _MSC_VER
46
#define KTX_API __declspec(dllimport)
47
#else
48
#error "Your compiler's equivalent of dllimport is unknown"
49
#endif
50
#endif
51
#elif defined(__ANDROID__)
52
#define KTX_API __attribute__((visibility("default")))
53
#else
54
#define KTX_API
55
#endif
56
57
#if defined(_WIN32) && !defined(KHRONOS_STATIC)
58
#if !defined(KTX_APIENTRY)
59
#define KTX_APIENTRY __stdcall
60
#endif
61
#else
62
#define KTX_APIENTRY
63
#endif
64
65
/* To avoid including <KHR/khrplatform.h> define our own types. */
66
typedef unsigned char ktx_uint8_t;
67
typedef bool ktx_bool_t;
68
#ifdef _MSC_VER
69
typedef unsigned __int16 ktx_uint16_t;
70
typedef signed __int16 ktx_int16_t;
71
typedef unsigned __int32 ktx_uint32_t;
72
typedef signed __int32 ktx_int32_t;
73
typedef size_t ktx_size_t;
74
typedef unsigned __int64 ktx_uint64_t;
75
typedef signed __int64 ktx_int64_t;
76
#else
77
#include <stdint.h>
78
typedef uint16_t ktx_uint16_t;
79
typedef int16_t ktx_int16_t;
80
typedef uint32_t ktx_uint32_t;
81
typedef int32_t ktx_int32_t;
82
typedef size_t ktx_size_t;
83
typedef uint64_t ktx_uint64_t;
84
typedef int64_t ktx_int64_t;
85
#endif
86
87
/* This will cause compilation to fail if size of uint32 != 4. */
88
typedef unsigned char ktx_uint32_t_SIZE_ASSERT[sizeof(ktx_uint32_t) == 4];
89
90
/*
91
* This #if allows libktx to be compiled with strict c99. It avoids
92
* compiler warnings or even errors when a gl.h is already included.
93
* "Redefinition of (type) is a c11 feature". Obviously this doesn't help if
94
* gl.h comes after. However nobody has complained about the unguarded typedefs
95
* since they were introduced so this is unlikely to be a problem in practice.
96
* Presumably everybody is using platform default compilers not c99 or else
97
* they are using C++.
98
*/
99
#if !defined(GL_NO_ERROR)
100
/*
101
* To avoid having to including gl.h ...
102
*/
103
typedef unsigned char GLboolean;
104
typedef unsigned int GLenum;
105
typedef int GLint;
106
typedef int GLsizei;
107
typedef unsigned int GLuint;
108
typedef unsigned char GLubyte;
109
#endif
110
111
#ifdef __cplusplus
112
extern "C" {
113
#endif
114
115
/**
116
* @~English
117
* @brief Key string for standard writer metadata.
118
*/
119
#define KTX_ANIMDATA_KEY "KTXanimData"
120
/**
121
* @~English
122
* @brief Key string for standard orientation metadata.
123
*/
124
#define KTX_ORIENTATION_KEY "KTXorientation"
125
/**
126
* @~English
127
* @brief Key string for standard swizzle metadata.
128
*/
129
#define KTX_SWIZZLE_KEY "KTXswizzle"
130
/**
131
* @~English
132
* @brief Key string for standard writer metadata.
133
*/
134
#define KTX_WRITER_KEY "KTXwriter"
135
/**
136
* @~English
137
* @brief Key string for standard writer supercompression parameter metadata.
138
*/
139
#define KTX_WRITER_SCPARAMS_KEY "KTXwriterScParams"
140
/**
141
* @~English
142
* @brief Standard KTX 1 format for 1D orientation value.
143
*/
144
#define KTX_ORIENTATION1_FMT "S=%c"
145
/**
146
* @~English
147
* @brief Standard KTX 1 format for 2D orientation value.
148
*/
149
#define KTX_ORIENTATION2_FMT "S=%c,T=%c"
150
/**
151
* @~English
152
* @brief Standard KTX 1 format for 3D orientation value.
153
*/
154
#define KTX_ORIENTATION3_FMT "S=%c,T=%c,R=%c"
155
/**
156
* @~English
157
* @brief Required unpack alignment
158
*/
159
#define KTX_GL_UNPACK_ALIGNMENT 4
160
#define KTX_FACESLICE_WHOLE_LEVEL UINT_MAX
161
162
#define KTX_TRUE true
163
#define KTX_FALSE false
164
165
/**
166
* @~English
167
* @brief Error codes returned by library functions.
168
*/
169
typedef enum ktx_error_code_e {
170
KTX_SUCCESS = 0, /*!< Operation was successful. */
171
KTX_FILE_DATA_ERROR, /*!< The data in the file is inconsistent with the spec. */
172
KTX_FILE_ISPIPE, /*!< The file is a pipe or named pipe. */
173
KTX_FILE_OPEN_FAILED, /*!< The target file could not be opened. */
174
KTX_FILE_OVERFLOW, /*!< The operation would exceed the max file size. */
175
KTX_FILE_READ_ERROR, /*!< An error occurred while reading from the file. */
176
KTX_FILE_SEEK_ERROR, /*!< An error occurred while seeking in the file. */
177
KTX_FILE_UNEXPECTED_EOF, /*!< File does not have enough data to satisfy request. */
178
KTX_FILE_WRITE_ERROR, /*!< An error occurred while writing to the file. */
179
KTX_GL_ERROR, /*!< GL operations resulted in an error. */
180
KTX_INVALID_OPERATION, /*!< The operation is not allowed in the current state. */
181
KTX_INVALID_VALUE, /*!< A parameter value was not valid. */
182
KTX_NOT_FOUND, /*!< Requested metadata key or required dynamically loaded GPU function was not found. */
183
KTX_OUT_OF_MEMORY, /*!< Not enough memory to complete the operation. */
184
KTX_TRANSCODE_FAILED, /*!< Transcoding of block compressed texture failed. */
185
KTX_UNKNOWN_FILE_FORMAT, /*!< The file not a KTX file */
186
KTX_UNSUPPORTED_TEXTURE_TYPE, /*!< The KTX file specifies an unsupported texture type. */
187
KTX_UNSUPPORTED_FEATURE, /*!< Feature not included in in-use library or not yet implemented. */
188
KTX_LIBRARY_NOT_LINKED, /*!< Library dependency (OpenGL or Vulkan) not linked into application. */
189
KTX_DECOMPRESS_LENGTH_ERROR, /*!< Decompressed byte count does not match expected byte size */
190
KTX_DECOMPRESS_CHECKSUM_ERROR, /*!< Checksum mismatch when decompressing */
191
KTX_ERROR_MAX_ENUM = KTX_DECOMPRESS_CHECKSUM_ERROR /*!< For safety checks. */
192
} ktx_error_code_e;
193
/**
194
* @~English
195
* @deprecated Use #ktx_error_code_e.
196
* @brief For backward compatibility
197
*/
198
#define KTX_error_code ktx_error_code_e
199
200
#define KTX_IDENTIFIER_REF { 0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A }
201
#define KTX_ENDIAN_REF (0x04030201)
202
#define KTX_ENDIAN_REF_REV (0x01020304)
203
#define KTX_HEADER_SIZE (64)
204
205
/**
206
* @~English
207
* @brief Result codes returned by library functions.
208
*/
209
typedef enum ktx_error_code_e ktxResult;
210
211
/**
212
* @class ktxHashList
213
* @~English
214
* @brief Opaque handle to a ktxHashList.
215
*/
216
typedef struct ktxKVListEntry* ktxHashList;
217
218
typedef struct ktxStream ktxStream;
219
220
#define KTX_APIENTRYP KTX_APIENTRY *
221
/**
222
* @class ktxHashListEntry
223
* @~English
224
* @brief Opaque handle to an entry in a @ref ktxHashList.
225
*/
226
typedef struct ktxKVListEntry ktxHashListEntry;
227
228
typedef enum ktxOrientationX {
229
KTX_ORIENT_X_LEFT = 'l', KTX_ORIENT_X_RIGHT = 'r'
230
} ktxOrientationX;
231
232
typedef enum ktxOrientationY {
233
KTX_ORIENT_Y_UP = 'u', KTX_ORIENT_Y_DOWN = 'd'
234
} ktxOrientationY;
235
236
typedef enum ktxOrientationZ {
237
KTX_ORIENT_Z_IN = 'i', KTX_ORIENT_Z_OUT = 'o'
238
} ktxOrientationZ;
239
240
typedef enum class_id {
241
ktxTexture1_c = 1,
242
ktxTexture2_c = 2
243
} class_id;
244
245
/**
246
* @~English
247
* @brief Struct describing the logical orientation of an image.
248
*/
249
struct ktxOrientation {
250
ktxOrientationX x; /*!< Orientation in X */
251
ktxOrientationY y; /*!< Orientation in Y */
252
ktxOrientationZ z; /*!< Orientation in Z */
253
};
254
255
#define KTXTEXTURECLASSDEFN \
256
class_id classId; \
257
struct ktxTexture_vtbl* vtbl; \
258
struct ktxTexture_vvtbl* vvtbl; \
259
struct ktxTexture_protected* _protected; \
260
ktx_bool_t isArray; \
261
ktx_bool_t isCubemap; \
262
ktx_bool_t isCompressed; \
263
ktx_bool_t generateMipmaps; \
264
ktx_uint32_t baseWidth; \
265
ktx_uint32_t baseHeight; \
266
ktx_uint32_t baseDepth; \
267
ktx_uint32_t numDimensions; \
268
ktx_uint32_t numLevels; \
269
ktx_uint32_t numLayers; \
270
ktx_uint32_t numFaces; \
271
struct ktxOrientation orientation; \
272
ktxHashList kvDataHead; \
273
ktx_uint32_t kvDataLen; \
274
ktx_uint8_t* kvData; \
275
ktx_size_t dataSize; \
276
ktx_uint8_t* pData;
277
278
279
/**
280
* @class ktxTexture
281
* @~English
282
* @brief Base class representing a texture.
283
*
284
* ktxTextures should be created only by one of the provided
285
* functions and these fields should be considered read-only.
286
*/
287
typedef struct ktxTexture {
288
KTXTEXTURECLASSDEFN
289
} ktxTexture;
290
/**
291
* @typedef ktxTexture::classId
292
* @~English
293
* @brief Identify the class type.
294
*
295
* Since there are no public ktxTexture constructors, this can only have
296
* values of ktxTexture1_c or ktxTexture2_c.
297
*/
298
/**
299
* @typedef ktxTexture::vtbl
300
* @~English
301
* @brief Pointer to the class's vtble.
302
*/
303
/**
304
* @typedef ktxTexture::vvtbl
305
* @~English
306
* @brief Pointer to the class's vtble for Vulkan functions.
307
*
308
* A separate vtble is used so this header does not need to include vulkan.h.
309
*/
310
/**
311
* @typedef ktxTexture::_protected
312
* @~English
313
* @brief Opaque pointer to the class's protected variables.
314
*/
315
/**
316
* @typedef ktxTexture::isArray
317
* @~English
318
*
319
* KTX_TRUE if the texture is an array texture, i.e,
320
* a GL_TEXTURE_*_ARRAY target is to be used.
321
*/
322
/**
323
* @typedef ktxTexture::isCubemap
324
* @~English
325
*
326
* KTX_TRUE if the texture is a cubemap or cubemap array.
327
*/
328
/**
329
* @typedef ktxTexture::isCompressed
330
* @~English
331
*
332
* KTX_TRUE if the texture's format is a block compressed format.
333
*/
334
/**
335
* @typedef ktxTexture::generateMipmaps
336
* @~English
337
*
338
* KTX_TRUE if mipmaps should be generated for the texture by
339
* ktxTexture_GLUpload() or ktxTexture_VkUpload().
340
*/
341
/**
342
* @typedef ktxTexture::baseWidth
343
* @~English
344
* @brief Width of the texture's base level.
345
*/
346
/**
347
* @typedef ktxTexture::baseHeight
348
* @~English
349
* @brief Height of the texture's base level.
350
*/
351
/**
352
* @typedef ktxTexture::baseDepth
353
* @~English
354
* @brief Depth of the texture's base level.
355
*/
356
/**
357
* @typedef ktxTexture::numDimensions
358
* @~English
359
* @brief Number of dimensions in the texture: 1, 2 or 3.
360
*/
361
/**
362
* @typedef ktxTexture::numLevels
363
* @~English
364
* @brief Number of mip levels in the texture.
365
*
366
* Must be 1, if @c generateMipmaps is KTX_TRUE. Can be less than a
367
* full pyramid but always starts at the base level.
368
*/
369
/**
370
* @typedef ktxTexture::numLevels
371
* @~English
372
* @brief Number of array layers in the texture.
373
*/
374
/**
375
* @typedef ktxTexture::numFaces
376
* @~English
377
* @brief Number of faces: 6 for cube maps, 1 otherwise.
378
*/
379
/**
380
* @typedef ktxTexture::orientation
381
* @~English
382
* @brief Describes the logical orientation of the images in each dimension.
383
*
384
* ktxOrientationX for X, ktxOrientationY for Y and ktxOrientationZ for Z.
385
*/
386
/**
387
* @typedef ktxTexture::kvDataHead
388
* @~English
389
* @brief Head of the hash list of metadata.
390
*/
391
/**
392
* @typedef ktxTexture::kvDataLen
393
* @~English
394
* @brief Length of the metadata, if it has been extracted in its raw form,
395
* otherwise 0.
396
*/
397
/**
398
* @typedef ktxTexture::kvData
399
* @~English
400
* @brief Pointer to the metadata, if it has been extracted in its raw form,
401
* otherwise NULL.
402
*/
403
/**
404
* @typedef ktxTexture::dataSize
405
* @~English
406
* @brief Byte length of the texture's uncompressed image data.
407
*/
408
/**
409
* @typedef ktxTexture::pData
410
* @~English
411
* @brief Pointer to the start of the image data.
412
*/
413
414
/**
415
* @memberof ktxTexture
416
* @~English
417
* @brief Signature of function called by the <tt>ktxTexture_Iterate*</tt>
418
* functions to receive image data.
419
*
420
* The function parameters are used to pass values which change for each image.
421
* Obtain values which are uniform across all images from the @c ktxTexture
422
* object.
423
*
424
* @param [in] miplevel MIP level from 0 to the max level which is
425
* dependent on the texture size.
426
* @param [in] face usually 0; for cube maps, one of the 6 cube
427
* faces in the order +X, -X, +Y, -Y, +Z, -Z,
428
* 0 to 5.
429
* @param [in] width width of the image.
430
* @param [in] height height of the image or, for 1D textures
431
* textures, 1.
432
* @param [in] depth depth of the image or, for 1D & 2D
433
* textures, 1.
434
* @param [in] faceLodSize number of bytes of data pointed at by
435
* @p pixels.
436
* @param [in] pixels pointer to the image data.
437
* @param [in,out] userdata pointer for the application to pass data to and
438
* from the callback function.
439
*/
440
441
typedef KTX_error_code
442
(* PFNKTXITERCB)(int miplevel, int face,
443
int width, int height, int depth,
444
ktx_uint64_t faceLodSize,
445
void* pixels, void* userdata);
446
447
/* Don't use KTX_APIENTRYP to avoid a Doxygen bug. */
448
typedef void (KTX_APIENTRY* PFNKTEXDESTROY)(ktxTexture* This);
449
typedef KTX_error_code
450
(KTX_APIENTRY* PFNKTEXGETIMAGEOFFSET)(ktxTexture* This, ktx_uint32_t level,
451
ktx_uint32_t layer,
452
ktx_uint32_t faceSlice,
453
ktx_size_t* pOffset);
454
typedef ktx_size_t
455
(KTX_APIENTRY* PFNKTEXGETDATASIZEUNCOMPRESSED)(ktxTexture* This);
456
typedef ktx_size_t
457
(KTX_APIENTRY* PFNKTEXGETIMAGESIZE)(ktxTexture* This, ktx_uint32_t level);
458
typedef ktx_size_t
459
(KTX_APIENTRY* PFNKTEXGETLEVELSIZE)(ktxTexture* This, ktx_uint32_t level);
460
typedef KTX_error_code
461
(KTX_APIENTRY* PFNKTEXITERATELEVELS)(ktxTexture* This, PFNKTXITERCB iterCb,
462
void* userdata);
463
464
typedef KTX_error_code
465
(KTX_APIENTRY* PFNKTEXITERATELOADLEVELFACES)(ktxTexture* This,
466
PFNKTXITERCB iterCb,
467
void* userdata);
468
typedef KTX_error_code
469
(KTX_APIENTRY* PFNKTEXLOADIMAGEDATA)(ktxTexture* This,
470
ktx_uint8_t* pBuffer,
471
ktx_size_t bufSize);
472
typedef ktx_bool_t
473
(KTX_APIENTRY* PFNKTEXNEEDSTRANSCODING)(ktxTexture* This);
474
475
typedef KTX_error_code
476
(KTX_APIENTRY* PFNKTEXSETIMAGEFROMMEMORY)(ktxTexture* This,
477
ktx_uint32_t level,
478
ktx_uint32_t layer,
479
ktx_uint32_t faceSlice,
480
const ktx_uint8_t* src,
481
ktx_size_t srcSize);
482
483
typedef KTX_error_code
484
(KTX_APIENTRY* PFNKTEXSETIMAGEFROMSTDIOSTREAM)(ktxTexture* This,
485
ktx_uint32_t level,
486
ktx_uint32_t layer,
487
ktx_uint32_t faceSlice,
488
FILE* src, ktx_size_t srcSize);
489
typedef KTX_error_code
490
(KTX_APIENTRY* PFNKTEXWRITETOSTDIOSTREAM)(ktxTexture* This, FILE* dstsstr);
491
typedef KTX_error_code
492
(KTX_APIENTRY* PFNKTEXWRITETONAMEDFILE)(ktxTexture* This,
493
const char* const dstname);
494
typedef KTX_error_code
495
(KTX_APIENTRY* PFNKTEXWRITETOMEMORY)(ktxTexture* This,
496
ktx_uint8_t** bytes, ktx_size_t* size);
497
typedef KTX_error_code
498
(KTX_APIENTRY* PFNKTEXWRITETOSTREAM)(ktxTexture* This,
499
ktxStream* dststr);
500
501
/**
502
* @memberof ktxTexture
503
* @~English
504
* @brief Table of virtual ktxTexture methods.
505
*/
506
struct ktxTexture_vtbl {
507
PFNKTEXDESTROY Destroy;
508
PFNKTEXGETIMAGEOFFSET GetImageOffset;
509
PFNKTEXGETDATASIZEUNCOMPRESSED GetDataSizeUncompressed;
510
PFNKTEXGETIMAGESIZE GetImageSize;
511
PFNKTEXGETLEVELSIZE GetLevelSize;
512
PFNKTEXITERATELEVELS IterateLevels;
513
PFNKTEXITERATELOADLEVELFACES IterateLoadLevelFaces;
514
PFNKTEXNEEDSTRANSCODING NeedsTranscoding;
515
PFNKTEXLOADIMAGEDATA LoadImageData;
516
PFNKTEXSETIMAGEFROMMEMORY SetImageFromMemory;
517
PFNKTEXSETIMAGEFROMSTDIOSTREAM SetImageFromStdioStream;
518
PFNKTEXWRITETOSTDIOSTREAM WriteToStdioStream;
519
PFNKTEXWRITETONAMEDFILE WriteToNamedFile;
520
PFNKTEXWRITETOMEMORY WriteToMemory;
521
PFNKTEXWRITETOSTREAM WriteToStream;
522
};
523
524
/****************************************************************
525
* Macros to give some backward compatibility to the previous API
526
****************************************************************/
527
528
/**
529
* @~English
530
* @brief Helper for calling the Destroy virtual method of a ktxTexture.
531
* @copydoc ktxTexture2.ktxTexture2_Destroy
532
*/
533
#define ktxTexture_Destroy(This) (This)->vtbl->Destroy(This)
534
535
/**
536
* @~English
537
* @brief Helper for calling the GetImageOffset virtual method of a
538
* ktxTexture.
539
* @copydoc ktxTexture2.ktxTexture2_GetImageOffset
540
*/
541
#define ktxTexture_GetImageOffset(This, level, layer, faceSlice, pOffset) \
542
(This)->vtbl->GetImageOffset(This, level, layer, faceSlice, pOffset)
543
544
/**
545
* @~English
546
* @brief Helper for calling the GetDataSizeUncompressed virtual method of a ktxTexture.
547
*
548
* For a ktxTexture1 this will always return the value of This->dataSize.
549
*
550
* @copydetails ktxTexture2.ktxTexture2_GetDataSizeUncompressed
551
*/
552
#define ktxTexture_GetDataSizeUncompressed(This) \
553
(This)->vtbl->GetDataSizeUncompressed(This)
554
555
/**
556
* @~English
557
* @brief Helper for calling the GetImageSize virtual method of a ktxTexture.
558
* @copydoc ktxTexture2.ktxTexture2_GetImageSize
559
*/
560
#define ktxTexture_GetImageSize(This, level) \
561
(This)->vtbl->GetImageSize(This, level)
562
563
/**
564
* @~English
565
* @brief Helper for calling the GetImageSize virtual method of a ktxTexture.
566
* @copydoc ktxTexture2.ktxTexture2_GetImageSize
567
*/
568
#define ktxTexture_GetLevelSize(This, level) \
569
(This)->vtbl->GetLevelSize(This, level)
570
571
/**
572
* @~English
573
* @brief Helper for calling the IterateLevels virtual method of a ktxTexture.
574
* @copydoc ktxTexture2.ktxTexture2_IterateLevels
575
*/
576
#define ktxTexture_IterateLevels(This, iterCb, userdata) \
577
(This)->vtbl->IterateLevels(This, iterCb, userdata)
578
579
/**
580
* @~English
581
* @brief Helper for calling the IterateLoadLevelFaces virtual method of a
582
* ktxTexture.
583
* @copydoc ktxTexture2.ktxTexture2_IterateLoadLevelFaces
584
*/
585
#define ktxTexture_IterateLoadLevelFaces(This, iterCb, userdata) \
586
(This)->vtbl->IterateLoadLevelFaces(This, iterCb, userdata)
587
588
/**
589
* @~English
590
* @brief Helper for calling the LoadImageData virtual method of a ktxTexture.
591
* @copydoc ktxTexture2.ktxTexture2_LoadImageData
592
*/
593
#define ktxTexture_LoadImageData(This, pBuffer, bufSize) \
594
(This)->vtbl->LoadImageData(This, pBuffer, bufSize)
595
596
/**
597
* @~English
598
* @brief Helper for calling the NeedsTranscoding virtual method of a ktxTexture.
599
* @copydoc ktxTexture2.ktxTexture2_NeedsTranscoding
600
*/
601
#define ktxTexture_NeedsTranscoding(This) (This)->vtbl->NeedsTranscoding(This)
602
603
/**
604
* @~English
605
* @brief Helper for calling the SetImageFromMemory virtual method of a
606
* ktxTexture.
607
* @copydoc ktxTexture2.ktxTexture2_SetImageFromMemory
608
*/
609
#define ktxTexture_SetImageFromMemory(This, level, layer, faceSlice, \
610
src, srcSize) \
611
(This)->vtbl->SetImageFromMemory(This, level, layer, faceSlice, src, srcSize)
612
613
/**
614
* @~English
615
* @brief Helper for calling the SetImageFromStdioStream virtual method of a
616
* ktxTexture.
617
* @copydoc ktxTexture2.ktxTexture2_SetImageFromStdioStream
618
*/
619
#define ktxTexture_SetImageFromStdioStream(This, level, layer, faceSlice, \
620
src, srcSize) \
621
(This)->vtbl->SetImageFromStdioStream(This, level, layer, faceSlice, \
622
src, srcSize)
623
624
/**
625
* @~English
626
* @brief Helper for calling the WriteToStdioStream virtual method of a
627
* ktxTexture.
628
* @copydoc ktxTexture2.ktxTexture2_WriteToStdioStream
629
*/
630
#define ktxTexture_WriteToStdioStream(This, dstsstr) \
631
(This)->vtbl->WriteToStdioStream(This, dstsstr)
632
633
/**
634
* @~English
635
* @brief Helper for calling the WriteToNamedfile virtual method of a
636
* ktxTexture.
637
* @copydoc ktxTexture2.ktxTexture2_WriteToNamedFile
638
*/
639
#define ktxTexture_WriteToNamedFile(This, dstname) \
640
(This)->vtbl->WriteToNamedFile(This, dstname)
641
642
/**
643
* @~English
644
* @brief Helper for calling the WriteToMemory virtual method of a ktxTexture.
645
* @copydoc ktxTexture2.ktxTexture2_WriteToMemory
646
*/
647
#define ktxTexture_WriteToMemory(This, ppDstBytes, pSize) \
648
(This)->vtbl->WriteToMemory(This, ppDstBytes, pSize)
649
650
/**
651
* @~English
652
* @brief Helper for calling the WriteToStream virtual method of a ktxTexture.
653
* @copydoc ktxTexture2.ktxTexture2_WriteToStream
654
*/
655
#define ktxTexture_WriteToStream(This, dststr) \
656
(This)->vtbl->WriteToStream(This, dststr)
657
658
659
/**
660
* @class ktxTexture1
661
* @~English
662
* @brief Class representing a KTX version 1 format texture.
663
*
664
* ktxTextures should be created only by one of the ktxTexture_Create*
665
* functions and these fields should be considered read-only.
666
*/
667
typedef struct ktxTexture1 {
668
KTXTEXTURECLASSDEFN
669
ktx_uint32_t glFormat; /*!< Format of the texture data, e.g., GL_RGB. */
670
ktx_uint32_t glInternalformat; /*!< Internal format of the texture data,
671
e.g., GL_RGB8. */
672
ktx_uint32_t glBaseInternalformat; /*!< Base format of the texture data,
673
e.g., GL_RGB. */
674
ktx_uint32_t glType; /*!< Type of the texture data, e.g, GL_UNSIGNED_BYTE.*/
675
struct ktxTexture1_private* _private; /*!< Private data. */
676
} ktxTexture1;
677
678
/*===========================================================*
679
* KTX format version 2 *
680
*===========================================================*/
681
682
/**
683
* @~English
684
* @brief Enumerators identifying the supercompression scheme.
685
*/
686
typedef enum ktxSupercmpScheme {
687
KTX_SS_NONE = 0, /*!< No supercompression. */
688
KTX_SS_BASIS_LZ = 1, /*!< Basis LZ supercompression. */
689
KTX_SS_ZSTD = 2, /*!< ZStd supercompression. */
690
KTX_SS_ZLIB = 3, /*!< ZLIB supercompression. */
691
KTX_SS_BEGIN_RANGE = KTX_SS_NONE,
692
KTX_SS_END_RANGE = KTX_SS_ZLIB,
693
KTX_SS_BEGIN_VENDOR_RANGE = 0x10000,
694
KTX_SS_END_VENDOR_RANGE = 0x1ffff,
695
KTX_SS_BEGIN_RESERVED = 0x20000
696
} ktxSupercmpScheme;
697
698
/**
699
* @class ktxTexture2
700
* @~English
701
* @brief Class representing a KTX version 2 format texture.
702
*
703
* ktxTextures should be created only by one of the ktxTexture_Create*
704
* functions and these fields should be considered read-only.
705
*/
706
typedef struct ktxTexture2 {
707
KTXTEXTURECLASSDEFN
708
ktx_uint32_t vkFormat;
709
ktx_uint32_t* pDfd;
710
ktxSupercmpScheme supercompressionScheme;
711
ktx_bool_t isVideo;
712
ktx_uint32_t duration;
713
ktx_uint32_t timescale;
714
ktx_uint32_t loopcount;
715
struct ktxTexture2_private* _private; /*!< Private data. */
716
} ktxTexture2;
717
718
/*
719
* If Doxygen sees this macro it gets confused and fails to spot
720
* references to ktxTexture_*() functions in the running text. It
721
* also complains it can't find the reference when @ref is used
722
* with a fully qualified method name to make an intra-class
723
* reference in the @c ktxTexture class.
724
* See https://github.com/doxygen/doxygen/issues/10311.
725
*
726
* Not documenting the macro is the lesser of two evils.
727
*/
728
#if !defined(KTX_DOXYGEN_SKIP)
729
/**
730
* @brief Helper for casting ktxTexture1 and ktxTexture2 to ktxTexture.
731
*
732
* Use with caution.
733
*/
734
#define ktxTexture(t) ((ktxTexture*)t)
735
#endif
736
737
/**
738
* @memberof ktxTexture
739
* @~English
740
* @brief Structure for passing texture information to ktxTexture1\_Create() and
741
* ktxTexture2\_Create().
742
*
743
* @sa @ref ktxTexture1::ktxTexture1\_Create() "ktxTexture1_Create()"
744
* @sa @ref ktxTexture2::ktxTexture2\_Create() "ktxTexture2_Create()"
745
*/
746
typedef struct
747
{
748
ktx_uint32_t glInternalformat; /*!< Internal format for the texture, e.g.,
749
GL_RGB8. Ignored when creating a
750
ktxTexture2. */
751
ktx_uint32_t vkFormat; /*!< VkFormat for texture. Ignored when creating a
752
ktxTexture1. */
753
ktx_uint32_t* pDfd; /*!< Pointer to DFD. Used only when creating a
754
ktxTexture2 and only if vkFormat is
755
VK_FORMAT_UNDEFINED. */
756
ktx_uint32_t baseWidth; /*!< Width of the base level of the texture. */
757
ktx_uint32_t baseHeight; /*!< Height of the base level of the texture. */
758
ktx_uint32_t baseDepth; /*!< Depth of the base level of the texture. */
759
ktx_uint32_t numDimensions; /*!< Number of dimensions in the texture, 1, 2
760
or 3. */
761
ktx_uint32_t numLevels; /*!< Number of mip levels in the texture. Should be
762
1 if @c generateMipmaps is KTX_TRUE; */
763
ktx_uint32_t numLayers; /*!< Number of array layers in the texture. */
764
ktx_uint32_t numFaces; /*!< Number of faces: 6 for cube maps, 1 otherwise. */
765
ktx_bool_t isArray; /*!< Set to KTX_TRUE if the texture is to be an
766
array texture. Means OpenGL will use a
767
GL_TEXTURE_*_ARRAY target. */
768
ktx_bool_t generateMipmaps; /*!< Set to KTX_TRUE if mipmaps should be
769
generated for the texture when loading
770
into a 3D API. */
771
} ktxTextureCreateInfo;
772
773
/**
774
* @memberof ktxTexture
775
* @~English
776
* @brief Enum for requesting, or not, allocation of storage for images.
777
*
778
* @sa ktxTexture1_Create() and ktxTexture2_Create().
779
*/
780
typedef enum {
781
KTX_TEXTURE_CREATE_NO_STORAGE = 0, /*!< Don't allocate any image storage. */
782
KTX_TEXTURE_CREATE_ALLOC_STORAGE = 1 /*!< Allocate image storage. */
783
} ktxTextureCreateStorageEnum;
784
785
/**
786
* @memberof ktxTexture
787
* @~English
788
* @brief Flags for requesting services during creation.
789
*
790
* @sa ktxTexture_CreateFrom*
791
*/
792
enum ktxTextureCreateFlagBits {
793
KTX_TEXTURE_CREATE_NO_FLAGS = 0x00,
794
KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT = 0x01,
795
/*!< Load the images from the KTX source. */
796
KTX_TEXTURE_CREATE_RAW_KVDATA_BIT = 0x02,
797
/*!< Load the raw key-value data instead of
798
creating a @c ktxHashList from it. */
799
KTX_TEXTURE_CREATE_SKIP_KVDATA_BIT = 0x04,
800
/*!< Skip any key-value data. This overrides
801
the RAW_KVDATA_BIT. */
802
KTX_TEXTURE_CREATE_CHECK_GLTF_BASISU_BIT = 0x08
803
/*!< Load texture compatible with the rules
804
of KHR_texture_basisu glTF extension */
805
};
806
/**
807
* @memberof ktxTexture
808
* @~English
809
* @brief Type for TextureCreateFlags parameters.
810
*
811
* @sa ktxTexture_CreateFrom*()
812
*/
813
typedef ktx_uint32_t ktxTextureCreateFlags;
814
815
/*===========================================================*
816
* ktxStream
817
*===========================================================*/
818
819
/*
820
* This is unsigned to allow ktxmemstreams to use the
821
* full amount of memory available. Platforms will
822
* limit the size of ktxfilestreams to, e.g, MAX_LONG
823
* on 32-bit and ktxfilestreams raises errors if
824
* offset values exceed the limits. This choice may
825
* need to be revisited if we ever start needing -ve
826
* offsets.
827
*
828
* Should the 2GB file size handling limit on 32-bit
829
* platforms become a problem, ktxfilestream will have
830
* to be changed to explicitly handle large files by
831
* using the 64-bit stream functions.
832
*/
833
#if defined(_MSC_VER) && defined(_WIN64)
834
typedef unsigned __int64 ktx_off_t;
835
#else
836
typedef off_t ktx_off_t;
837
#endif
838
typedef struct ktxMem ktxMem;
839
typedef struct ktxStream ktxStream;
840
841
enum streamType { eStreamTypeFile = 1, eStreamTypeMemory = 2, eStreamTypeCustom = 3 };
842
843
/**
844
* @~English
845
* @brief type for a pointer to a stream reading function
846
*/
847
typedef KTX_error_code (*ktxStream_read)(ktxStream* str, void* dst,
848
const ktx_size_t count);
849
/**
850
* @~English
851
* @brief type for a pointer to a stream skipping function
852
*/
853
typedef KTX_error_code (*ktxStream_skip)(ktxStream* str,
854
const ktx_size_t count);
855
856
/**
857
* @~English
858
* @brief type for a pointer to a stream writing function
859
*/
860
typedef KTX_error_code (*ktxStream_write)(ktxStream* str, const void *src,
861
const ktx_size_t size,
862
const ktx_size_t count);
863
864
/**
865
* @~English
866
* @brief type for a pointer to a stream position query function
867
*/
868
typedef KTX_error_code (*ktxStream_getpos)(ktxStream* str, ktx_off_t* const offset);
869
870
/**
871
* @~English
872
* @brief type for a pointer to a stream position query function
873
*/
874
typedef KTX_error_code (*ktxStream_setpos)(ktxStream* str, const ktx_off_t offset);
875
876
/**
877
* @~English
878
* @brief type for a pointer to a stream size query function
879
*/
880
typedef KTX_error_code (*ktxStream_getsize)(ktxStream* str, ktx_size_t* const size);
881
882
/**
883
* @~English
884
* @brief Destruct a stream
885
*/
886
typedef void (*ktxStream_destruct)(ktxStream* str);
887
888
/**
889
* @~English
890
*
891
* @brief Interface of ktxStream.
892
*
893
* @author Maksim Kolesin
894
* @author Georg Kolling, Imagination Technology
895
* @author Mark Callow, HI Corporation
896
*/
897
struct ktxStream
898
{
899
ktxStream_read read; /*!< pointer to function for reading bytes. */
900
ktxStream_skip skip; /*!< pointer to function for skipping bytes. */
901
ktxStream_write write; /*!< pointer to function for writing bytes. */
902
ktxStream_getpos getpos; /*!< pointer to function for getting current position in stream. */
903
ktxStream_setpos setpos; /*!< pointer to function for setting current position in stream. */
904
ktxStream_getsize getsize; /*!< pointer to function for querying size. */
905
ktxStream_destruct destruct; /*!< destruct the stream. */
906
907
enum streamType type;
908
union {
909
FILE* file; /**< a stdio FILE pointer for a ktxFileStream. */
910
ktxMem* mem; /**< a pointer to a ktxMem struct for a ktxMemStream. */
911
struct
912
{
913
void* address; /**< pointer to the data. */
914
void* allocatorAddress; /**< pointer to a memory allocator. */
915
ktx_size_t size; /**< size of the data. */
916
} custom_ptr; /**< pointer to a struct for custom streams. */
917
} data; /**< pointer to the stream data. */
918
ktx_off_t readpos; /**< used by FileStream for stdin. */
919
ktx_bool_t closeOnDestruct; /**< Close FILE* or dispose of memory on destruct. */
920
};
921
922
/*
923
* See the implementation files for the full documentation of the following
924
* functions.
925
*/
926
927
/**
928
* @~English
929
* @brief typedef of function pointer returned by GLGetProcAddress functions.
930
*/
931
typedef void (KTX_APIENTRY* PFNVOIDFUNCTION)(void);
932
/**
933
* @~English
934
* @brief typedef of pointer to function for retrieving OpenGL function pointers.
935
*/
936
typedef PFNVOIDFUNCTION (KTX_APIENTRY* PFNGLGETPROCADDRESS) (const char *proc);
937
/*
938
* Load pointers for the OpenGL functions needed by ktxTexture_GLUpload.
939
*/
940
KTX_API KTX_error_code KTX_APIENTRY
941
ktxLoadOpenGL(PFNGLGETPROCADDRESS pfnGLGetProcAddress);
942
943
/*
944
* These four create a ktxTexture1 or ktxTexture2 according to the data
945
* header, and return a pointer to the base ktxTexture class.
946
*/
947
KTX_API KTX_error_code KTX_APIENTRY
948
ktxTexture_CreateFromStdioStream(FILE* stdioStream,
949
ktxTextureCreateFlags createFlags,
950
ktxTexture** newTex);
951
952
KTX_API KTX_error_code KTX_APIENTRY
953
ktxTexture_CreateFromNamedFile(const char* const filename,
954
ktxTextureCreateFlags createFlags,
955
ktxTexture** newTex);
956
957
KTX_API KTX_error_code KTX_APIENTRY
958
ktxTexture_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size,
959
ktxTextureCreateFlags createFlags,
960
ktxTexture** newTex);
961
962
KTX_API KTX_error_code KTX_APIENTRY
963
ktxTexture_CreateFromStream(ktxStream* stream,
964
ktxTextureCreateFlags createFlags,
965
ktxTexture** newTex);
966
967
/*
968
* Returns a pointer to the image data of a ktxTexture object.
969
*/
970
KTX_API ktx_uint8_t* KTX_APIENTRY
971
ktxTexture_GetData(ktxTexture* This);
972
973
/*
974
* Returns the pitch of a row of an image at the specified level.
975
* Similar to the rowPitch in a VkSubResourceLayout.
976
*/
977
KTX_API ktx_uint32_t KTX_APIENTRY
978
ktxTexture_GetRowPitch(ktxTexture* This, ktx_uint32_t level);
979
980
/*
981
* Return the element size of the texture's images.
982
*/
983
KTX_API ktx_uint32_t KTX_APIENTRY
984
ktxTexture_GetElementSize(ktxTexture* This);
985
986
/*
987
* Returns the size of all the image data of a ktxTexture object in bytes.
988
*/
989
KTX_API ktx_size_t KTX_APIENTRY
990
ktxTexture_GetDataSize(ktxTexture* This);
991
992
/* Uploads a texture to OpenGL {,ES}. */
993
KTX_API KTX_error_code KTX_APIENTRY
994
ktxTexture_GLUpload(ktxTexture* This, GLuint* pTexture, GLenum* pTarget,
995
GLenum* pGlerror);
996
997
/*
998
* Iterate over the levels or faces in a ktxTexture object.
999
*/
1000
KTX_API KTX_error_code KTX_APIENTRY
1001
ktxTexture_IterateLevelFaces(ktxTexture* This, PFNKTXITERCB iterCb,
1002
void* userdata);
1003
/*
1004
* Create a new ktxTexture1.
1005
*/
1006
KTX_API KTX_error_code KTX_APIENTRY
1007
ktxTexture1_Create(const ktxTextureCreateInfo* const createInfo,
1008
ktxTextureCreateStorageEnum storageAllocation,
1009
ktxTexture1** newTex);
1010
1011
/*
1012
* These four create a ktxTexture1 provided the data is in KTX format.
1013
*/
1014
KTX_API KTX_error_code KTX_APIENTRY
1015
ktxTexture1_CreateFromStdioStream(FILE* stdioStream,
1016
ktxTextureCreateFlags createFlags,
1017
ktxTexture1** newTex);
1018
1019
KTX_API KTX_error_code KTX_APIENTRY
1020
ktxTexture1_CreateFromNamedFile(const char* const filename,
1021
ktxTextureCreateFlags createFlags,
1022
ktxTexture1** newTex);
1023
1024
KTX_API KTX_error_code KTX_APIENTRY
1025
ktxTexture1_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size,
1026
ktxTextureCreateFlags createFlags,
1027
ktxTexture1** newTex);
1028
1029
KTX_API KTX_error_code KTX_APIENTRY
1030
ktxTexture1_CreateFromStream(ktxStream* stream,
1031
ktxTextureCreateFlags createFlags,
1032
ktxTexture1** newTex);
1033
KTX_API void KTX_APIENTRY
1034
ktxTexture1_Destroy(ktxTexture1* This);
1035
1036
KTX_API ktx_bool_t KTX_APIENTRY
1037
ktxTexture1_NeedsTranscoding(ktxTexture1* This);
1038
1039
KTX_API ktx_error_code_e KTX_APIENTRY
1040
ktxTexture1_LoadImageData(ktxTexture1* This, ktx_uint8_t* pBuffer, ktx_size_t bufSize);
1041
1042
/*
1043
* These four write a ktxTexture1 object to a KTX v1 file.
1044
*/
1045
KTX_API KTX_error_code KTX_APIENTRY
1046
ktxTexture1_WriteToStdioStream(ktxTexture1* This, FILE* dstsstr);
1047
1048
KTX_API KTX_error_code KTX_APIENTRY
1049
ktxTexture1_WriteToNamedFile(ktxTexture1* This, const char* const dstname);
1050
1051
KTX_API KTX_error_code KTX_APIENTRY
1052
ktxTexture1_WriteToMemory(ktxTexture1* This,
1053
ktx_uint8_t** bytes, ktx_size_t* size);
1054
1055
KTX_API KTX_error_code KTX_APIENTRY
1056
ktxTexture1_WriteToStream(ktxTexture1* This, ktxStream *dststr);
1057
1058
/*
1059
* These four write a ktxTexture1 object to a KTX v2 file.
1060
*/
1061
KTX_API KTX_error_code KTX_APIENTRY
1062
ktxTexture1_WriteKTX2ToStdioStream(ktxTexture1* This, FILE* dstsstr);
1063
1064
KTX_API KTX_error_code KTX_APIENTRY
1065
ktxTexture1_WriteKTX2ToNamedFile(ktxTexture1* This, const char* const dstname);
1066
1067
KTX_API KTX_error_code KTX_APIENTRY
1068
ktxTexture1_WriteKTX2ToMemory(ktxTexture1* This,
1069
ktx_uint8_t** bytes, ktx_size_t* size);
1070
1071
KTX_API KTX_error_code KTX_APIENTRY
1072
ktxTexture1_WriteKTX2ToStream(ktxTexture1* This, ktxStream *dststr);
1073
1074
/*
1075
* Create a new ktxTexture2.
1076
*/
1077
KTX_API KTX_error_code KTX_APIENTRY
1078
ktxTexture2_Create(const ktxTextureCreateInfo* const createInfo,
1079
ktxTextureCreateStorageEnum storageAllocation,
1080
ktxTexture2** newTex);
1081
1082
/*
1083
* Create a new ktxTexture2 as a copy of an existing texture.
1084
*/
1085
KTX_API KTX_error_code KTX_APIENTRY
1086
ktxTexture2_CreateCopy(ktxTexture2* orig, ktxTexture2** newTex);
1087
1088
/*
1089
* These four create a ktxTexture2 provided the data is in KTX2 format.
1090
*/
1091
KTX_API KTX_error_code KTX_APIENTRY
1092
ktxTexture2_CreateFromStdioStream(FILE* stdioStream,
1093
ktxTextureCreateFlags createFlags,
1094
ktxTexture2** newTex);
1095
1096
KTX_API KTX_error_code KTX_APIENTRY
1097
ktxTexture2_CreateFromNamedFile(const char* const filename,
1098
ktxTextureCreateFlags createFlags,
1099
ktxTexture2** newTex);
1100
1101
KTX_API KTX_error_code KTX_APIENTRY
1102
ktxTexture2_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size,
1103
ktxTextureCreateFlags createFlags,
1104
ktxTexture2** newTex);
1105
1106
KTX_API KTX_error_code KTX_APIENTRY
1107
ktxTexture2_CreateFromStream(ktxStream* stream,
1108
ktxTextureCreateFlags createFlags,
1109
ktxTexture2** newTex);
1110
1111
KTX_API void KTX_APIENTRY
1112
ktxTexture2_Destroy(ktxTexture2* This);
1113
1114
KTX_API KTX_error_code KTX_APIENTRY
1115
ktxTexture2_CompressBasis(ktxTexture2* This, ktx_uint32_t quality);
1116
1117
KTX_API KTX_error_code KTX_APIENTRY
1118
ktxTexture2_DeflateZstd(ktxTexture2* This, ktx_uint32_t level);
1119
1120
KTX_API KTX_error_code KTX_APIENTRY
1121
ktxTexture2_DeflateZLIB(ktxTexture2* This, ktx_uint32_t level);
1122
1123
KTX_API void KTX_APIENTRY
1124
ktxTexture2_GetComponentInfo(ktxTexture2* This, ktx_uint32_t* numComponents,
1125
ktx_uint32_t* componentByteLength);
1126
1127
KTX_API KTX_error_code KTX_APIENTRY
1128
ktxTexture2_GetImageOffset(ktxTexture2* This, ktx_uint32_t level,
1129
ktx_uint32_t layer, ktx_uint32_t faceSlice,
1130
ktx_size_t* pOffset);
1131
1132
KTX_API ktx_uint32_t KTX_APIENTRY
1133
ktxTexture2_GetNumComponents(ktxTexture2* This);
1134
1135
KTX_API khr_df_transfer_e KTX_APIENTRY
1136
ktxTexture2_GetTransferFunction_e(ktxTexture2* This);
1137
/* For backward compatibility. */
1138
KTX_API khr_df_transfer_e KTX_APIENTRY
1139
ktxTexture2_GetOETF_e(ktxTexture2* This);
1140
KTX_API ktx_uint32_t KTX_APIENTRY
1141
ktxTexture2_GetOETF(ktxTexture2* This);
1142
1143
KTX_API khr_df_model_e KTX_APIENTRY
1144
ktxTexture2_GetColorModel_e(ktxTexture2* This);
1145
1146
KTX_API ktx_bool_t KTX_APIENTRY
1147
ktxTexture2_GetPremultipliedAlpha(ktxTexture2* This);
1148
1149
KTX_API khr_df_primaries_e KTX_APIENTRY
1150
ktxTexture2_GetPrimaries_e(ktxTexture2* This);
1151
1152
KTX_API ktx_bool_t KTX_APIENTRY
1153
ktxTexture2_NeedsTranscoding(ktxTexture2* This);
1154
1155
KTX_API ktx_error_code_e KTX_APIENTRY
1156
ktxTexture2_SetTransferFunction(ktxTexture2* This, khr_df_transfer_e tf);
1157
/* For backward compatibility. */
1158
KTX_API ktx_error_code_e KTX_APIENTRY
1159
ktxTexture2_SetOETF(ktxTexture2* This, khr_df_transfer_e oetf);
1160
1161
KTX_API ktx_error_code_e KTX_APIENTRY
1162
ktxTexture2_SetPrimaries(ktxTexture2* This, khr_df_primaries_e primaries);
1163
1164
KTX_API ktx_error_code_e KTX_APIENTRY
1165
ktxTexture2_LoadImageData(ktxTexture2* This, ktx_uint8_t* pBuffer, ktx_size_t bufSize);
1166
/*
1167
* For rare testing scenarios. Use ktxTexture2_LoadImageData.
1168
*/
1169
KTX_API ktx_error_code_e KTX_APIENTRY
1170
ktxTexture2_LoadDeflatedImageData(ktxTexture2* This,
1171
ktx_uint8_t* pBuffer, ktx_size_t bufSize);
1172
1173
/*
1174
* These four write a ktxTexture2 object to a KTX v2 file.
1175
*/
1176
KTX_API KTX_error_code KTX_APIENTRY
1177
ktxTexture2_WriteToStdioStream(ktxTexture2* This, FILE* dstsstr);
1178
1179
KTX_API KTX_error_code KTX_APIENTRY
1180
ktxTexture2_WriteToNamedFile(ktxTexture2* This, const char* const dstname);
1181
1182
KTX_API KTX_error_code KTX_APIENTRY
1183
ktxTexture2_WriteToMemory(ktxTexture2* This,
1184
ktx_uint8_t** bytes, ktx_size_t* size);
1185
1186
KTX_API KTX_error_code KTX_APIENTRY
1187
ktxTexture2_WriteToStream(ktxTexture2* This, ktxStream *dststr);
1188
1189
/**
1190
* @~English
1191
* @brief Flags specifiying UASTC encoding options.
1192
*/
1193
typedef enum ktx_pack_uastc_flag_bits_e {
1194
KTX_PACK_UASTC_LEVEL_FASTEST = 0,
1195
/*!< Fastest compression. 43.45dB. */
1196
KTX_PACK_UASTC_LEVEL_FASTER = 1,
1197
/*!< Faster compression. 46.49dB. */
1198
KTX_PACK_UASTC_LEVEL_DEFAULT = 2,
1199
/*!< Default compression. 47.47dB. */
1200
KTX_PACK_UASTC_LEVEL_SLOWER = 3,
1201
/*!< Slower compression. 48.01dB. */
1202
KTX_PACK_UASTC_LEVEL_VERYSLOW = 4,
1203
/*!< Very slow compression. 48.24dB. */
1204
KTX_PACK_UASTC_MAX_LEVEL = KTX_PACK_UASTC_LEVEL_VERYSLOW,
1205
/*!< Maximum supported quality level. */
1206
KTX_PACK_UASTC_LEVEL_MASK = 0xF,
1207
/*!< Mask to extract the level from the other bits. */
1208
KTX_PACK_UASTC_FAVOR_UASTC_ERROR = 8,
1209
/*!< Optimize for lowest UASTC error. */
1210
KTX_PACK_UASTC_FAVOR_BC7_ERROR = 16,
1211
/*!< Optimize for lowest BC7 error. */
1212
KTX_PACK_UASTC_ETC1_FASTER_HINTS = 64,
1213
/*!< Optimize for faster transcoding to ETC1. */
1214
KTX_PACK_UASTC_ETC1_FASTEST_HINTS = 128,
1215
/*!< Optimize for fastest transcoding to ETC1. */
1216
KTX_PACK_UASTC__ETC1_DISABLE_FLIP_AND_INDIVIDUAL = 256
1217
/*!< Not documented in BasisU code. */
1218
} ktx_pack_uastc_flag_bits_e;
1219
typedef ktx_uint32_t ktx_pack_uastc_flags;
1220
1221
/**
1222
* @~English
1223
* @brief Options specifiying ASTC encoding quality levels.
1224
*/
1225
typedef enum ktx_pack_astc_quality_levels_e {
1226
KTX_PACK_ASTC_QUALITY_LEVEL_FASTEST = 0,
1227
/*!< Fastest compression. */
1228
KTX_PACK_ASTC_QUALITY_LEVEL_FAST = 10,
1229
/*!< Fast compression. */
1230
KTX_PACK_ASTC_QUALITY_LEVEL_MEDIUM = 60,
1231
/*!< Medium compression. */
1232
KTX_PACK_ASTC_QUALITY_LEVEL_THOROUGH = 98,
1233
/*!< Slower compression. */
1234
KTX_PACK_ASTC_QUALITY_LEVEL_EXHAUSTIVE = 100,
1235
/*!< Very slow compression. */
1236
KTX_PACK_ASTC_QUALITY_LEVEL_MAX = KTX_PACK_ASTC_QUALITY_LEVEL_EXHAUSTIVE,
1237
/*!< Maximum supported quality level. */
1238
} ktx_pack_astc_quality_levels_e;
1239
1240
/**
1241
* @~English
1242
* @brief Options specifiying ASTC encoding block dimensions
1243
*/
1244
typedef enum ktx_pack_astc_block_dimension_e {
1245
// 2D formats
1246
KTX_PACK_ASTC_BLOCK_DIMENSION_4x4, //: 8.00 bpp
1247
KTX_PACK_ASTC_BLOCK_DIMENSION_5x4, //: 6.40 bpp
1248
KTX_PACK_ASTC_BLOCK_DIMENSION_5x5, //: 5.12 bpp
1249
KTX_PACK_ASTC_BLOCK_DIMENSION_6x5, //: 4.27 bpp
1250
KTX_PACK_ASTC_BLOCK_DIMENSION_6x6, //: 3.56 bpp
1251
KTX_PACK_ASTC_BLOCK_DIMENSION_8x5, //: 3.20 bpp
1252
KTX_PACK_ASTC_BLOCK_DIMENSION_8x6, //: 2.67 bpp
1253
KTX_PACK_ASTC_BLOCK_DIMENSION_10x5, //: 2.56 bpp
1254
KTX_PACK_ASTC_BLOCK_DIMENSION_10x6, //: 2.13 bpp
1255
KTX_PACK_ASTC_BLOCK_DIMENSION_8x8, //: 2.00 bpp
1256
KTX_PACK_ASTC_BLOCK_DIMENSION_10x8, //: 1.60 bpp
1257
KTX_PACK_ASTC_BLOCK_DIMENSION_10x10, //: 1.28 bpp
1258
KTX_PACK_ASTC_BLOCK_DIMENSION_12x10, //: 1.07 bpp
1259
KTX_PACK_ASTC_BLOCK_DIMENSION_12x12, //: 0.89 bpp
1260
// 3D formats
1261
KTX_PACK_ASTC_BLOCK_DIMENSION_3x3x3, //: 4.74 bpp
1262
KTX_PACK_ASTC_BLOCK_DIMENSION_4x3x3, //: 3.56 bpp
1263
KTX_PACK_ASTC_BLOCK_DIMENSION_4x4x3, //: 2.67 bpp
1264
KTX_PACK_ASTC_BLOCK_DIMENSION_4x4x4, //: 2.00 bpp
1265
KTX_PACK_ASTC_BLOCK_DIMENSION_5x4x4, //: 1.60 bpp
1266
KTX_PACK_ASTC_BLOCK_DIMENSION_5x5x4, //: 1.28 bpp
1267
KTX_PACK_ASTC_BLOCK_DIMENSION_5x5x5, //: 1.02 bpp
1268
KTX_PACK_ASTC_BLOCK_DIMENSION_6x5x5, //: 0.85 bpp
1269
KTX_PACK_ASTC_BLOCK_DIMENSION_6x6x5, //: 0.71 bpp
1270
KTX_PACK_ASTC_BLOCK_DIMENSION_6x6x6, //: 0.59 bpp
1271
KTX_PACK_ASTC_BLOCK_DIMENSION_MAX = KTX_PACK_ASTC_BLOCK_DIMENSION_6x6x6
1272
/*!< Maximum supported blocks. */
1273
} ktx_pack_astc_block_dimension_e;
1274
1275
/**
1276
* @~English
1277
* @brief Options specifying ASTC encoder profile mode
1278
* This and function is used later to derive the profile.
1279
*/
1280
typedef enum ktx_pack_astc_encoder_mode_e {
1281
KTX_PACK_ASTC_ENCODER_MODE_DEFAULT,
1282
KTX_PACK_ASTC_ENCODER_MODE_LDR,
1283
KTX_PACK_ASTC_ENCODER_MODE_HDR,
1284
KTX_PACK_ASTC_ENCODER_MODE_MAX = KTX_PACK_ASTC_ENCODER_MODE_HDR
1285
} ktx_pack_astc_encoder_mode_e;
1286
1287
extern KTX_API const ktx_uint32_t KTX_ETC1S_DEFAULT_COMPRESSION_LEVEL;
1288
1289
/**
1290
* @memberof ktxTexture
1291
* @~English
1292
* @brief Structure for passing extended parameters to
1293
* ktxTexture_CompressAstc.
1294
*
1295
* Passing a struct initialized to 0 (e.g. " = {0};") will use blockDimension
1296
* 4x4, mode LDR and qualityLevel FASTEST. Setting qualityLevel to
1297
* KTX_PACK_ASTC_QUALITY_LEVEL_MEDIUM is recommended.
1298
*/
1299
typedef struct ktxAstcParams {
1300
ktx_uint32_t structSize;
1301
/*!< Size of this struct. Used so library can tell which version
1302
of struct is being passed.
1303
*/
1304
1305
ktx_bool_t verbose;
1306
/*!< If true, prints Astc encoder operation details to
1307
@c stdout. Not recommended for GUI apps.
1308
*/
1309
1310
ktx_uint32_t threadCount;
1311
/*!< Number of threads used for compression. Default is 1.
1312
*/
1313
1314
/* astcenc params */
1315
ktx_uint32_t blockDimension;
1316
/*!< Combinations of block dimensions that astcenc supports
1317
i.e. 6x6, 8x8, 6x5 etc
1318
*/
1319
1320
ktx_uint32_t mode;
1321
/*!< Can be {ldr/hdr} from astcenc
1322
*/
1323
1324
ktx_uint32_t qualityLevel;
1325
/*!< astcenc supports -fastest, -fast, -medium, -thorough, -exhaustive
1326
*/
1327
1328
ktx_bool_t normalMap;
1329
/*!< Tunes codec parameters for better quality on normal maps
1330
In this mode normals are compressed to X,Y components
1331
Discarding Z component, reader will need to generate Z
1332
component in shaders.
1333
*/
1334
1335
ktx_bool_t perceptual;
1336
/*!< The codec should optimize for perceptual error, instead of direct
1337
RMS error. This aims to improves perceived image quality, but
1338
typically lowers the measured PSNR score. Perceptual methods are
1339
currently only available for normal maps and RGB color data.
1340
*/
1341
1342
char inputSwizzle[4];
1343
/*!< A swizzle to provide as input to astcenc. It must match the regular
1344
expression /^[rgba01]{4}$/.
1345
*/
1346
} ktxAstcParams;
1347
1348
KTX_API KTX_error_code KTX_APIENTRY
1349
ktxTexture2_CompressAstcEx(ktxTexture2* This, ktxAstcParams* params);
1350
1351
KTX_API KTX_error_code KTX_APIENTRY
1352
ktxTexture2_CompressAstc(ktxTexture2* This, ktx_uint32_t quality);
1353
1354
KTX_API KTX_error_code KTX_APIENTRY
1355
ktxTexture2_DecodeAstc(ktxTexture2* This);
1356
1357
/**
1358
* @memberof ktxTexture2
1359
* @~English
1360
* @brief Structure for passing extended parameters to
1361
* ktxTexture2_CompressBasisEx().
1362
*
1363
* If you only want default values, use ktxTexture2_CompressBasis(). Here, at
1364
* a minimum you must initialize the structure as follows:
1365
* @code
1366
* ktxBasisParams params = {0};
1367
* params.structSize = sizeof(params);
1368
* params.compressionLevel = KTX_ETC1S_DEFAULT_COMPRESSION_LEVEL;
1369
* @endcode
1370
*
1371
* @e compressionLevel has to be explicitly set because 0 is a valid
1372
* @e compressionLevel but is not the default used by the BasisU encoder
1373
* when no value is set. Only the other settings that are to be non-default
1374
* must be non-zero.
1375
*/
1376
typedef struct ktxBasisParams {
1377
ktx_uint32_t structSize;
1378
/*!< Size of this struct. Used so library can tell which version
1379
of struct is being passed.
1380
*/
1381
ktx_bool_t uastc;
1382
/*!< True to use UASTC base, false to use ETC1S base. */
1383
ktx_bool_t verbose;
1384
/*!< If true, prints Basis Universal encoder operation details to
1385
@c stdout. Not recommended for GUI apps.
1386
*/
1387
ktx_bool_t noSSE;
1388
/*!< True to forbid use of the SSE instruction set. Ignored if CPU
1389
does not support SSE. */
1390
ktx_uint32_t threadCount;
1391
/*!< Number of threads used for compression. Default is 1. */
1392
1393
/* ETC1S params */
1394
1395
ktx_uint32_t compressionLevel;
1396
/*!< Encoding speed vs. quality tradeoff. Range is [0,6]. Higher values
1397
are much slower, but give slightly higher quality. Higher levels
1398
are intended for video. There is no default. Callers must
1399
explicitly set this value. Callers can use
1400
KTX\_ETC1S\_DEFAULT\_COMPRESSION\_LEVEL as a default value.
1401
Currently this is 2.
1402
*/
1403
ktx_uint32_t qualityLevel;
1404
/*!< Compression quality. Range is [1,255]. Lower gives better
1405
compression/lower quality/faster. Higher gives less compression
1406
/higher quality/slower. This automatically determines values for
1407
@c maxEndpoints, @c maxSelectors,
1408
@c endpointRDOThreshold and @c selectorRDOThreshold
1409
for the target quality level. Setting these parameters overrides
1410
the values determined by @c qualityLevel which defaults to
1411
128 if neither it nor both of @c maxEndpoints and
1412
@c maxSelectors have been set.
1413
@note @e Both of @c maxEndpoints and @c maxSelectors
1414
must be set for them to have any effect.
1415
@note qualityLevel will only determine values for
1416
@c endpointRDOThreshold and @c selectorRDOThreshold
1417
when its value exceeds 128, otherwise their defaults will be used.
1418
*/
1419
ktx_uint32_t maxEndpoints;
1420
/*!< Manually set the max number of color endpoint clusters.
1421
Range is [1,16128]. Default is 0, unset. If this is set, maxSelectors
1422
must also be set, otherwise the value will be ignored.
1423
*/
1424
float endpointRDOThreshold;
1425
/*!< Set endpoint RDO quality threshold. The default is 1.25. Lower is
1426
higher quality but less quality per output bit (try [1.0,3.0].
1427
This will override the value chosen by @c qualityLevel.
1428
*/
1429
ktx_uint32_t maxSelectors;
1430
/*!< Manually set the max number of color selector clusters. Range
1431
is [1,16128]. Default is 0, unset. If this is set, maxEndpoints
1432
must also be set, otherwise the value will be ignored.
1433
*/
1434
float selectorRDOThreshold;
1435
/*!< Set selector RDO quality threshold. The default is 1.5. Lower is
1436
higher quality but less quality per output bit (try [1.0,3.0]).
1437
This will override the value chosen by @c qualityLevel.
1438
*/
1439
char inputSwizzle[4];
1440
/*!< A swizzle to apply before encoding. It must match the regular
1441
expression /^[rgba01]{4}$/. If both this and preSwizzle
1442
are specified ktxTexture_CompressBasisEx will raise
1443
KTX_INVALID_OPERATION. Usable with both ETC1S and UASTC.
1444
*/
1445
ktx_bool_t normalMap;
1446
/*!< Tunes codec parameters for better quality on normal maps (no
1447
selector RDO, no endpoint RDO) and sets the texture's DFD appropriately.
1448
Only valid for linear textures.
1449
*/
1450
ktx_bool_t separateRGToRGB_A;
1451
/*!< @deprecated This was and is a no-op. 2-component inputs have
1452
always been automatically separated using an "rrrg" inputSwizzle.
1453
@sa inputSwizzle and normalMode.
1454
*/
1455
ktx_bool_t preSwizzle;
1456
/*!< If the texture has @c KTXswizzle metadata, apply it before
1457
compressing. Swizzling, like @c rabb may yield drastically
1458
different error metrics if done after supercompression. Usable
1459
for both ETC1S and UASTC.
1460
*/
1461
ktx_bool_t noEndpointRDO;
1462
/*!< Disable endpoint rate distortion optimizations. Slightly faster,
1463
less noisy output, but lower quality per output bit. Default is
1464
KTX_FALSE.
1465
*/
1466
ktx_bool_t noSelectorRDO;
1467
/*!< Disable selector rate distortion optimizations. Slightly faster,
1468
less noisy output, but lower quality per output bit. Default is
1469
KTX_FALSE.
1470
*/
1471
1472
/* UASTC params */
1473
1474
ktx_pack_uastc_flags uastcFlags;
1475
/*!< A set of ::ktx_pack_uastc_flag_bits_e controlling UASTC
1476
encoding. The most important value is the level given in the
1477
least-significant 4 bits which selects a speed vs quality tradeoff
1478
as shown in the following table:
1479
1480
Level/Speed | Quality
1481
:-----: | :-------:
1482
KTX_PACK_UASTC_LEVEL_FASTEST | 43.45dB
1483
KTX_PACK_UASTC_LEVEL_FASTER | 46.49dB
1484
KTX_PACK_UASTC_LEVEL_DEFAULT | 47.47dB
1485
KTX_PACK_UASTC_LEVEL_SLOWER | 48.01dB
1486
KTX_PACK_UASTC_LEVEL_VERYSLOW | 48.24dB
1487
*/
1488
ktx_bool_t uastcRDO;
1489
/*!< Enable Rate Distortion Optimization (RDO) post-processing.
1490
*/
1491
float uastcRDOQualityScalar;
1492
/*!< UASTC RDO quality scalar (lambda). Lower values yield higher
1493
quality/larger LZ compressed files, higher values yield lower
1494
quality/smaller LZ compressed files. A good range to try is [.2,4].
1495
Full range is [.001,50.0]. Default is 1.0.
1496
*/
1497
ktx_uint32_t uastcRDODictSize;
1498
/*!< UASTC RDO dictionary size in bytes. Default is 4096. Lower
1499
values=faster, but give less compression. Range is [64,65536].
1500
*/
1501
float uastcRDOMaxSmoothBlockErrorScale;
1502
/*!< UASTC RDO max smooth block error scale. Range is [1,300].
1503
Default is 10.0, 1.0 is disabled. Larger values suppress more
1504
artifacts (and allocate more bits) on smooth blocks.
1505
*/
1506
float uastcRDOMaxSmoothBlockStdDev;
1507
/*!< UASTC RDO max smooth block standard deviation. Range is
1508
[.01,65536.0]. Default is 18.0. Larger values expand the range of
1509
blocks considered smooth.
1510
*/
1511
ktx_bool_t uastcRDODontFavorSimplerModes;
1512
/*!< Do not favor simpler UASTC modes in RDO mode.
1513
*/
1514
ktx_bool_t uastcRDONoMultithreading;
1515
/*!< Disable RDO multithreading (slightly higher compression,
1516
deterministic).
1517
*/
1518
1519
} ktxBasisParams;
1520
1521
KTX_API KTX_error_code KTX_APIENTRY
1522
ktxTexture2_CompressBasisEx(ktxTexture2* This, ktxBasisParams* params);
1523
1524
/**
1525
* @~English
1526
* @brief Enumerators for specifying the transcode target format.
1527
*
1528
* For BasisU/ETC1S format, @e Opaque and @e alpha here refer to 2 separate
1529
* RGB images, a.k.a slices within the BasisU compressed data. For UASTC
1530
* format they refer to the RGB and the alpha components of the UASTC data. If
1531
* the original image had only 2 components, R will be in the opaque portion
1532
* and G in the alpha portion. The R value will be replicated in the RGB
1533
* components. In the case of BasisU the G value will be replicated in all 3
1534
* components of the alpha slice. If the original image had only 1 component
1535
* it's value is replicated in all 3 components of the opaque portion and
1536
* there is no alpha.
1537
*
1538
* @note You should not transcode sRGB encoded data to @c KTX_TTF_BC4_R,
1539
* @c KTX_TTF_BC5_RG, @c KTX_TTF_ETC2_EAC_R{,G}11, @c KTX_TTF_RGB565,
1540
* @c KTX_TTF_BGR565 or @c KTX_TTF_RGBA4444 formats as neither OpenGL nor
1541
* Vulkan support sRGB variants of these. Doing sRGB decoding in the shader
1542
* will not produce correct results if any texture filtering is being used.
1543
*/
1544
typedef enum ktx_transcode_fmt_e {
1545
// Compressed formats
1546
1547
// ETC1-2
1548
KTX_TTF_ETC1_RGB = 0,
1549
/*!< Opaque only. Returns RGB or alpha data, if
1550
KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is
1551
specified. */
1552
KTX_TTF_ETC2_RGBA = 1,
1553
/*!< Opaque+alpha. EAC_A8 block followed by an ETC1 block. The
1554
alpha channel will be opaque for textures without an alpha
1555
channel. */
1556
1557
// BC1-5, BC7 (desktop, some mobile devices)
1558
KTX_TTF_BC1_RGB = 2,
1559
/*!< Opaque only, no punchthrough alpha support yet. Returns RGB
1560
or alpha data, if KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS
1561
flag is specified. */
1562
KTX_TTF_BC3_RGBA = 3,
1563
/*!< Opaque+alpha. BC4 block with alpha followed by a BC1 block. The
1564
alpha channel will be opaque for textures without an alpha
1565
channel. */
1566
KTX_TTF_BC4_R = 4,
1567
/*!< One BC4 block. R = opaque.g or alpha.g, if
1568
KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is
1569
specified. */
1570
KTX_TTF_BC5_RG = 5,
1571
/*!< Two BC4 blocks, R=opaque.g and G=alpha.g The texture should
1572
have an alpha channel (if not G will be all 255's. For tangent
1573
space normal maps. */
1574
KTX_TTF_BC7_RGBA = 6,
1575
/*!< RGB or RGBA mode 5 for ETC1S, modes 1, 2, 3, 4, 5, 6, 7 for
1576
UASTC. */
1577
1578
// PVRTC1 4bpp (mobile, PowerVR devices)
1579
KTX_TTF_PVRTC1_4_RGB = 8,
1580
/*!< Opaque only. Returns RGB or alpha data, if
1581
KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is
1582
specified. */
1583
KTX_TTF_PVRTC1_4_RGBA = 9,
1584
/*!< Opaque+alpha. Most useful for simple opacity maps. If the
1585
texture doesn't have an alpha channel KTX_TTF_PVRTC1_4_RGB
1586
will be used instead. Lowest quality of any supported
1587
texture format. */
1588
1589
// ASTC (mobile, Intel devices, hopefully all desktop GPU's one day)
1590
KTX_TTF_ASTC_4x4_RGBA = 10,
1591
/*!< Opaque+alpha, ASTC 4x4. The alpha channel will be opaque for
1592
textures without an alpha channel. The transcoder uses
1593
RGB/RGBA/L/LA modes, void extent, and up to two ([0,47] and
1594
[0,255]) endpoint precisions. */
1595
1596
// ATC and FXT1 formats are not supported by KTX2 as there
1597
// are no equivalent VkFormats.
1598
1599
KTX_TTF_PVRTC2_4_RGB = 18,
1600
/*!< Opaque-only. Almost BC1 quality, much faster to transcode
1601
and supports arbitrary texture dimensions (unlike
1602
PVRTC1 RGB). */
1603
KTX_TTF_PVRTC2_4_RGBA = 19,
1604
/*!< Opaque+alpha. Slower to transcode than cTFPVRTC2_4_RGB.
1605
Premultiplied alpha is highly recommended, otherwise the
1606
color channel can leak into the alpha channel on transparent
1607
blocks. */
1608
1609
KTX_TTF_ETC2_EAC_R11 = 20,
1610
/*!< R only (ETC2 EAC R11 unsigned). R = opaque.g or alpha.g, if
1611
KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is
1612
specified. */
1613
KTX_TTF_ETC2_EAC_RG11 = 21,
1614
/*!< RG only (ETC2 EAC RG11 unsigned), R=opaque.g, G=alpha.g. The
1615
texture should have an alpha channel (if not G will be all
1616
255's. For tangent space normal maps. */
1617
1618
// Uncompressed (raw pixel) formats
1619
KTX_TTF_RGBA32 = 13,
1620
/*!< 32bpp RGBA image stored in raster (not block) order in
1621
memory, R is first byte, A is last byte. */
1622
KTX_TTF_RGB565 = 14,
1623
/*!< 16bpp RGB image stored in raster (not block) order in memory,
1624
R at bit position 11. */
1625
KTX_TTF_BGR565 = 15,
1626
/*!< 16bpp RGB image stored in raster (not block) order in memory,
1627
R at bit position 0. */
1628
KTX_TTF_RGBA4444 = 16,
1629
/*!< 16bpp RGBA image stored in raster (not block) order in memory,
1630
R at bit position 12, A at bit position 0. */
1631
1632
// Values for automatic selection of RGB or RGBA depending if alpha
1633
// present.
1634
KTX_TTF_ETC = 22,
1635
/*!< Automatically selects @c KTX_TTF_ETC1_RGB or
1636
@c KTX_TTF_ETC2_RGBA according to presence of alpha. */
1637
KTX_TTF_BC1_OR_3 = 23,
1638
/*!< Automatically selects @c KTX_TTF_BC1_RGB or
1639
@c KTX_TTF_BC3_RGBA according to presence of alpha. */
1640
1641
KTX_TTF_NOSELECTION = 0x7fffffff,
1642
1643
// Old enums for compatibility with code compiled against previous
1644
// versions of libktx.
1645
KTX_TF_ETC1 = KTX_TTF_ETC1_RGB,
1646
//!< @deprecated Use #KTX_TTF_ETC1_RGB.
1647
KTX_TF_ETC2 = KTX_TTF_ETC,
1648
//!< @deprecated Use #KTX_TTF_ETC.
1649
KTX_TF_BC1 = KTX_TTF_BC1_RGB,
1650
//!< @deprecated Use #KTX_TTF_BC1_RGB.
1651
KTX_TF_BC3 = KTX_TTF_BC3_RGBA,
1652
//!< @deprecated Use #KTX_TTF_BC3_RGBA.
1653
KTX_TF_BC4 = KTX_TTF_BC4_R,
1654
//!< @deprecated Use #KTX_TTF_BC4_R.
1655
KTX_TF_BC5 = KTX_TTF_BC5_RG,
1656
//!< @deprecated Use #KTX_TTF_BC5_RG.
1657
KTX_TTF_BC7_M6_RGB = KTX_TTF_BC7_RGBA,
1658
//!< @deprecated Use #KTX_TTF_BC7_RGBA.
1659
KTX_TTF_BC7_M5_RGBA = KTX_TTF_BC7_RGBA,
1660
//!< @deprecated Use #KTX_TTF_BC7_RGBA.
1661
KTX_TF_BC7_M6_OPAQUE_ONLY = KTX_TTF_BC7_RGBA,
1662
//!< @deprecated Use #KTX_TTF_BC7_RGBA
1663
KTX_TF_PVRTC1_4_OPAQUE_ONLY = KTX_TTF_PVRTC1_4_RGB
1664
//!< @deprecated Use #KTX_TTF_PVRTC1_4_RGB.
1665
} ktx_transcode_fmt_e;
1666
1667
/**
1668
* @~English
1669
* @brief Flags guiding transcoding of Basis Universal compressed textures.
1670
*/
1671
typedef enum ktx_transcode_flag_bits_e {
1672
KTX_TF_PVRTC_DECODE_TO_NEXT_POW2 = 2,
1673
/*!< PVRTC1: decode non-pow2 ETC1S texture level to the next larger
1674
power of 2 (not implemented yet, but we're going to support it).
1675
Ignored if the slice's dimensions are already a power of 2.
1676
*/
1677
KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS = 4,
1678
/*!< When decoding to an opaque texture format, if the Basis data has
1679
alpha, decode the alpha slice instead of the color slice to the
1680
output texture format. Has no effect if there is no alpha data.
1681
*/
1682
KTX_TF_HIGH_QUALITY = 32,
1683
/*!< Request higher quality transcode of UASTC to BC1, BC3, ETC2_EAC_R11 and
1684
ETC2_EAC_RG11. The flag is unused by other UASTC transcoders.
1685
*/
1686
} ktx_transcode_flag_bits_e;
1687
typedef ktx_uint32_t ktx_transcode_flags;
1688
1689
KTX_API KTX_error_code KTX_APIENTRY
1690
ktxTexture2_TranscodeBasis(ktxTexture2* This, ktx_transcode_fmt_e fmt,
1691
ktx_transcode_flags transcodeFlags);
1692
1693
/*
1694
* Returns a string corresponding to a KTX error code.
1695
*/
1696
KTX_API const char* KTX_APIENTRY
1697
ktxErrorString(KTX_error_code error);
1698
1699
/*
1700
* Returns a string corresponding to a supercompression scheme.
1701
*/
1702
KTX_API const char* KTX_APIENTRY
1703
ktxSupercompressionSchemeString(ktxSupercmpScheme scheme);
1704
1705
/*
1706
* Returns a string corresponding to a transcode target format.
1707
*/
1708
KTX_API const char* KTX_APIENTRY
1709
ktxTranscodeFormatString(ktx_transcode_fmt_e format);
1710
1711
KTX_API KTX_error_code KTX_APIENTRY ktxHashList_Create(ktxHashList** ppHl);
1712
KTX_API KTX_error_code KTX_APIENTRY
1713
ktxHashList_CreateCopy(ktxHashList** ppHl, ktxHashList orig);
1714
KTX_API void KTX_APIENTRY ktxHashList_Construct(ktxHashList* pHl);
1715
KTX_API void KTX_APIENTRY
1716
ktxHashList_ConstructCopy(ktxHashList* pHl, ktxHashList orig);
1717
KTX_API void KTX_APIENTRY ktxHashList_Destroy(ktxHashList* head);
1718
KTX_API void KTX_APIENTRY ktxHashList_Destruct(ktxHashList* head);
1719
1720
/*
1721
* Adds a key-value pair to a hash list.
1722
*/
1723
KTX_API KTX_error_code KTX_APIENTRY
1724
ktxHashList_AddKVPair(ktxHashList* pHead, const char* key,
1725
unsigned int valueLen, const void* value);
1726
1727
/*
1728
* Deletes a ktxHashListEntry from a ktxHashList.
1729
*/
1730
KTX_API KTX_error_code KTX_APIENTRY
1731
ktxHashList_DeleteEntry(ktxHashList* pHead, ktxHashListEntry* pEntry);
1732
1733
/*
1734
* Finds the entry for a key in a ktxHashList and deletes it.
1735
*/
1736
KTX_API KTX_error_code KTX_APIENTRY
1737
ktxHashList_DeleteKVPair(ktxHashList* pHead, const char* key);
1738
1739
/*
1740
* Looks up a key and returns the ktxHashListEntry.
1741
*/
1742
KTX_API KTX_error_code KTX_APIENTRY
1743
ktxHashList_FindEntry(ktxHashList* pHead, const char* key,
1744
ktxHashListEntry** ppEntry);
1745
1746
/*
1747
* Looks up a key and returns the value.
1748
*/
1749
KTX_API KTX_error_code KTX_APIENTRY
1750
ktxHashList_FindValue(ktxHashList* pHead, const char* key,
1751
unsigned int* pValueLen, void** pValue);
1752
1753
/*
1754
* Return the next entry in a ktxHashList.
1755
*/
1756
KTX_API ktxHashListEntry* KTX_APIENTRY
1757
ktxHashList_Next(ktxHashListEntry* entry);
1758
1759
/*
1760
* Sorts a ktxHashList into order of the key codepoints.
1761
*/
1762
KTX_API KTX_error_code KTX_APIENTRY
1763
ktxHashList_Sort(ktxHashList* pHead);
1764
1765
/*
1766
* Serializes a ktxHashList to a block of memory suitable for
1767
* writing to a KTX file.
1768
*/
1769
KTX_API KTX_error_code KTX_APIENTRY
1770
ktxHashList_Serialize(ktxHashList* pHead,
1771
unsigned int* kvdLen, unsigned char** kvd);
1772
1773
/*
1774
* Creates a hash table from the serialized data read from a
1775
* a KTX file.
1776
*/
1777
KTX_API KTX_error_code KTX_APIENTRY
1778
ktxHashList_Deserialize(ktxHashList* pHead, unsigned int kvdLen, void* kvd);
1779
1780
/*
1781
* Get the key from a ktxHashListEntry
1782
*/
1783
KTX_API KTX_error_code KTX_APIENTRY
1784
ktxHashListEntry_GetKey(ktxHashListEntry* This,
1785
unsigned int* pKeyLen, char** ppKey);
1786
1787
/*
1788
* Get the value from a ktxHashListEntry
1789
*/
1790
KTX_API KTX_error_code KTX_APIENTRY
1791
ktxHashListEntry_GetValue(ktxHashListEntry* This,
1792
unsigned int* pValueLen, void** ppValue);
1793
1794
/*===========================================================*
1795
* Utilities for printing info about a KTX file. *
1796
*===========================================================*/
1797
1798
KTX_API KTX_error_code KTX_APIENTRY ktxPrintInfoForStdioStream(FILE* stdioStream);
1799
KTX_API KTX_error_code KTX_APIENTRY ktxPrintInfoForNamedFile(const char* const filename);
1800
KTX_API KTX_error_code KTX_APIENTRY ktxPrintInfoForMemory(const ktx_uint8_t* bytes, ktx_size_t size);
1801
1802
/*===========================================================*
1803
* Utilities for printing info about a KTX2 file. *
1804
*===========================================================*/
1805
1806
KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForMemory(const ktx_uint8_t* bytes, ktx_size_t size);
1807
KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForNamedFile(const char* const filename);
1808
KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForStdioStream(FILE* stdioStream);
1809
KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForStream(ktxStream* stream);
1810
KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForMemory(const ktx_uint8_t* bytes, ktx_size_t size, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified);
1811
KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForNamedFile(const char* const filename, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified);
1812
KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForStdioStream(FILE* stdioStream, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified);
1813
KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForStream(ktxStream* stream, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified);
1814
1815
#ifdef __cplusplus
1816
}
1817
#endif
1818
1819
/**
1820
@~English
1821
@page libktx_history Revision History
1822
1823
No longer updated. Kept to preserve ancient history. For more recent history see the repo log at
1824
https://github.com/KhronosGroup/KTX-Software. See also the Release Notes in the repo.
1825
1826
@section v8 Version 4.0
1827
Added:
1828
@li Support for KTX Version 2.
1829
@li Support for encoding and transcoding Basis Universal images in KTX Version 2 files.
1830
@li Function to print info about a KTX file.
1831
1832
@section v7 Version 3.0.1
1833
Fixed:
1834
@li GitHub issue #159: compile failure with recent Vulkan SDKs.
1835
@li Incorrect mapping of GL DXT3 and DXT5 formats to Vulkan equivalents.
1836
@li Incorrect BC4 blocksize.
1837
@li Missing mapping of PVRTC formats from GL to Vulkan.
1838
@li Incorrect block width and height calculations for sizes that are not
1839
a multiple of the block size.
1840
@li Incorrect KTXorientation key in test images.
1841
1842
@section v6 Version 3.0
1843
Added:
1844
@li new ktxTexture object based API for reading KTX files without an OpenGL context.
1845
@li Vulkan loader. @#include <ktxvulkan.h> to use it.
1846
1847
Changed:
1848
@li ktx.h to not depend on KHR/khrplatform.h and GL{,ES*}/gl{corearb,}.h.
1849
Applications using OpenGL must now include these files themselves.
1850
@li ktxLoadTexture[FMN], removing the hack of loading 1D textures as 2D textures
1851
when the OpenGL context does not support 1D textures.
1852
KTX_UNSUPPORTED_TEXTURE_TYPE is now returned.
1853
1854
@section v5 Version 2.0.2
1855
Added:
1856
@li Support for cubemap arrays.
1857
1858
Changed:
1859
@li New build system
1860
1861
Fixed:
1862
@li GitHub issue #40: failure to byte-swap key-value lengths.
1863
@li GitHub issue #33: returning incorrect target when loading cubemaps.
1864
@li GitHub PR #42: loading of texture arrays.
1865
@li GitHub PR #41: compilation error when KTX_OPENGL_ES2=1 defined.
1866
@li GitHub issue #39: stack-buffer-overflow in toktx
1867
@li Don't use GL_EXTENSIONS on recent OpenGL versions.
1868
1869
@section v4 Version 2.0.1
1870
Added:
1871
@li CMake build files. Thanks to Pavel Rotjberg for the initial version.
1872
1873
Changed:
1874
@li ktxWriteKTXF to check the validity of the type & format combinations
1875
passed to it.
1876
1877
Fixed:
1878
@li Public Bugzilla <a href="http://www.khronos.org/bugzilla/show_bug.cgi?id=999">999</a>: 16-bit luminance texture cannot be written.
1879
@li compile warnings from compilers stricter than MS Visual C++. Thanks to
1880
Pavel Rotjberg.
1881
1882
@section v3 Version 2.0
1883
Added:
1884
@li support for decoding ETC2 and EAC formats in the absence of a hardware
1885
decoder.
1886
@li support for converting textures with legacy LUMINANCE, LUMINANCE_ALPHA,
1887
etc. formats to the equivalent R, RG, etc. format with an
1888
appropriate swizzle, when loading in OpenGL Core Profile contexts.
1889
@li ktxErrorString function to return a string corresponding to an error code.
1890
@li tests for ktxLoadTexture[FN] that run under OpenGL ES 3.0 and OpenGL 3.3.
1891
The latter includes an EGL on WGL wrapper that makes porting apps between
1892
OpenGL ES and OpenGL easier on Windows.
1893
@li more texture formats to ktxLoadTexture[FN] and toktx tests.
1894
1895
Changed:
1896
@li ktxLoadTexture[FMN] to discover the capabilities of the GL context at
1897
run time and load textures, or not, according to those capabilities.
1898
1899
Fixed:
1900
@li failure of ktxWriteKTXF to pad image rows to 4 bytes as required by the KTX
1901
format.
1902
@li ktxWriteKTXF exiting with KTX_FILE_WRITE_ERROR when attempting to write
1903
more than 1 byte of face-LOD padding.
1904
1905
Although there is only a very minor API change, the addition of ktxErrorString,
1906
the functional changes are large enough to justify bumping the major revision
1907
number.
1908
1909
@section v2 Version 1.0.1
1910
Implemented ktxLoadTextureM.
1911
Fixed the following:
1912
@li Public Bugzilla <a href="http://www.khronos.org/bugzilla/show_bug.cgi?id=571">571</a>: crash when null passed for pIsMipmapped.
1913
@li Public Bugzilla <a href="http://www.khronos.org/bugzilla/show_bug.cgi?id=572">572</a>: memory leak when unpacking ETC textures.
1914
@li Public Bugzilla <a href="http://www.khronos.org/bugzilla/show_bug.cgi?id=573">573</a>: potential crash when unpacking ETC textures with unused padding pixels.
1915
@li Public Bugzilla <a href="http://www.khronos.org/bugzilla/show_bug.cgi?id=576">576</a>: various small fixes.
1916
1917
Thanks to Krystian Bigaj for the ktxLoadTextureM implementation and these fixes.
1918
1919
@section v1 Version 1.0
1920
Initial release.
1921
1922
*/
1923
1924
#endif /* KTX_H_A55A6F00956F42F3A137C11929827FE1 */
1925
1926