MCPcopy Create free account
hub / github.com/axmolengine/axmol / initWithS3TCData

Method initWithS3TCData

core/platform/Image.cpp:2222–2347  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2220}
2221
2222bool Image::initWithS3TCData(uint8_t* data, ssize_t dataLen, bool ownData)
2223{
2224 const uint32_t FOURCC_DXT1 = makeFourCC('D', 'X', 'T', '1');
2225 const uint32_t FOURCC_DXT3 = makeFourCC('D', 'X', 'T', '3');
2226 const uint32_t FOURCC_DXT5 = makeFourCC('D', 'X', 'T', '5');
2227
2228 /* load the .dds file */
2229
2230 S3TCTexHeader* header = (S3TCTexHeader*)data;
2231 _width = header->ddsd.width;
2232 _height = header->ddsd.height;
2233 _numberOfMipmaps = MAX(
2234 1,
2235 header->ddsd.DUMMYUNIONNAMEN2
2236 .mipMapCount); // if dds header reports 0 mipmaps, set to 1 to force correct software decoding (if needed).
2237 _dataLen = 0;
2238 int blockSize = (FOURCC_DXT1 == header->ddsd.DUMMYUNIONNAMEN4.ddpfPixelFormat.fourCC) ? 8 : 16;
2239
2240 /* calculate the dataLen */
2241
2242 int width = _width;
2243 int height = _height;
2244
2245 const int pixelOffset = sizeof(S3TCTexHeader);
2246 uint8_t* pixelData = data + pixelOffset;
2247
2248 bool hardware = Configuration::getInstance()->supportsS3TC();
2249 /* if hardware supports s3tc, set pixelformat before loading mipmaps, to support non-mipmapped textures */
2250 if (hardware)
2251 { // decode texture through hardware
2252
2253 if (FOURCC_DXT1 == header->ddsd.DUMMYUNIONNAMEN4.ddpfPixelFormat.fourCC)
2254 {
2255 _pixelFormat = backend::PixelFormat::S3TC_DXT1;
2256 }
2257 else if (FOURCC_DXT3 == header->ddsd.DUMMYUNIONNAMEN4.ddpfPixelFormat.fourCC)
2258 {
2259 _pixelFormat = backend::PixelFormat::S3TC_DXT3;
2260 }
2261 else if (FOURCC_DXT5 == header->ddsd.DUMMYUNIONNAMEN4.ddpfPixelFormat.fourCC)
2262 {
2263 _pixelFormat = backend::PixelFormat::S3TC_DXT5;
2264 }
2265 }
2266 else
2267 { // will software decode
2268 _pixelFormat = backend::PixelFormat::RGBA8;
2269
2270 // prepare data for software decompress
2271 for (int i = 0; i < _numberOfMipmaps && (width || height); ++i)
2272 {
2273 if (width == 0)
2274 width = 1;
2275 if (height == 0)
2276 height = 1;
2277
2278 _dataLen += (height * width * 4);
2279

Callers

nothing calls this directly

Calls 4

makeFourCCFunction · 0.85
getInstanceFunction · 0.85
s3tc_decodeFunction · 0.85
supportsS3TCMethod · 0.80

Tested by

no test coverage detected