MCPcopy Create free account
hub / github.com/DentonW/DevIL / ILAPIENTRY ilSquishCompressDXT

Function ILAPIENTRY ilSquishCompressDXT

DevIL/src-IL/src/il_squish.cpp:37–80  ·  view source on GitHub ↗

Compresses data to a DXT format using libsquish. The data must be in unsigned byte RGBA format. The alpha channel will be ignored if DxtType is IL_DXT1. DxtSize is used to return the size in bytes of the DXTC data returned.

Source from the content-addressed store, hash-verified

35// The data must be in unsigned byte RGBA format. The alpha channel will be ignored if DxtType is IL_DXT1.
36// DxtSize is used to return the size in bytes of the DXTC data returned.
37ILAPI ILubyte* ILAPIENTRY ilSquishCompressDXT(ILubyte *Data, ILuint Width, ILuint Height, ILuint Depth, ILenum DxtFormat, ILuint *DxtSize)
38{
39 ILuint Size; //@TODO: Support larger than 32-bit data?
40 ILint Flags;
41 ILubyte *DxtcData;
42
43 if (Data == NULL) { // We cannot operate on a null pointer.
44 ilSetError(IL_INVALID_PARAM);
45 return NULL;
46 }
47
48 // The nVidia Texture Tools library does not support volume textures yet.
49 if (Depth != 1) {
50 ilSetError(IL_INVALID_PARAM);
51 return NULL;
52 }
53
54 switch (DxtFormat)
55 {
56 case IL_DXT1: // Should these two be
57 case IL_DXT1A: // any different?
58 Flags = squish::kDxt1;
59 break;
60 case IL_DXT3:
61 Flags = squish::kDxt3;
62 break;
63 case IL_DXT5:
64 Flags = squish::kDxt5;
65 break;
66 default: // Does not support DXT2 or DXT4.
67 ilSetError(IL_INVALID_PARAM);
68 break;
69 }
70
71 Size = squish::GetStorageRequirements(Width, Height, Flags);
72 DxtcData = (ILubyte*)ialloc(Size);
73 if (DxtcData == NULL)
74 return NULL;
75
76 squish::CompressImage(Data, Width, Height, DxtcData, Flags);
77
78 *DxtSize = Size;
79 return DxtcData;
80}
81
82#else
83// Let's have this so that the function is always created and exported, even if it does nothing.

Callers

nothing calls this directly

Calls 1

ilSetErrorFunction · 0.85

Tested by

no test coverage detected