File: TextureLoaderPkm.cpp

package info (click to toggle)
jazz2-native 3.5.0-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 16,912 kB
  • sloc: cpp: 172,557; xml: 113; python: 36; makefile: 5; sh: 2
file content (43 lines) | stat: -rw-r--r-- 1,166 bytes parent folder | download
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
#include "TextureLoaderPkm.h"

#if defined(DEATH_TARGET_ANDROID) && defined(WITH_OPENGLES)

#include <cstring>

#include <Base/Memory.h>

using namespace Death::IO;
using namespace Death::Memory;

namespace nCine
{
	TextureLoaderPkm::TextureLoaderPkm(std::unique_ptr<Stream> fileHandle)
		: ITextureLoader(std::move(fileHandle))
	{
		if (!fileHandle_->IsValid()) {
			return;
		}

		PkmHeader header;
		fileHandle_->Read(&header, 16); // PKM header is 16 bytes long

		// Checking for the header presence
		DEATH_ASSERT(AsBE(header.magicId) == 0x504B4D20 /* "PKM 10" */, "Invalid PKM signature", );
		DEATH_ASSERT(AsBE(header.version) == 0x3130 /* "10" */, ("PKM version not supported: 0x{:.4x}", header.version), );
		DEATH_ASSERT(AsBE(header.dataType) == 0, ("PKM data type not supported: 0x{:.4x}", header.dataType), );

		headerSize_ = 16;
		width_ = AsBE(header.width);
		height_ = AsBE(header.height);

		const int extWidth = AsBE(header.extendedWidth);
		const int extHeight = AsBE(header.extendedHeight);

		LOGI("Header found: w:{} h:{}, xw:{} xh:{}", width_, height_, extWidth, extHeight);

		loadPixels(GL_ETC1_RGB8_OES);
		hasLoaded_ = true;
	}
}

#endif