-
Notifications
You must be signed in to change notification settings - Fork 0
/
DirectXTex.h
1229 lines (917 loc) · 49 KB
/
DirectXTex.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
#pragma once
#pragma comment(lib, "d3d12.lib")
#define D3DX12_NO_STATE_OBJECT_HELPERS
#define D3DX12_NO_CHECK_FEATURE_SUPPORT_CLASS
#ifdef _GAMING_XBOX_SCARLETT
#include <d3dx12_xs.h>
#elif (defined(_XBOX_ONE) && defined(_TITLE)) || defined(_GAMING_XBOX)
#include "d3dx12_x.h"
#elif !defined(_WIN32) || defined(USING_DIRECTX_HEADERS)
#include "directx/d3dx12.h"
#include "dxguids/dxguids.h"
#include "directx/dxgiformat.h"
#else
#include "d3d12.h"
#include "dxgiformat.h"
#endif
#ifdef _WIN32
#include <d3d11_1.h>
#endif
// #define DEFINE_STRUCTS_AND_ENUMS
#ifdef DEFINE_STRUCTS_AND_ENUMS
#include <DirectXMath.h>
struct IWICImagingFactory;
struct IWICMetadataQueryReader;
typedef struct ScratchImage *ScratchImageT;
typedef struct Blob *BlobT;
#ifdef _WIN32
typedef void(__cdecl *SetCustomProps)(IPropertyBag2 *pBag);
typedef void(__cdecl *GetMQR)(IWICMetadataQueryReader *qMqr);
#endif
typedef void(__cdecl *EvaluateImageFunc)(const DirectX::XMVECTOR *pixels, size_t width, size_t y);
typedef void(__cdecl *TransformImageFunc)(DirectX::XMVECTOR *outPixels, const DirectX::XMVECTOR *inPixels, size_t width, size_t y);
typedef enum
{
FORMAT_TYPE_TYPELESS,
FORMAT_TYPE_FLOAT,
FORMAT_TYPE_UNORM,
FORMAT_TYPE_SNORM,
FORMAT_TYPE_UINT,
FORMAT_TYPE_SINT,
} FORMAT_TYPE;
typedef enum
{
CP_FLAGS_NONE = 0x0,
// Normal operation
CP_FLAGS_LEGACY_DWORD = 0x1,
// Assume pitch is DWORD aligned instead of BYTE aligned
CP_FLAGS_PARAGRAPH = 0x2,
// Assume pitch is 16-byte aligned instead of BYTE aligned
CP_FLAGS_YMM = 0x4,
// Assume pitch is 32-byte aligned instead of BYTE aligned
CP_FLAGS_ZMM = 0x8,
// Assume pitch is 64-byte aligned instead of BYTE aligned
CP_FLAGS_PAGE4K = 0x200,
// Assume pitch is 4096-byte aligned instead of BYTE aligned
CP_FLAGS_BAD_DXTN_TAILS = 0x1000,
// BC formats with malformed mipchain blocks smaller than 4x4
CP_FLAGS_24BPP = 0x10000,
// Override with a legacy 24 bits-per-pixel format size
CP_FLAGS_16BPP = 0x20000,
// Override with a legacy 16 bits-per-pixel format size
CP_FLAGS_8BPP = 0x40000,
// Override with a legacy 8 bits-per-pixel format size
} CP_FLAGS;
typedef enum
{
TEX_DIMENSION_TEXTURE1D = 2,
TEX_DIMENSION_TEXTURE2D = 3,
TEX_DIMENSION_TEXTURE3D = 4,
} TEX_DIMENSION;
// Subset here matches D3D10_RESOURCE_MISC_FLAG and D3D11_RESOURCE_MISC_FLAG
typedef enum
{
TEX_MISC_TEXTURECUBE = 0x4L,
} TEX_MISC_FLAG;
typedef enum
{
TEX_MISC2_ALPHA_MODE_MASK = 0x7L,
} TEX_MISC_FLAG2;
// Matches DDS_ALPHA_MODE, encoded in MISC_FLAGS2
typedef enum
{
TEX_ALPHA_MODE_UNKNOWN = 0,
TEX_ALPHA_MODE_STRAIGHT = 1,
TEX_ALPHA_MODE_PREMULTIPLIED = 2,
TEX_ALPHA_MODE_OPAQUE = 3,
TEX_ALPHA_MODE_CUSTOM = 4,
} TEX_ALPHA_MODE;
typedef struct
{
size_t width;
size_t height; // Should be 1 for 1D textures
size_t depth; // Should be 1 for 1D or 2D textures
size_t arraySize; // For cubemap, this is a multiple of 6
size_t mipLevels;
uint32_t miscFlags;
uint32_t miscFlags2;
DXGI_FORMAT format;
TEX_DIMENSION dimension;
} TexMetadata;
typedef enum
{
DDS_FLAGS_NONE = 0x0,
DDS_FLAGS_LEGACY_DWORD = 0x1,
// Assume pitch is DWORD aligned instead of BYTE aligned (used by some legacy DDS files)
DDS_FLAGS_NO_LEGACY_EXPANSION = 0x2,
// Do not implicitly convert legacy formats that result in larger pixel sizes (24 bpp, 3:3:2, A8L8, A4L4, P8, A8P8)
DDS_FLAGS_NO_R10B10G10A2_FIXUP = 0x4,
// Do not use work-around for long-standing D3DX DDS file format issue which reversed the 10:10:10:2 color order masks
DDS_FLAGS_FORCE_RGB = 0x8,
// Convert DXGI 1.1 BGR formats to DXGI_FORMAT_R8G8B8A8_UNORM to avoid use of optional WDDM 1.1 formats
DDS_FLAGS_NO_16BPP = 0x10,
// Conversions avoid use of 565, 5551, and 4444 formats and instead expand to 8888 to avoid use of optional WDDM 1.2 formats
DDS_FLAGS_EXPAND_LUMINANCE = 0x20,
// When loading legacy luminance formats expand replicating the color channels rather than leaving them packed (L8, L16, A8L8)
DDS_FLAGS_BAD_DXTN_TAILS = 0x40,
// Some older DXTn DDS files incorrectly handle mipchain tails for blocks smaller than 4x4
DDS_FLAGS_FORCE_DX10_EXT = 0x10000,
// Always use the 'DX10' header extension for DDS writer (i.e. don't try to write DX9 compatible DDS files)
DDS_FLAGS_FORCE_DX10_EXT_MISC2 = 0x20000,
// DDS_FLAGS_FORCE_DX10_EXT including miscFlags2 information (result may not be compatible with D3DX10 or D3DX11)
DDS_FLAGS_FORCE_DX9_LEGACY = 0x40000,
// Force use of legacy header for DDS writer (will fail if unable to write as such)
DDS_FLAGS_ALLOW_LARGE_FILES = 0x1000000,
// Enables the loader to read large dimension .dds files (i.e. greater than known hardware requirements)
} DDS_FLAGS;
typedef enum
{
TGA_FLAGS_NONE = 0x0,
TGA_FLAGS_BGR = 0x1,
// 24bpp files are returned as BGRX; 32bpp files are returned as BGRA
TGA_FLAGS_ALLOW_ALL_ZERO_ALPHA = 0x2,
// If the loaded image has an all zero alpha channel, normally we assume it should be opaque. This flag leaves it alone.
TGA_FLAGS_IGNORE_SRGB = 0x10,
// Ignores sRGB TGA 2.0 metadata if present in the file
TGA_FLAGS_FORCE_SRGB = 0x20,
// Writes sRGB metadata into the file reguardless of format (TGA 2.0 only)
TGA_FLAGS_FORCE_LINEAR = 0x40,
// Writes linear gamma metadata into the file reguardless of format (TGA 2.0 only)
TGA_FLAGS_DEFAULT_SRGB = 0x80,
// If no colorspace is specified in TGA 2.0 metadata, assume sRGB
} TGA_FLAGS;
typedef enum
{
WIC_FLAGS_NONE = 0x0,
WIC_FLAGS_FORCE_RGB = 0x1,
// Loads DXGI 1.1 BGR formats as DXGI_FORMAT_R8G8B8A8_UNORM to avoid use of optional WDDM 1.1 formats
WIC_FLAGS_NO_X2_BIAS = 0x2,
// Loads DXGI 1.1 X2 10:10:10:2 format as DXGI_FORMAT_R10G10B10A2_UNORM
WIC_FLAGS_NO_16BPP = 0x4,
// Loads 565, 5551, and 4444 formats as 8888 to avoid use of optional WDDM 1.2 formats
WIC_FLAGS_ALLOW_MONO = 0x8,
// Loads 1-bit monochrome (black & white) as R1_UNORM rather than 8-bit grayscale
WIC_FLAGS_ALL_FRAMES = 0x10,
// Loads all images in a multi-frame file, converting/resizing to match the first frame as needed, defaults to 0th frame otherwise
WIC_FLAGS_IGNORE_SRGB = 0x20,
// Ignores sRGB metadata if present in the file
WIC_FLAGS_FORCE_SRGB = 0x40,
// Writes sRGB metadata into the file reguardless of format
WIC_FLAGS_FORCE_LINEAR = 0x80,
// Writes linear gamma metadata into the file reguardless of format
WIC_FLAGS_DEFAULT_SRGB = 0x100,
// If no colorspace is specified, assume sRGB
WIC_FLAGS_DITHER = 0x10000,
// Use ordered 4x4 dithering for any required conversions
WIC_FLAGS_DITHER_DIFFUSION = 0x20000,
// Use error-diffusion dithering for any required conversions
WIC_FLAGS_FILTER_POINT = 0x100000,
WIC_FLAGS_FILTER_LINEAR = 0x200000,
WIC_FLAGS_FILTER_CUBIC = 0x300000,
WIC_FLAGS_FILTER_FANT = 0x400000, // Combination of Linear and Box filter
// Filtering mode to use for any required image resizing (only needed when loading arrays of differently sized images; defaults to Fant)
} WIC_FLAGS;
typedef struct
{
size_t width;
size_t height;
DXGI_FORMAT format;
size_t rowPitch;
size_t slicePitch;
uint8_t *pixels;
} Image;
typedef enum
{
TEX_FR_ROTATE0 = 0x0,
TEX_FR_ROTATE90 = 0x1,
TEX_FR_ROTATE180 = 0x2,
TEX_FR_ROTATE270 = 0x3,
TEX_FR_FLIP_HORIZONTAL = 0x08,
TEX_FR_FLIP_VERTICAL = 0x10,
} TEX_FR_FLAGS;
typedef enum
{
TEX_FILTER_DEFAULT = 0,
TEX_FILTER_WRAP_U = 0x1,
TEX_FILTER_WRAP_V = 0x2,
TEX_FILTER_WRAP_W = 0x4,
TEX_FILTER_WRAP = (TEX_FILTER_WRAP_U | TEX_FILTER_WRAP_V | TEX_FILTER_WRAP_W),
TEX_FILTER_MIRROR_U = 0x10,
TEX_FILTER_MIRROR_V = 0x20,
TEX_FILTER_MIRROR_W = 0x40,
TEX_FILTER_MIRROR = (TEX_FILTER_MIRROR_U | TEX_FILTER_MIRROR_V | TEX_FILTER_MIRROR_W),
// Wrap vs. Mirror vs. Clamp filtering options
TEX_FILTER_SEPARATE_ALPHA = 0x100,
// Resize color and alpha channel independently
TEX_FILTER_FLOAT_X2BIAS = 0x200,
// Enable *2 - 1 conversion cases for unorm<->float and positive-only float formats
TEX_FILTER_RGB_COPY_RED = 0x1000,
TEX_FILTER_RGB_COPY_GREEN = 0x2000,
TEX_FILTER_RGB_COPY_BLUE = 0x4000,
TEX_FILTER_RGB_COPY_ALPHA = 0x8000,
// When converting RGB(A) to R, defaults to using grayscale. These flags indicate copying a specific channel instead
// When converting RGB(A) to RG, defaults to copying RED | GREEN. These flags control which channels are selected instead.
TEX_FILTER_DITHER = 0x10000,
// Use ordered 4x4 dithering for any required conversions
TEX_FILTER_DITHER_DIFFUSION = 0x20000,
// Use error-diffusion dithering for any required conversions
TEX_FILTER_POINT = 0x100000,
TEX_FILTER_LINEAR = 0x200000,
TEX_FILTER_CUBIC = 0x300000,
TEX_FILTER_BOX = 0x400000,
TEX_FILTER_FANT = 0x400000, // Equiv to Box filtering for mipmap generation
TEX_FILTER_TRIANGLE = 0x500000,
// Filtering mode to use for any required image resizing
TEX_FILTER_SRGB_IN = 0x1000000,
TEX_FILTER_SRGB_OUT = 0x2000000,
TEX_FILTER_SRGB = (TEX_FILTER_SRGB_IN | TEX_FILTER_SRGB_OUT),
// sRGB <-> RGB for use in conversion operations
// if the input format type is IsSRGB(), then SRGB_IN is on by default
// if the output format type is IsSRGB(), then SRGB_OUT is on by default
TEX_FILTER_FORCE_NON_WIC = 0x10000000,
// Forces use of the non-WIC path when both are an option
TEX_FILTER_FORCE_WIC = 0x20000000,
// Forces use of the WIC path even when logic would have picked a non-WIC path when both are an option
} TEX_FILTER_FLAGS;
typedef enum
{
TEX_PMALPHA_DEFAULT = 0,
TEX_PMALPHA_IGNORE_SRGB = 0x1,
// ignores sRGB colorspace conversions
TEX_PMALPHA_REVERSE = 0x2,
// converts from premultiplied alpha back to straight alpha
TEX_PMALPHA_SRGB_IN = 0x1000000,
TEX_PMALPHA_SRGB_OUT = 0x2000000,
TEX_PMALPHA_SRGB = (TEX_PMALPHA_SRGB_IN | TEX_PMALPHA_SRGB_OUT),
// if the input format type is IsSRGB(), then SRGB_IN is on by default
// if the output format type is IsSRGB(), then SRGB_OUT is on by default
} TEX_PMALPHA_FLAGS;
typedef enum
{
TEX_COMPRESS_DEFAULT = 0,
TEX_COMPRESS_RGB_DITHER = 0x10000,
// Enables dithering RGB colors for BC1-3 compression
TEX_COMPRESS_A_DITHER = 0x20000,
// Enables dithering alpha for BC1-3 compression
TEX_COMPRESS_DITHER = 0x30000,
// Enables both RGB and alpha dithering for BC1-3 compression
TEX_COMPRESS_UNIFORM = 0x40000,
// Uniform color weighting for BC1-3 compression; by default uses perceptual weighting
TEX_COMPRESS_BC7_USE_3SUBSETS = 0x80000,
// Enables exhaustive search for BC7 compress for mode 0 and 2; by default skips trying these modes
TEX_COMPRESS_BC7_QUICK = 0x100000,
// Minimal modes (usually mode 6) for BC7 compression
TEX_COMPRESS_SRGB_IN = 0x1000000,
TEX_COMPRESS_SRGB_OUT = 0x2000000,
TEX_COMPRESS_SRGB = (TEX_COMPRESS_SRGB_IN | TEX_COMPRESS_SRGB_OUT),
// if the input format type is IsSRGB(), then SRGB_IN is on by default
// if the output format type is IsSRGB(), then SRGB_OUT is on by default
TEX_COMPRESS_PARALLEL = 0x10000000,
// Compress is free to use multithreading to improve performance (by default it does not use multithreading)
} TEX_COMPRESS_FLAGS;
typedef enum
{
CNMAP_DEFAULT = 0,
CNMAP_CHANNEL_RED = 0x1,
CNMAP_CHANNEL_GREEN = 0x2,
CNMAP_CHANNEL_BLUE = 0x3,
CNMAP_CHANNEL_ALPHA = 0x4,
CNMAP_CHANNEL_LUMINANCE = 0x5,
// Channel selection when evaluting color value for height
// Luminance is a combination of red, green, and blue
CNMAP_MIRROR_U = 0x1000,
CNMAP_MIRROR_V = 0x2000,
CNMAP_MIRROR = 0x3000,
// Use mirror semantics for scanline references (defaults to wrap)
CNMAP_INVERT_SIGN = 0x4000,
// Inverts normal sign
CNMAP_COMPUTE_OCCLUSION = 0x8000,
// Computes a crude occlusion term stored in the alpha channel
} CNMAP_FLAGS;
typedef struct
{
size_t x;
size_t y;
size_t w;
size_t h;
} Rect;
typedef enum
{
CMSE_DEFAULT = 0,
CMSE_IMAGE1_SRGB = 0x1,
CMSE_IMAGE2_SRGB = 0x2,
// Indicates that image needs gamma correction before comparision
CMSE_IGNORE_RED = 0x10,
CMSE_IGNORE_GREEN = 0x20,
CMSE_IGNORE_BLUE = 0x40,
CMSE_IGNORE_ALPHA = 0x80,
// Ignore the channel when computing MSE
CMSE_IMAGE1_X2_BIAS = 0x100,
CMSE_IMAGE2_X2_BIAS = 0x200,
// Indicates that image should be scaled and biased before comparison (i.e. UNORM -> SNORM)
} CMSE_FLAGS;
typedef enum
{
WIC_CODEC_BMP = 1, // Windows Bitmap (.bmp)
WIC_CODEC_JPEG, // Joint Photographic Experts Group (.jpg, .jpeg)
WIC_CODEC_PNG, // Portable Network Graphics (.png)
WIC_CODEC_TIFF, // Tagged Image File Format (.tif, .tiff)
WIC_CODEC_GIF, // Graphics Interchange Format (.gif)
WIC_CODEC_WMP, // Windows Media Photo / HD Photo / JPEG XR (.hdp, .jxr, .wdp)
WIC_CODEC_ICO, // Windows Icon (.ico)
WIC_CODEC_HEIF, // High Efficiency Image File (.heif, .heic)
} WICCodecs;
typedef enum
{
CREATETEX_DEFAULT = 0,
CREATETEX_FORCE_SRGB = 0x1,
CREATETEX_IGNORE_SRGB = 0x2,
} CREATETEX_FLAGS;
namespace DirectX
{
#ifdef _WIN32
typedef void(__cdecl *SetCustomProps)(IPropertyBag2 *pBag);
typedef void(__cdecl *GetMQR)(IWICMetadataQueryReader *qMqr);
#endif
typedef void(__cdecl *EvaluateImageFunc)(const DirectX::XMVECTOR *pixels, size_t width, size_t y);
typedef void(__cdecl *TransformImageFunc)(DirectX::XMVECTOR *outPixels, const DirectX::XMVECTOR *inPixels, size_t width, size_t y);
typedef enum
{
FORMAT_TYPE_TYPELESS,
FORMAT_TYPE_FLOAT,
FORMAT_TYPE_UNORM,
FORMAT_TYPE_SNORM,
FORMAT_TYPE_UINT,
FORMAT_TYPE_SINT,
} FORMAT_TYPE;
typedef enum
{
CP_FLAGS_NONE = 0x0,
// Normal operation
CP_FLAGS_LEGACY_DWORD = 0x1,
// Assume pitch is DWORD aligned instead of BYTE aligned
CP_FLAGS_PARAGRAPH = 0x2,
// Assume pitch is 16-byte aligned instead of BYTE aligned
CP_FLAGS_YMM = 0x4,
// Assume pitch is 32-byte aligned instead of BYTE aligned
CP_FLAGS_ZMM = 0x8,
// Assume pitch is 64-byte aligned instead of BYTE aligned
CP_FLAGS_PAGE4K = 0x200,
// Assume pitch is 4096-byte aligned instead of BYTE aligned
CP_FLAGS_BAD_DXTN_TAILS = 0x1000,
// BC formats with malformed mipchain blocks smaller than 4x4
CP_FLAGS_24BPP = 0x10000,
// Override with a legacy 24 bits-per-pixel format size
CP_FLAGS_16BPP = 0x20000,
// Override with a legacy 16 bits-per-pixel format size
CP_FLAGS_8BPP = 0x40000,
// Override with a legacy 8 bits-per-pixel format size
} CP_FLAGS;
typedef enum
{
TEX_DIMENSION_TEXTURE1D = 2,
TEX_DIMENSION_TEXTURE2D = 3,
TEX_DIMENSION_TEXTURE3D = 4,
} TEX_DIMENSION;
// Subset here matches D3D10_RESOURCE_MISC_FLAG and D3D11_RESOURCE_MISC_FLAG
typedef enum
{
TEX_MISC_TEXTURECUBE = 0x4L,
} TEX_MISC_FLAG;
typedef enum
{
TEX_MISC2_ALPHA_MODE_MASK = 0x7L,
} TEX_MISC_FLAG2;
// Matches DDS_ALPHA_MODE, encoded in MISC_FLAGS2
typedef enum
{
TEX_ALPHA_MODE_UNKNOWN = 0,
TEX_ALPHA_MODE_STRAIGHT = 1,
TEX_ALPHA_MODE_PREMULTIPLIED = 2,
TEX_ALPHA_MODE_OPAQUE = 3,
TEX_ALPHA_MODE_CUSTOM = 4,
} TEX_ALPHA_MODE;
typedef struct
{
size_t width;
size_t height; // Should be 1 for 1D textures
size_t depth; // Should be 1 for 1D or 2D textures
size_t arraySize; // For cubemap, this is a multiple of 6
size_t mipLevels;
uint32_t miscFlags;
uint32_t miscFlags2;
DXGI_FORMAT format;
TEX_DIMENSION dimension;
} TexMetadata;
typedef enum
{
DDS_FLAGS_NONE = 0x0,
DDS_FLAGS_LEGACY_DWORD = 0x1,
// Assume pitch is DWORD aligned instead of BYTE aligned (used by some legacy DDS files)
DDS_FLAGS_NO_LEGACY_EXPANSION = 0x2,
// Do not implicitly convert legacy formats that result in larger pixel sizes (24 bpp, 3:3:2, A8L8, A4L4, P8, A8P8)
DDS_FLAGS_NO_R10B10G10A2_FIXUP = 0x4,
// Do not use work-around for long-standing D3DX DDS file format issue which reversed the 10:10:10:2 color order masks
DDS_FLAGS_FORCE_RGB = 0x8,
// Convert DXGI 1.1 BGR formats to DXGI_FORMAT_R8G8B8A8_UNORM to avoid use of optional WDDM 1.1 formats
DDS_FLAGS_NO_16BPP = 0x10,
// Conversions avoid use of 565, 5551, and 4444 formats and instead expand to 8888 to avoid use of optional WDDM 1.2 formats
DDS_FLAGS_EXPAND_LUMINANCE = 0x20,
// When loading legacy luminance formats expand replicating the color channels rather than leaving them packed (L8, L16, A8L8)
DDS_FLAGS_BAD_DXTN_TAILS = 0x40,
// Some older DXTn DDS files incorrectly handle mipchain tails for blocks smaller than 4x4
DDS_FLAGS_FORCE_DX10_EXT = 0x10000,
// Always use the 'DX10' header extension for DDS writer (i.e. don't try to write DX9 compatible DDS files)
DDS_FLAGS_FORCE_DX10_EXT_MISC2 = 0x20000,
// DDS_FLAGS_FORCE_DX10_EXT including miscFlags2 information (result may not be compatible with D3DX10 or D3DX11)
DDS_FLAGS_FORCE_DX9_LEGACY = 0x40000,
// Force use of legacy header for DDS writer (will fail if unable to write as such)
DDS_FLAGS_ALLOW_LARGE_FILES = 0x1000000,
// Enables the loader to read large dimension .dds files (i.e. greater than known hardware requirements)
} DDS_FLAGS;
typedef enum
{
TGA_FLAGS_NONE = 0x0,
TGA_FLAGS_BGR = 0x1,
// 24bpp files are returned as BGRX; 32bpp files are returned as BGRA
TGA_FLAGS_ALLOW_ALL_ZERO_ALPHA = 0x2,
// If the loaded image has an all zero alpha channel, normally we assume it should be opaque. This flag leaves it alone.
TGA_FLAGS_IGNORE_SRGB = 0x10,
// Ignores sRGB TGA 2.0 metadata if present in the file
TGA_FLAGS_FORCE_SRGB = 0x20,
// Writes sRGB metadata into the file reguardless of format (TGA 2.0 only)
TGA_FLAGS_FORCE_LINEAR = 0x40,
// Writes linear gamma metadata into the file reguardless of format (TGA 2.0 only)
TGA_FLAGS_DEFAULT_SRGB = 0x80,
// If no colorspace is specified in TGA 2.0 metadata, assume sRGB
} TGA_FLAGS;
typedef enum
{
WIC_FLAGS_NONE = 0x0,
WIC_FLAGS_FORCE_RGB = 0x1,
// Loads DXGI 1.1 BGR formats as DXGI_FORMAT_R8G8B8A8_UNORM to avoid use of optional WDDM 1.1 formats
WIC_FLAGS_NO_X2_BIAS = 0x2,
// Loads DXGI 1.1 X2 10:10:10:2 format as DXGI_FORMAT_R10G10B10A2_UNORM
WIC_FLAGS_NO_16BPP = 0x4,
// Loads 565, 5551, and 4444 formats as 8888 to avoid use of optional WDDM 1.2 formats
WIC_FLAGS_ALLOW_MONO = 0x8,
// Loads 1-bit monochrome (black & white) as R1_UNORM rather than 8-bit grayscale
WIC_FLAGS_ALL_FRAMES = 0x10,
// Loads all images in a multi-frame file, converting/resizing to match the first frame as needed, defaults to 0th frame otherwise
WIC_FLAGS_IGNORE_SRGB = 0x20,
// Ignores sRGB metadata if present in the file
WIC_FLAGS_FORCE_SRGB = 0x40,
// Writes sRGB metadata into the file reguardless of format
WIC_FLAGS_FORCE_LINEAR = 0x80,
// Writes linear gamma metadata into the file reguardless of format
WIC_FLAGS_DEFAULT_SRGB = 0x100,
// If no colorspace is specified, assume sRGB
WIC_FLAGS_DITHER = 0x10000,
// Use ordered 4x4 dithering for any required conversions
WIC_FLAGS_DITHER_DIFFUSION = 0x20000,
// Use error-diffusion dithering for any required conversions
WIC_FLAGS_FILTER_POINT = 0x100000,
WIC_FLAGS_FILTER_LINEAR = 0x200000,
WIC_FLAGS_FILTER_CUBIC = 0x300000,
WIC_FLAGS_FILTER_FANT = 0x400000, // Combination of Linear and Box filter
// Filtering mode to use for any required image resizing (only needed when loading arrays of differently sized images; defaults to Fant)
} WIC_FLAGS;
typedef struct
{
size_t width;
size_t height;
DXGI_FORMAT format;
size_t rowPitch;
size_t slicePitch;
uint8_t *pixels;
} Image;
typedef enum
{
TEX_FR_ROTATE0 = 0x0,
TEX_FR_ROTATE90 = 0x1,
TEX_FR_ROTATE180 = 0x2,
TEX_FR_ROTATE270 = 0x3,
TEX_FR_FLIP_HORIZONTAL = 0x08,
TEX_FR_FLIP_VERTICAL = 0x10,
} TEX_FR_FLAGS;
typedef enum
{
TEX_FILTER_DEFAULT = 0,
TEX_FILTER_WRAP_U = 0x1,
TEX_FILTER_WRAP_V = 0x2,
TEX_FILTER_WRAP_W = 0x4,
TEX_FILTER_WRAP = (TEX_FILTER_WRAP_U | TEX_FILTER_WRAP_V | TEX_FILTER_WRAP_W),
TEX_FILTER_MIRROR_U = 0x10,
TEX_FILTER_MIRROR_V = 0x20,
TEX_FILTER_MIRROR_W = 0x40,
TEX_FILTER_MIRROR = (TEX_FILTER_MIRROR_U | TEX_FILTER_MIRROR_V | TEX_FILTER_MIRROR_W),
// Wrap vs. Mirror vs. Clamp filtering options
TEX_FILTER_SEPARATE_ALPHA = 0x100,
// Resize color and alpha channel independently
TEX_FILTER_FLOAT_X2BIAS = 0x200,
// Enable *2 - 1 conversion cases for unorm<->float and positive-only float formats
TEX_FILTER_RGB_COPY_RED = 0x1000,
TEX_FILTER_RGB_COPY_GREEN = 0x2000,
TEX_FILTER_RGB_COPY_BLUE = 0x4000,
TEX_FILTER_RGB_COPY_ALPHA = 0x8000,
// When converting RGB(A) to R, defaults to using grayscale. These flags indicate copying a specific channel instead
// When converting RGB(A) to RG, defaults to copying RED | GREEN. These flags control which channels are selected instead.
TEX_FILTER_DITHER = 0x10000,
// Use ordered 4x4 dithering for any required conversions
TEX_FILTER_DITHER_DIFFUSION = 0x20000,
// Use error-diffusion dithering for any required conversions
TEX_FILTER_POINT = 0x100000,
TEX_FILTER_LINEAR = 0x200000,
TEX_FILTER_CUBIC = 0x300000,
TEX_FILTER_BOX = 0x400000,
TEX_FILTER_FANT = 0x400000, // Equiv to Box filtering for mipmap generation
TEX_FILTER_TRIANGLE = 0x500000,
// Filtering mode to use for any required image resizing
TEX_FILTER_SRGB_IN = 0x1000000,
TEX_FILTER_SRGB_OUT = 0x2000000,
TEX_FILTER_SRGB = (TEX_FILTER_SRGB_IN | TEX_FILTER_SRGB_OUT),
// sRGB <-> RGB for use in conversion operations
// if the input format type is IsSRGB(), then SRGB_IN is on by default
// if the output format type is IsSRGB(), then SRGB_OUT is on by default
TEX_FILTER_FORCE_NON_WIC = 0x10000000,
// Forces use of the non-WIC path when both are an option
TEX_FILTER_FORCE_WIC = 0x20000000,
// Forces use of the WIC path even when logic would have picked a non-WIC path when both are an option
} TEX_FILTER_FLAGS;
typedef enum
{
TEX_PMALPHA_DEFAULT = 0,
TEX_PMALPHA_IGNORE_SRGB = 0x1,
// ignores sRGB colorspace conversions
TEX_PMALPHA_REVERSE = 0x2,
// converts from premultiplied alpha back to straight alpha
TEX_PMALPHA_SRGB_IN = 0x1000000,
TEX_PMALPHA_SRGB_OUT = 0x2000000,
TEX_PMALPHA_SRGB = (TEX_PMALPHA_SRGB_IN | TEX_PMALPHA_SRGB_OUT),
// if the input format type is IsSRGB(), then SRGB_IN is on by default
// if the output format type is IsSRGB(), then SRGB_OUT is on by default
} TEX_PMALPHA_FLAGS;
typedef enum
{
TEX_COMPRESS_DEFAULT = 0,
TEX_COMPRESS_RGB_DITHER = 0x10000,
// Enables dithering RGB colors for BC1-3 compression
TEX_COMPRESS_A_DITHER = 0x20000,
// Enables dithering alpha for BC1-3 compression
TEX_COMPRESS_DITHER = 0x30000,
// Enables both RGB and alpha dithering for BC1-3 compression
TEX_COMPRESS_UNIFORM = 0x40000,
// Uniform color weighting for BC1-3 compression; by default uses perceptual weighting
TEX_COMPRESS_BC7_USE_3SUBSETS = 0x80000,
// Enables exhaustive search for BC7 compress for mode 0 and 2; by default skips trying these modes
TEX_COMPRESS_BC7_QUICK = 0x100000,
// Minimal modes (usually mode 6) for BC7 compression
TEX_COMPRESS_SRGB_IN = 0x1000000,
TEX_COMPRESS_SRGB_OUT = 0x2000000,
TEX_COMPRESS_SRGB = (TEX_COMPRESS_SRGB_IN | TEX_COMPRESS_SRGB_OUT),
// if the input format type is IsSRGB(), then SRGB_IN is on by default
// if the output format type is IsSRGB(), then SRGB_OUT is on by default
TEX_COMPRESS_PARALLEL = 0x10000000,
// Compress is free to use multithreading to improve performance (by default it does not use multithreading)
} TEX_COMPRESS_FLAGS;
typedef enum
{
CNMAP_DEFAULT = 0,
CNMAP_CHANNEL_RED = 0x1,
CNMAP_CHANNEL_GREEN = 0x2,
CNMAP_CHANNEL_BLUE = 0x3,
CNMAP_CHANNEL_ALPHA = 0x4,
CNMAP_CHANNEL_LUMINANCE = 0x5,
// Channel selection when evaluting color value for height
// Luminance is a combination of red, green, and blue
CNMAP_MIRROR_U = 0x1000,
CNMAP_MIRROR_V = 0x2000,
CNMAP_MIRROR = 0x3000,
// Use mirror semantics for scanline references (defaults to wrap)
CNMAP_INVERT_SIGN = 0x4000,
// Inverts normal sign
CNMAP_COMPUTE_OCCLUSION = 0x8000,
// Computes a crude occlusion term stored in the alpha channel
} CNMAP_FLAGS;
typedef struct
{
size_t x;
size_t y;
size_t w;
size_t h;
} Rect;
typedef enum
{
CMSE_DEFAULT = 0,
CMSE_IMAGE1_SRGB = 0x1,
CMSE_IMAGE2_SRGB = 0x2,
// Indicates that image needs gamma correction before comparision
CMSE_IGNORE_RED = 0x10,
CMSE_IGNORE_GREEN = 0x20,
CMSE_IGNORE_BLUE = 0x40,
CMSE_IGNORE_ALPHA = 0x80,
// Ignore the channel when computing MSE
CMSE_IMAGE1_X2_BIAS = 0x100,
CMSE_IMAGE2_X2_BIAS = 0x200,
// Indicates that image should be scaled and biased before comparison (i.e. UNORM -> SNORM)
} CMSE_FLAGS;
typedef enum
{
WIC_CODEC_BMP = 1, // Windows Bitmap (.bmp)
WIC_CODEC_JPEG, // Joint Photographic Experts Group (.jpg, .jpeg)
WIC_CODEC_PNG, // Portable Network Graphics (.png)
WIC_CODEC_TIFF, // Tagged Image File Format (.tif, .tiff)
WIC_CODEC_GIF, // Graphics Interchange Format (.gif)
WIC_CODEC_WMP, // Windows Media Photo / HD Photo / JPEG XR (.hdp, .jxr, .wdp)
WIC_CODEC_ICO, // Windows Icon (.ico)
WIC_CODEC_HEIF, // High Efficiency Image File (.heif, .heic)
} WICCodecs;
typedef enum
{
CREATETEX_DEFAULT = 0,
CREATETEX_FORCE_SRGB = 0x1,
CREATETEX_IGNORE_SRGB = 0x2,
} CREATETEX_FLAGS;
} // namespace DirectX
#else
#include "DirectXTex/DirectXTex/DirectXTex.h"
#include "DirectXTex/Auxiliary/DirectXTexPNG.h"
#include "DirectXTex/Auxiliary/DirectXTexJPEG.h"
#include "DirectXTex/Auxiliary/DirectXTexEXR.h"
typedef struct
{
DirectX::ScratchImage *image;
} ScratchImageT;
typedef struct
{
DirectX::Blob *blob;
} BlobT;
#endif
typedef unsigned short DXTexWChar;
#if defined(_WIN32) || defined(__CYGWIN__)
#define API __declspec(dllexport)
#elif defined(__linux__) || defined(__APPLE__)
#define API __attribute__((visibility("default")))
#else
#define API
#pragma warning Unknown dynamic link import / export semantics.
#endif
#ifdef __cplusplus
extern "C"
{
#endif
#ifdef _WIN32
typedef void(__cdecl *SetCustomProps)(IPropertyBag2 *pBag);
typedef void(__cdecl *GetMQR)(IWICMetadataQueryReader *qMqr);
#endif
typedef void(__cdecl *EvaluateImageFunc)(_In_reads_(width) const DirectX::XMVECTOR *pixels, size_t width, size_t y);
typedef void(__cdecl *TransformImageFunc)(_Out_writes_(width) DirectX::XMVECTOR *outPixels, _In_reads_(width) const DirectX::XMVECTOR *inPixels, size_t width, size_t y);
#pragma region IPropertyBag2 methods
#ifdef _WIN32
API HRESULT Read(IPropertyBag2 *p, _In_ ULONG cProperties, __RPC__in_ecount_full(cProperties) PROPBAG2 *pPropBag, __RPC__in_opt IErrorLog *pErrLog, __RPC__out_ecount_full(cProperties) VARIANT *pvarValue, __RPC__inout_ecount_full_opt(cProperties) HRESULT *phrError);
API HRESULT Write(IPropertyBag2 *p, _In_ ULONG cProperties, __RPC__in_ecount_full(cProperties) PROPBAG2 *pPropBag, __RPC__in_ecount_full(cProperties) VARIANT *pvarValue);
API HRESULT CountProperties(IPropertyBag2 *p, __RPC__out ULONG *pcProperties);
API HRESULT GetPropertyInfo(IPropertyBag2 *p, _In_ ULONG iProperty, _In_ ULONG cProperties, __RPC__out_ecount_full(cProperties) PROPBAG2 *pPropBag, __RPC__out ULONG *pcProperties);
API HRESULT LoadObject(IPropertyBag2 *p, __RPC__in LPCOLESTR pstrName, _In_ DWORD dwHint, __RPC__in_opt IUnknown *pUnkObject, __RPC__in_opt IErrorLog *pErrLog);
#endif
#pragma endregion
#pragma region IWICMetadataQueryReader methods
#ifdef _WIN32
API HRESULT GetContainerFormat(IWICMetadataQueryReader *p, __RPC__out GUID *pguidContainerFormat);
API HRESULT GetLocation(IWICMetadataQueryReader *p, _In_ UINT cchMaxLength, __RPC__inout_ecount_full_opt(cchMaxLength) WCHAR *wzNamespace, __RPC__out UINT *pcchActualLength);
API HRESULT GetMetadataByName(IWICMetadataQueryReader *p, __RPC__in LPCWSTR wzName, __RPC__inout_opt PROPVARIANT *pvarValue);
API HRESULT GetEnumerator(IWICMetadataQueryReader *p, __RPC__deref_out_opt IEnumString **ppIEnumString);
#endif
#pragma endregion
#pragma region DXGI Format Utilities
API bool IsValid(_In_ DXGI_FORMAT fmt) noexcept;
API bool IsCompressed(_In_ DXGI_FORMAT fmt) noexcept;
API bool IsPacked(_In_ DXGI_FORMAT fmt) noexcept;
API bool IsVideo(_In_ DXGI_FORMAT fmt) noexcept;
API bool IsPlanar(_In_ DXGI_FORMAT fmt) noexcept;
API bool IsPalettized(_In_ DXGI_FORMAT fmt) noexcept;
API bool IsDepthStencil(_In_ DXGI_FORMAT fmt) noexcept;
API bool IsSRGB(_In_ DXGI_FORMAT fmt) noexcept;
API bool IsTypeless(_In_ DXGI_FORMAT fmt, _In_ bool partialTypeless) noexcept;
API bool HasAlpha(_In_ DXGI_FORMAT fmt) noexcept;
API size_t BitsPerPixel(_In_ DXGI_FORMAT fmt) noexcept;
API size_t BitsPerColor(_In_ DXGI_FORMAT fmt) noexcept;
API DirectX::FORMAT_TYPE FormatDataType(_In_ DXGI_FORMAT fmt) noexcept;
API HRESULT ComputePitch(_In_ DXGI_FORMAT fmt, _In_ size_t width, _In_ size_t height, _Out_ size_t &rowPitch, _Out_ size_t &slicePitch, _In_ DirectX::CP_FLAGS flags) noexcept;
API size_t ComputeScanlines(_In_ DXGI_FORMAT fmt, _In_ size_t height) noexcept;
API DXGI_FORMAT MakeSRGB(_In_ DXGI_FORMAT fmt) noexcept;
API DXGI_FORMAT MakeTypeless(_In_ DXGI_FORMAT fmt) noexcept;
API DXGI_FORMAT MakeTypelessUNORM(_In_ DXGI_FORMAT fmt) noexcept;
API DXGI_FORMAT MakeTypelessFLOAT(_In_ DXGI_FORMAT fmt) noexcept;
#pragma endregion
#pragma region MetadataIO
API HRESULT GetMetadataFromDDSMemory(
_In_reads_bytes_(size) const void *pSource, _In_ size_t size,
_In_ DirectX::DDS_FLAGS flags,
_Out_ DirectX::TexMetadata &metadata) noexcept;
API HRESULT GetMetadataFromDDSFile(
_In_z_ const DXTexWChar *szFile,
_In_ DirectX::DDS_FLAGS flags,
_Out_ DirectX::TexMetadata &metadata) noexcept;
API HRESULT GetMetadataFromHDRMemory(
_In_reads_bytes_(size) const void *pSource, _In_ size_t size,
_Out_ DirectX::TexMetadata &metadata) noexcept;
API HRESULT GetMetadataFromHDRFile(
_In_z_ const DXTexWChar *szFile,
_Out_ DirectX::TexMetadata &metadata) noexcept;
API HRESULT GetMetadataFromTGAMemory(
_In_reads_bytes_(size) const void *pSource, _In_ size_t size,
_In_ DirectX::TGA_FLAGS flags,
_Out_ DirectX::TexMetadata &metadata) noexcept;
API HRESULT GetMetadataFromTGAFile(
_In_z_ const DXTexWChar *szFile,
_In_ DirectX::TGA_FLAGS flags,
_Out_ DirectX::TexMetadata &metadata) noexcept;
// PNG operations
API HRESULT GetMetadataFromPNGFile(const DXTexWChar *szfile, DirectX::TexMetadata &metadata) noexcept;
// JPEG operations
API HRESULT GetMetadataFromJPEGFile(const DXTexWChar *szfile, DirectX::TexMetadata &metadata) noexcept;
// EXR operations
API HRESULT GetMetadataFromEXRFile(const DXTexWChar *szfile, DirectX::TexMetadata &metadata) noexcept;
#ifdef _WIN32
API HRESULT GetMetadataFromWICMemory(
_In_reads_bytes_(size) const void *pSource, _In_ size_t size,
_In_ DirectX::WIC_FLAGS flags,
_Out_ DirectX::TexMetadata &metadata);
API HRESULT GetMetadataFromWICFile(
_In_z_ const DXTexWChar *szFile,
_In_ DirectX::WIC_FLAGS flags,
_Out_ DirectX::TexMetadata &metadata);
#endif
// Compatability helpers
API HRESULT GetMetadataFromTGAMemory2(
_In_reads_bytes_(size) const void *pSource, _In_ size_t size,
_Out_ DirectX::TexMetadata &metadata) noexcept;
API HRESULT GetMetadataFromTGAFile2(
_In_z_ const DXTexWChar *szFile,
_Out_ DirectX::TexMetadata &metadata) noexcept;
#pragma endregion
#pragma region TexMetadata Methods
API size_t ComputeIndex(DirectX::TexMetadata *metadata, _In_ size_t mip, _In_ size_t item, _In_ size_t slice) noexcept;
// Returns size_t(-1) to indicate an out-of-range error
API bool IsCubemap(DirectX::TexMetadata *metadata) noexcept;
// Helper for miscFlags
API bool IsPMAlpha(DirectX::TexMetadata *metadata) noexcept;
API void SetAlphaMode(DirectX::TexMetadata *metadata, DirectX::TEX_ALPHA_MODE mode) noexcept;
API DirectX::TEX_ALPHA_MODE GetAlphaMode(DirectX::TexMetadata *metadata) noexcept;
// Helpers for miscFlags2
API bool IsVolumemap(DirectX::TexMetadata *metadata) noexcept;
// Helper for dimension
#pragma endregion
#pragma region ScratchImage Methods
API ScratchImageT CreateScratchImage();
API HRESULT Initialize(ScratchImageT img, _In_ const DirectX::TexMetadata &mdata, _In_ DirectX::CP_FLAGS flags) noexcept;