-
Notifications
You must be signed in to change notification settings - Fork 235
/
ktx.h
1883 lines (1691 loc) · 69 KB
/
ktx.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- tab-width: 4; -*- */
/* vi: set sw=2 ts=4 expandtab: */
#ifndef KTX_H_A55A6F00956F42F3A137C11929827FE1
#define KTX_H_A55A6F00956F42F3A137C11929827FE1
/*
* Copyright 2010-2018 The Khronos Group, Inc.
* SPDX-License-Identifier: Apache-2.0
*
* See the accompanying LICENSE.md for licensing details for all files in
* the KTX library and KTX loader tests.
*/
/**
* @file
* @~English
*
* @brief Declares the public functions and structures of the
* KTX API.
*
* @author Mark Callow, Edgewise Consulting and while at HI Corporation
* @author Based on original work by Georg Kolling, Imagination Technology
*
* @snippet{doc} version.h API version
*/
#include <limits.h>
#include <stdio.h>
#include <stdbool.h>
#include <sys/types.h>
#include <KHR/khr_df.h>
/*
* Don't use khrplatform.h in order not to break apps existing
* before these definitions were needed.
*/
#if defined(KHRONOS_STATIC)
#define KTX_API
#elif defined(_WIN32) || defined(__CYGWIN__)
#if !defined(KTX_API)
#if __GNUC__
#define KTX_API __attribute__ ((dllimport))
#elif _MSC_VER
#define KTX_API __declspec(dllimport)
#else
#error "Your compiler's equivalent of dllimport is unknown"
#endif
#endif
#elif defined(__ANDROID__)
#define KTX_API __attribute__((visibility("default")))
#else
#define KTX_API
#endif
#if defined(_WIN32) && !defined(KHRONOS_STATIC)
#if !defined(KTX_APIENTRY)
#define KTX_APIENTRY __stdcall
#endif
#else
#define KTX_APIENTRY
#endif
/* To avoid including <KHR/khrplatform.h> define our own types. */
typedef unsigned char ktx_uint8_t;
typedef bool ktx_bool_t;
#ifdef _MSC_VER
typedef unsigned __int16 ktx_uint16_t;
typedef signed __int16 ktx_int16_t;
typedef unsigned __int32 ktx_uint32_t;
typedef signed __int32 ktx_int32_t;
typedef size_t ktx_size_t;
typedef unsigned __int64 ktx_uint64_t;
typedef signed __int64 ktx_int64_t;
#else
#include <stdint.h>
typedef uint16_t ktx_uint16_t;
typedef int16_t ktx_int16_t;
typedef uint32_t ktx_uint32_t;
typedef int32_t ktx_int32_t;
typedef size_t ktx_size_t;
typedef uint64_t ktx_uint64_t;
typedef int64_t ktx_int64_t;
#endif
/* This will cause compilation to fail if size of uint32 != 4. */
typedef unsigned char ktx_uint32_t_SIZE_ASSERT[sizeof(ktx_uint32_t) == 4];
/*
* This #if allows libktx to be compiled with strict c99. It avoids
* compiler warnings or even errors when a gl.h is already included.
* "Redefinition of (type) is a c11 feature". Obviously this doesn't help if
* gl.h comes after. However nobody has complained about the unguarded typedefs
* since they were introduced so this is unlikely to be a problem in practice.
* Presumably everybody is using platform default compilers not c99 or else
* they are using C++.
*/
#if !defined(GL_NO_ERROR)
/*
* To avoid having to including gl.h ...
*/
typedef unsigned char GLboolean;
typedef unsigned int GLenum;
typedef int GLint;
typedef int GLsizei;
typedef unsigned int GLuint;
typedef unsigned char GLubyte;
#endif
#ifdef __cplusplus
extern "C" {
#endif
/**
* @~English
* @brief Key string for standard writer metadata.
*/
#define KTX_ANIMDATA_KEY "KTXanimData"
/**
* @~English
* @brief Key string for standard orientation metadata.
*/
#define KTX_ORIENTATION_KEY "KTXorientation"
/**
* @~English
* @brief Key string for standard swizzle metadata.
*/
#define KTX_SWIZZLE_KEY "KTXswizzle"
/**
* @~English
* @brief Key string for standard writer metadata.
*/
#define KTX_WRITER_KEY "KTXwriter"
/**
* @~English
* @brief Key string for standard writer supercompression parameter metadata.
*/
#define KTX_WRITER_SCPARAMS_KEY "KTXwriterScParams"
/**
* @~English
* @brief Standard KTX 1 format for 1D orientation value.
*/
#define KTX_ORIENTATION1_FMT "S=%c"
/**
* @~English
* @brief Standard KTX 1 format for 2D orientation value.
*/
#define KTX_ORIENTATION2_FMT "S=%c,T=%c"
/**
* @~English
* @brief Standard KTX 1 format for 3D orientation value.
*/
#define KTX_ORIENTATION3_FMT "S=%c,T=%c,R=%c"
/**
* @~English
* @brief Required unpack alignment
*/
#define KTX_GL_UNPACK_ALIGNMENT 4
#define KTX_FACESLICE_WHOLE_LEVEL UINT_MAX
#define KTX_TRUE true
#define KTX_FALSE false
/**
* @~English
* @brief Error codes returned by library functions.
*/
typedef enum ktx_error_code_e {
KTX_SUCCESS = 0, /*!< Operation was successful. */
KTX_FILE_DATA_ERROR, /*!< The data in the file is inconsistent with the spec. */
KTX_FILE_ISPIPE, /*!< The file is a pipe or named pipe. */
KTX_FILE_OPEN_FAILED, /*!< The target file could not be opened. */
KTX_FILE_OVERFLOW, /*!< The operation would exceed the max file size. */
KTX_FILE_READ_ERROR, /*!< An error occurred while reading from the file. */
KTX_FILE_SEEK_ERROR, /*!< An error occurred while seeking in the file. */
KTX_FILE_UNEXPECTED_EOF, /*!< File does not have enough data to satisfy request. */
KTX_FILE_WRITE_ERROR, /*!< An error occurred while writing to the file. */
KTX_GL_ERROR, /*!< GL operations resulted in an error. */
KTX_INVALID_OPERATION, /*!< The operation is not allowed in the current state. */
KTX_INVALID_VALUE, /*!< A parameter value was not valid. */
KTX_NOT_FOUND, /*!< Requested metadata key or required dynamically loaded GPU function was not found. */
KTX_OUT_OF_MEMORY, /*!< Not enough memory to complete the operation. */
KTX_TRANSCODE_FAILED, /*!< Transcoding of block compressed texture failed. */
KTX_UNKNOWN_FILE_FORMAT, /*!< The file not a KTX file */
KTX_UNSUPPORTED_TEXTURE_TYPE, /*!< The KTX file specifies an unsupported texture type. */
KTX_UNSUPPORTED_FEATURE, /*!< Feature not included in in-use library or not yet implemented. */
KTX_LIBRARY_NOT_LINKED, /*!< Library dependency (OpenGL or Vulkan) not linked into application. */
KTX_DECOMPRESS_LENGTH_ERROR, /*!< Decompressed byte count does not match expected byte size */
KTX_DECOMPRESS_CHECKSUM_ERROR, /*!< Checksum mismatch when decompressing */
KTX_ERROR_MAX_ENUM = KTX_DECOMPRESS_CHECKSUM_ERROR /*!< For safety checks. */
} ktx_error_code_e;
/**
* @~English
* @deprecated Use #ktx_error_code_e.
* @brief For backward compatibility
*/
#define KTX_error_code ktx_error_code_e
#define KTX_IDENTIFIER_REF { 0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A }
#define KTX_ENDIAN_REF (0x04030201)
#define KTX_ENDIAN_REF_REV (0x01020304)
#define KTX_HEADER_SIZE (64)
/**
* @~English
* @brief Result codes returned by library functions.
*/
typedef enum ktx_error_code_e ktxResult;
/**
* @class ktxHashList
* @~English
* @brief Opaque handle to a ktxHashList.
*/
typedef struct ktxKVListEntry* ktxHashList;
typedef struct ktxStream ktxStream;
#define KTX_APIENTRYP KTX_APIENTRY *
/**
* @class ktxHashListEntry
* @~English
* @brief Opaque handle to an entry in a @ref ktxHashList.
*/
typedef struct ktxKVListEntry ktxHashListEntry;
typedef enum ktxOrientationX {
KTX_ORIENT_X_LEFT = 'l', KTX_ORIENT_X_RIGHT = 'r'
} ktxOrientationX;
typedef enum ktxOrientationY {
KTX_ORIENT_Y_UP = 'u', KTX_ORIENT_Y_DOWN = 'd'
} ktxOrientationY;
typedef enum ktxOrientationZ {
KTX_ORIENT_Z_IN = 'i', KTX_ORIENT_Z_OUT = 'o'
} ktxOrientationZ;
typedef enum class_id {
ktxTexture1_c = 1,
ktxTexture2_c = 2
} class_id;
/**
* @~English
* @brief Struct describing the logical orientation of an image.
*/
struct ktxOrientation {
ktxOrientationX x; /*!< Orientation in X */
ktxOrientationY y; /*!< Orientation in Y */
ktxOrientationZ z; /*!< Orientation in Z */
};
#define KTXTEXTURECLASSDEFN \
class_id classId; \
struct ktxTexture_vtbl* vtbl; \
struct ktxTexture_vvtbl* vvtbl; \
struct ktxTexture_protected* _protected; \
ktx_bool_t isArray; \
ktx_bool_t isCubemap; \
ktx_bool_t isCompressed; \
ktx_bool_t generateMipmaps; \
ktx_uint32_t baseWidth; \
ktx_uint32_t baseHeight; \
ktx_uint32_t baseDepth; \
ktx_uint32_t numDimensions; \
ktx_uint32_t numLevels; \
ktx_uint32_t numLayers; \
ktx_uint32_t numFaces; \
struct ktxOrientation orientation; \
ktxHashList kvDataHead; \
ktx_uint32_t kvDataLen; \
ktx_uint8_t* kvData; \
ktx_size_t dataSize; \
ktx_uint8_t* pData;
/**
* @class ktxTexture
* @~English
* @brief Base class representing a texture.
*
* ktxTextures should be created only by one of the provided
* functions and these fields should be considered read-only.
*/
typedef struct ktxTexture {
KTXTEXTURECLASSDEFN
} ktxTexture;
/**
* @typedef ktxTexture::classId
* @~English
* @brief Identify the class type.
*
* Since there are no public ktxTexture constructors, this can only have
* values of ktxTexture1_c or ktxTexture2_c.
*/
/**
* @typedef ktxTexture::vtbl
* @~English
* @brief Pointer to the class's vtble.
*/
/**
* @typedef ktxTexture::vvtbl
* @~English
* @brief Pointer to the class's vtble for Vulkan functions.
*
* A separate vtble is used so this header does not need to include vulkan.h.
*/
/**
* @typedef ktxTexture::_protected
* @~English
* @brief Opaque pointer to the class's protected variables.
*/
/**
* @typedef ktxTexture::isArray
* @~English
*
* KTX_TRUE if the texture is an array texture, i.e,
* a GL_TEXTURE_*_ARRAY target is to be used.
*/
/**
* @typedef ktxTexture::isCubemap
* @~English
*
* KTX_TRUE if the texture is a cubemap or cubemap array.
*/
/**
* @typedef ktxTexture::isCompressed
* @~English
*
* KTX_TRUE if the texture's format is a block compressed format.
*/
/**
* @typedef ktxTexture::generateMipmaps
* @~English
*
* KTX_TRUE if mipmaps should be generated for the texture by
* ktxTexture_GLUpload() or ktxTexture_VkUpload().
*/
/**
* @typedef ktxTexture::baseWidth
* @~English
* @brief Width of the texture's base level.
*/
/**
* @typedef ktxTexture::baseHeight
* @~English
* @brief Height of the texture's base level.
*/
/**
* @typedef ktxTexture::baseDepth
* @~English
* @brief Depth of the texture's base level.
*/
/**
* @typedef ktxTexture::numDimensions
* @~English
* @brief Number of dimensions in the texture: 1, 2 or 3.
*/
/**
* @typedef ktxTexture::numLevels
* @~English
* @brief Number of mip levels in the texture.
*
* Must be 1, if @c generateMipmaps is KTX_TRUE. Can be less than a
* full pyramid but always starts at the base level.
*/
/**
* @typedef ktxTexture::numLevels
* @~English
* @brief Number of array layers in the texture.
*/
/**
* @typedef ktxTexture::numFaces
* @~English
* @brief Number of faces: 6 for cube maps, 1 otherwise.
*/
/**
* @typedef ktxTexture::orientation
* @~English
* @brief Describes the logical orientation of the images in each dimension.
*
* ktxOrientationX for X, ktxOrientationY for Y and ktxOrientationZ for Z.
*/
/**
* @typedef ktxTexture::kvDataHead
* @~English
* @brief Head of the hash list of metadata.
*/
/**
* @typedef ktxTexture::kvDataLen
* @~English
* @brief Length of the metadata, if it has been extracted in its raw form,
* otherwise 0.
*/
/**
* @typedef ktxTexture::kvData
* @~English
* @brief Pointer to the metadata, if it has been extracted in its raw form,
* otherwise NULL.
*/
/**
* @typedef ktxTexture::dataSize
* @~English
* @brief Byte length of the texture's uncompressed image data.
*/
/**
* @typedef ktxTexture::pData
* @~English
* @brief Pointer to the start of the image data.
*/
/**
* @memberof ktxTexture
* @~English
* @brief Signature of function called by the <tt>ktxTexture_Iterate*</tt>
* functions to receive image data.
*
* The function parameters are used to pass values which change for each image.
* Obtain values which are uniform across all images from the @c ktxTexture
* object.
*
* @param [in] miplevel MIP level from 0 to the max level which is
* dependent on the texture size.
* @param [in] face usually 0; for cube maps, one of the 6 cube
* faces in the order +X, -X, +Y, -Y, +Z, -Z,
* 0 to 5.
* @param [in] width width of the image.
* @param [in] height height of the image or, for 1D textures
* textures, 1.
* @param [in] depth depth of the image or, for 1D & 2D
* textures, 1.
* @param [in] faceLodSize number of bytes of data pointed at by
* @p pixels.
* @param [in] pixels pointer to the image data.
* @param [in,out] userdata pointer for the application to pass data to and
* from the callback function.
*/
typedef KTX_error_code
(* PFNKTXITERCB)(int miplevel, int face,
int width, int height, int depth,
ktx_uint64_t faceLodSize,
void* pixels, void* userdata);
/* Don't use KTX_APIENTRYP to avoid a Doxygen bug. */
typedef void (KTX_APIENTRY* PFNKTEXDESTROY)(ktxTexture* This);
typedef KTX_error_code
(KTX_APIENTRY* PFNKTEXGETIMAGEOFFSET)(ktxTexture* This, ktx_uint32_t level,
ktx_uint32_t layer,
ktx_uint32_t faceSlice,
ktx_size_t* pOffset);
typedef ktx_size_t
(KTX_APIENTRY* PFNKTEXGETDATASIZEUNCOMPRESSED)(ktxTexture* This);
typedef ktx_size_t
(KTX_APIENTRY* PFNKTEXGETIMAGESIZE)(ktxTexture* This, ktx_uint32_t level);
typedef ktx_size_t
(KTX_APIENTRY* PFNKTEXGETLEVELSIZE)(ktxTexture* This, ktx_uint32_t level);
typedef KTX_error_code
(KTX_APIENTRY* PFNKTEXITERATELEVELS)(ktxTexture* This, PFNKTXITERCB iterCb,
void* userdata);
typedef KTX_error_code
(KTX_APIENTRY* PFNKTEXITERATELOADLEVELFACES)(ktxTexture* This,
PFNKTXITERCB iterCb,
void* userdata);
typedef KTX_error_code
(KTX_APIENTRY* PFNKTEXLOADIMAGEDATA)(ktxTexture* This,
ktx_uint8_t* pBuffer,
ktx_size_t bufSize);
typedef ktx_bool_t
(KTX_APIENTRY* PFNKTEXNEEDSTRANSCODING)(ktxTexture* This);
typedef KTX_error_code
(KTX_APIENTRY* PFNKTEXSETIMAGEFROMMEMORY)(ktxTexture* This,
ktx_uint32_t level,
ktx_uint32_t layer,
ktx_uint32_t faceSlice,
const ktx_uint8_t* src,
ktx_size_t srcSize);
typedef KTX_error_code
(KTX_APIENTRY* PFNKTEXSETIMAGEFROMSTDIOSTREAM)(ktxTexture* This,
ktx_uint32_t level,
ktx_uint32_t layer,
ktx_uint32_t faceSlice,
FILE* src, ktx_size_t srcSize);
typedef KTX_error_code
(KTX_APIENTRY* PFNKTEXWRITETOSTDIOSTREAM)(ktxTexture* This, FILE* dstsstr);
typedef KTX_error_code
(KTX_APIENTRY* PFNKTEXWRITETONAMEDFILE)(ktxTexture* This,
const char* const dstname);
typedef KTX_error_code
(KTX_APIENTRY* PFNKTEXWRITETOMEMORY)(ktxTexture* This,
ktx_uint8_t** bytes, ktx_size_t* size);
typedef KTX_error_code
(KTX_APIENTRY* PFNKTEXWRITETOSTREAM)(ktxTexture* This,
ktxStream* dststr);
/**
* @memberof ktxTexture
* @~English
* @brief Table of virtual ktxTexture methods.
*/
struct ktxTexture_vtbl {
PFNKTEXDESTROY Destroy;
PFNKTEXGETIMAGEOFFSET GetImageOffset;
PFNKTEXGETDATASIZEUNCOMPRESSED GetDataSizeUncompressed;
PFNKTEXGETIMAGESIZE GetImageSize;
PFNKTEXGETLEVELSIZE GetLevelSize;
PFNKTEXITERATELEVELS IterateLevels;
PFNKTEXITERATELOADLEVELFACES IterateLoadLevelFaces;
PFNKTEXNEEDSTRANSCODING NeedsTranscoding;
PFNKTEXLOADIMAGEDATA LoadImageData;
PFNKTEXSETIMAGEFROMMEMORY SetImageFromMemory;
PFNKTEXSETIMAGEFROMSTDIOSTREAM SetImageFromStdioStream;
PFNKTEXWRITETOSTDIOSTREAM WriteToStdioStream;
PFNKTEXWRITETONAMEDFILE WriteToNamedFile;
PFNKTEXWRITETOMEMORY WriteToMemory;
PFNKTEXWRITETOSTREAM WriteToStream;
};
/****************************************************************
* Macros to give some backward compatibility to the previous API
****************************************************************/
/**
* @~English
* @brief Helper for calling the Destroy virtual method of a ktxTexture.
* @copydoc ktxTexture2.ktxTexture2_Destroy
*/
#define ktxTexture_Destroy(This) (This)->vtbl->Destroy(This)
/**
* @~English
* @brief Helper for calling the GetImageOffset virtual method of a
* ktxTexture.
* @copydoc ktxTexture2.ktxTexture2_GetImageOffset
*/
#define ktxTexture_GetImageOffset(This, level, layer, faceSlice, pOffset) \
(This)->vtbl->GetImageOffset(This, level, layer, faceSlice, pOffset)
/**
* @~English
* @brief Helper for calling the GetDataSizeUncompressed virtual method of a ktxTexture.
*
* For a ktxTexture1 this will always return the value of This->dataSize.
*
* @copydetails ktxTexture2.ktxTexture2_GetDataSizeUncompressed
*/
#define ktxTexture_GetDataSizeUncompressed(This) \
(This)->vtbl->GetDataSizeUncompressed(This)
/**
* @~English
* @brief Helper for calling the GetImageSize virtual method of a ktxTexture.
* @copydoc ktxTexture2.ktxTexture2_GetImageSize
*/
#define ktxTexture_GetImageSize(This, level) \
(This)->vtbl->GetImageSize(This, level)
/**
* @~English
* @brief Helper for calling the GetImageSize virtual method of a ktxTexture.
* @copydoc ktxTexture2.ktxTexture2_GetImageSize
*/
#define ktxTexture_GetLevelSize(This, level) \
(This)->vtbl->GetLevelSize(This, level)
/**
* @~English
* @brief Helper for calling the IterateLevels virtual method of a ktxTexture.
* @copydoc ktxTexture2.ktxTexture2_IterateLevels
*/
#define ktxTexture_IterateLevels(This, iterCb, userdata) \
(This)->vtbl->IterateLevels(This, iterCb, userdata)
/**
* @~English
* @brief Helper for calling the IterateLoadLevelFaces virtual method of a
* ktxTexture.
* @copydoc ktxTexture2.ktxTexture2_IterateLoadLevelFaces
*/
#define ktxTexture_IterateLoadLevelFaces(This, iterCb, userdata) \
(This)->vtbl->IterateLoadLevelFaces(This, iterCb, userdata)
/**
* @~English
* @brief Helper for calling the LoadImageData virtual method of a ktxTexture.
* @copydoc ktxTexture2.ktxTexture2_LoadImageData
*/
#define ktxTexture_LoadImageData(This, pBuffer, bufSize) \
(This)->vtbl->LoadImageData(This, pBuffer, bufSize)
/**
* @~English
* @brief Helper for calling the NeedsTranscoding virtual method of a ktxTexture.
* @copydoc ktxTexture2.ktxTexture2_NeedsTranscoding
*/
#define ktxTexture_NeedsTranscoding(This) (This)->vtbl->NeedsTranscoding(This)
/**
* @~English
* @brief Helper for calling the SetImageFromMemory virtual method of a
* ktxTexture.
* @copydoc ktxTexture2.ktxTexture2_SetImageFromMemory
*/
#define ktxTexture_SetImageFromMemory(This, level, layer, faceSlice, \
src, srcSize) \
(This)->vtbl->SetImageFromMemory(This, level, layer, faceSlice, src, srcSize)
/**
* @~English
* @brief Helper for calling the SetImageFromStdioStream virtual method of a
* ktxTexture.
* @copydoc ktxTexture2.ktxTexture2_SetImageFromStdioStream
*/
#define ktxTexture_SetImageFromStdioStream(This, level, layer, faceSlice, \
src, srcSize) \
(This)->vtbl->SetImageFromStdioStream(This, level, layer, faceSlice, \
src, srcSize)
/**
* @~English
* @brief Helper for calling the WriteToStdioStream virtual method of a
* ktxTexture.
* @copydoc ktxTexture2.ktxTexture2_WriteToStdioStream
*/
#define ktxTexture_WriteToStdioStream(This, dstsstr) \
(This)->vtbl->WriteToStdioStream(This, dstsstr)
/**
* @~English
* @brief Helper for calling the WriteToNamedfile virtual method of a
* ktxTexture.
* @copydoc ktxTexture2.ktxTexture2_WriteToNamedFile
*/
#define ktxTexture_WriteToNamedFile(This, dstname) \
(This)->vtbl->WriteToNamedFile(This, dstname)
/**
* @~English
* @brief Helper for calling the WriteToMemory virtual method of a ktxTexture.
* @copydoc ktxTexture2.ktxTexture2_WriteToMemory
*/
#define ktxTexture_WriteToMemory(This, ppDstBytes, pSize) \
(This)->vtbl->WriteToMemory(This, ppDstBytes, pSize)
/**
* @~English
* @brief Helper for calling the WriteToStream virtual method of a ktxTexture.
* @copydoc ktxTexture2.ktxTexture2_WriteToStream
*/
#define ktxTexture_WriteToStream(This, dststr) \
(This)->vtbl->WriteToStream(This, dststr)
/**
* @class ktxTexture1
* @~English
* @brief Class representing a KTX version 1 format texture.
*
* ktxTextures should be created only by one of the ktxTexture_Create*
* functions and these fields should be considered read-only.
*/
typedef struct ktxTexture1 {
KTXTEXTURECLASSDEFN
ktx_uint32_t glFormat; /*!< Format of the texture data, e.g., GL_RGB. */
ktx_uint32_t glInternalformat; /*!< Internal format of the texture data,
e.g., GL_RGB8. */
ktx_uint32_t glBaseInternalformat; /*!< Base format of the texture data,
e.g., GL_RGB. */
ktx_uint32_t glType; /*!< Type of the texture data, e.g, GL_UNSIGNED_BYTE.*/
struct ktxTexture1_private* _private; /*!< Private data. */
} ktxTexture1;
/*===========================================================*
* KTX format version 2 *
*===========================================================*/
/**
* @~English
* @brief Enumerators identifying the supercompression scheme.
*/
typedef enum ktxSupercmpScheme {
KTX_SS_NONE = 0, /*!< No supercompression. */
KTX_SS_BASIS_LZ = 1, /*!< Basis LZ supercompression. */
KTX_SS_ZSTD = 2, /*!< ZStd supercompression. */
KTX_SS_ZLIB = 3, /*!< ZLIB supercompression. */
KTX_SS_BEGIN_RANGE = KTX_SS_NONE,
KTX_SS_END_RANGE = KTX_SS_ZLIB,
KTX_SS_BEGIN_VENDOR_RANGE = 0x10000,
KTX_SS_END_VENDOR_RANGE = 0x1ffff,
KTX_SS_BEGIN_RESERVED = 0x20000
} ktxSupercmpScheme;
/**
* @class ktxTexture2
* @~English
* @brief Class representing a KTX version 2 format texture.
*
* ktxTextures should be created only by one of the ktxTexture_Create*
* functions and these fields should be considered read-only.
*/
typedef struct ktxTexture2 {
KTXTEXTURECLASSDEFN
ktx_uint32_t vkFormat;
ktx_uint32_t* pDfd;
ktxSupercmpScheme supercompressionScheme;
ktx_bool_t isVideo;
ktx_uint32_t duration;
ktx_uint32_t timescale;
ktx_uint32_t loopcount;
struct ktxTexture2_private* _private; /*!< Private data. */
} ktxTexture2;
/*
* If Doxygen sees this macro it gets confused and fails to spot
* references to ktxTexture_*() functions in the running text. It
* also complains it can't find the reference when @ref is used
* with a fully qualified method name to make an intra-class
* reference in the @c ktxTexture class.
* See https://github.com/doxygen/doxygen/issues/10311.
*
* Not documenting the macro is the lesser of two evils.
*/
#if !defined(KTX_DOXYGEN_SKIP)
/**
* @brief Helper for casting ktxTexture1 and ktxTexture2 to ktxTexture.
*
* Use with caution.
*/
#define ktxTexture(t) ((ktxTexture*)t)
#endif
/**
* @memberof ktxTexture
* @~English
* @brief Structure for passing texture information to ktxTexture1\_Create() and
* ktxTexture2\_Create().
*
* @sa @ref ktxTexture1::ktxTexture1\_Create() "ktxTexture1_Create()"
* @sa @ref ktxTexture2::ktxTexture2\_Create() "ktxTexture2_Create()"
*/
typedef struct
{
ktx_uint32_t glInternalformat; /*!< Internal format for the texture, e.g.,
GL_RGB8. Ignored when creating a
ktxTexture2. */
ktx_uint32_t vkFormat; /*!< VkFormat for texture. Ignored when creating a
ktxTexture1. */
ktx_uint32_t* pDfd; /*!< Pointer to DFD. Used only when creating a
ktxTexture2 and only if vkFormat is
VK_FORMAT_UNDEFINED. */
ktx_uint32_t baseWidth; /*!< Width of the base level of the texture. */
ktx_uint32_t baseHeight; /*!< Height of the base level of the texture. */
ktx_uint32_t baseDepth; /*!< Depth of the base level of the texture. */
ktx_uint32_t numDimensions; /*!< Number of dimensions in the texture, 1, 2
or 3. */
ktx_uint32_t numLevels; /*!< Number of mip levels in the texture. Should be
1 if @c generateMipmaps is KTX_TRUE; */
ktx_uint32_t numLayers; /*!< Number of array layers in the texture. */
ktx_uint32_t numFaces; /*!< Number of faces: 6 for cube maps, 1 otherwise. */
ktx_bool_t isArray; /*!< Set to KTX_TRUE if the texture is to be an
array texture. Means OpenGL will use a
GL_TEXTURE_*_ARRAY target. */
ktx_bool_t generateMipmaps; /*!< Set to KTX_TRUE if mipmaps should be
generated for the texture when loading
into a 3D API. */
} ktxTextureCreateInfo;
/**
* @memberof ktxTexture
* @~English
* @brief Enum for requesting, or not, allocation of storage for images.
*
* @sa ktxTexture1_Create() and ktxTexture2_Create().
*/
typedef enum {
KTX_TEXTURE_CREATE_NO_STORAGE = 0, /*!< Don't allocate any image storage. */
KTX_TEXTURE_CREATE_ALLOC_STORAGE = 1 /*!< Allocate image storage. */
} ktxTextureCreateStorageEnum;
/**
* @memberof ktxTexture
* @~English
* @brief Flags for requesting services during creation.
*
* @sa ktxTexture_CreateFrom*
*/
enum ktxTextureCreateFlagBits {
KTX_TEXTURE_CREATE_NO_FLAGS = 0x00,
KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT = 0x01,
/*!< Load the images from the KTX source. */
KTX_TEXTURE_CREATE_RAW_KVDATA_BIT = 0x02,
/*!< Load the raw key-value data instead of
creating a @c ktxHashList from it. */
KTX_TEXTURE_CREATE_SKIP_KVDATA_BIT = 0x04,
/*!< Skip any key-value data. This overrides
the RAW_KVDATA_BIT. */
KTX_TEXTURE_CREATE_CHECK_GLTF_BASISU_BIT = 0x08
/*!< Load texture compatible with the rules
of KHR_texture_basisu glTF extension */
};
/**
* @memberof ktxTexture
* @~English
* @brief Type for TextureCreateFlags parameters.
*
* @sa ktxTexture_CreateFrom*()
*/
typedef ktx_uint32_t ktxTextureCreateFlags;
/*===========================================================*
* ktxStream
*===========================================================*/
/*
* This is unsigned to allow ktxmemstreams to use the
* full amount of memory available. Platforms will
* limit the size of ktxfilestreams to, e.g, MAX_LONG
* on 32-bit and ktxfilestreams raises errors if
* offset values exceed the limits. This choice may
* need to be revisited if we ever start needing -ve
* offsets.
*
* Should the 2GB file size handling limit on 32-bit
* platforms become a problem, ktxfilestream will have
* to be changed to explicitly handle large files by
* using the 64-bit stream functions.
*/
#if defined(_MSC_VER) && defined(_WIN64)
typedef unsigned __int64 ktx_off_t;
#else
typedef off_t ktx_off_t;
#endif
typedef struct ktxMem ktxMem;
typedef struct ktxStream ktxStream;
enum streamType { eStreamTypeFile = 1, eStreamTypeMemory = 2, eStreamTypeCustom = 3 };
/**
* @~English
* @brief type for a pointer to a stream reading function
*/
typedef KTX_error_code (*ktxStream_read)(ktxStream* str, void* dst,
const ktx_size_t count);
/**
* @~English
* @brief type for a pointer to a stream skipping function
*/
typedef KTX_error_code (*ktxStream_skip)(ktxStream* str,
const ktx_size_t count);
/**
* @~English
* @brief type for a pointer to a stream writing function
*/
typedef KTX_error_code (*ktxStream_write)(ktxStream* str, const void *src,
const ktx_size_t size,
const ktx_size_t count);
/**
* @~English
* @brief type for a pointer to a stream position query function
*/
typedef KTX_error_code (*ktxStream_getpos)(ktxStream* str, ktx_off_t* const offset);
/**
* @~English
* @brief type for a pointer to a stream position query function
*/
typedef KTX_error_code (*ktxStream_setpos)(ktxStream* str, const ktx_off_t offset);
/**
* @~English
* @brief type for a pointer to a stream size query function
*/
typedef KTX_error_code (*ktxStream_getsize)(ktxStream* str, ktx_size_t* const size);
/**
* @~English
* @brief Destruct a stream
*/
typedef void (*ktxStream_destruct)(ktxStream* str);
/**
* @~English
*
* @brief Interface of ktxStream.
*
* @author Maksim Kolesin
* @author Georg Kolling, Imagination Technology
* @author Mark Callow, HI Corporation
*/
struct ktxStream
{
ktxStream_read read; /*!< pointer to function for reading bytes. */
ktxStream_skip skip; /*!< pointer to function for skipping bytes. */
ktxStream_write write; /*!< pointer to function for writing bytes. */
ktxStream_getpos getpos; /*!< pointer to function for getting current position in stream. */
ktxStream_setpos setpos; /*!< pointer to function for setting current position in stream. */
ktxStream_getsize getsize; /*!< pointer to function for querying size. */
ktxStream_destruct destruct; /*!< destruct the stream. */
enum streamType type;
union {
FILE* file; /**< a stdio FILE pointer for a ktxFileStream. */
ktxMem* mem; /**< a pointer to a ktxMem struct for a ktxMemStream. */
struct
{
void* address; /**< pointer to the data. */
void* allocatorAddress; /**< pointer to a memory allocator. */
ktx_size_t size; /**< size of the data. */
} custom_ptr; /**< pointer to a struct for custom streams. */
} data; /**< pointer to the stream data. */
ktx_off_t readpos; /**< used by FileStream for stdin. */
ktx_bool_t closeOnDestruct; /**< Close FILE* or dispose of memory on destruct. */
};
/*
* See the implementation files for the full documentation of the following
* functions.
*/
/**
* @~English
* @brief typedef of function pointer returned by GLGetProcAddress functions.
*/
typedef void (KTX_APIENTRY* PFNVOIDFUNCTION)(void);
/**
* @~English
* @brief typedef of pointer to function for retrieving OpenGL function pointers.
*/
typedef PFNVOIDFUNCTION (KTX_APIENTRY* PFNGLGETPROCADDRESS) (const char *proc);
/*
* Load pointers for the OpenGL functions needed by ktxTexture_GLUpload.
*/
KTX_API KTX_error_code KTX_APIENTRY
ktxLoadOpenGL(PFNGLGETPROCADDRESS pfnGLGetProcAddress);
/*
* These four create a ktxTexture1 or ktxTexture2 according to the data
* header, and return a pointer to the base ktxTexture class.
*/
KTX_API KTX_error_code KTX_APIENTRY
ktxTexture_CreateFromStdioStream(FILE* stdioStream,
ktxTextureCreateFlags createFlags,
ktxTexture** newTex);
KTX_API KTX_error_code KTX_APIENTRY
ktxTexture_CreateFromNamedFile(const char* const filename,
ktxTextureCreateFlags createFlags,
ktxTexture** newTex);
KTX_API KTX_error_code KTX_APIENTRY
ktxTexture_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size,
ktxTextureCreateFlags createFlags,
ktxTexture** newTex);
KTX_API KTX_error_code KTX_APIENTRY
ktxTexture_CreateFromStream(ktxStream* stream,
ktxTextureCreateFlags createFlags,
ktxTexture** newTex);
/*
* Returns a pointer to the image data of a ktxTexture object.
*/
KTX_API ktx_uint8_t* KTX_APIENTRY
ktxTexture_GetData(ktxTexture* This);
/*
* Returns the pitch of a row of an image at the specified level.
* Similar to the rowPitch in a VkSubResourceLayout.
*/
KTX_API ktx_uint32_t KTX_APIENTRY
ktxTexture_GetRowPitch(ktxTexture* This, ktx_uint32_t level);
/*
* Return the element size of the texture's images.
*/
KTX_API ktx_uint32_t KTX_APIENTRY
ktxTexture_GetElementSize(ktxTexture* This);
/*
* Returns the size of all the image data of a ktxTexture object in bytes.
*/
KTX_API ktx_size_t KTX_APIENTRY
ktxTexture_GetDataSize(ktxTexture* This);
/* Uploads a texture to OpenGL {,ES}. */
KTX_API KTX_error_code KTX_APIENTRY
ktxTexture_GLUpload(ktxTexture* This, GLuint* pTexture, GLenum* pTarget,
GLenum* pGlerror);
/*
* Iterate over the levels or faces in a ktxTexture object.
*/
KTX_API KTX_error_code KTX_APIENTRY