summaryrefslogtreecommitdiff
path: root/lyt/materials/texmap.cpp
blob: 1bb416b2143968d13bdf0cfcf1c7f0cddc429dbb (plain)
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
#include "texmap.h"
#include "../layout.h"

LYTTexMap::LYTTexMap() {
}

void LYTTexMap::dumpToDebug() {
	qDebug() << "LYTTexMap @" << (void*)this << ":" << textureName;
	qDebug() << "- wrap_s:" << wrap_s << "- wrap_t:" << wrap_t;
	qDebug() << "- mag_filter:" << mag_filter << "- min_filter:" << min_filter;
}


void LYTTexMap::writeToDataStream(QDataStream &out, LYTLayout &layout) {
	quint16 texNum = layout.m_textureRefs.indexOf(textureName);
	out << (quint16)texNum;

	quint8 var1, var2;
	var1 = wrap_s | (((min_filter + 7) & 7) << 2);
	var2 = wrap_t | (((mag_filter + 1) & 1) << 2);
	out << (quint8)var1;
	out << (quint8)var2;
}


void LYTTexMap::readFromDataStream(QDataStream &in, LYTLayout &layout) {
	quint16 texNum;
	in >> (quint16&)texNum;

	textureName = layout.m_textureRefs[texNum];

	quint8 var1, var2;
	in >> (quint8&)var1;
	in >> (quint8&)var2;

	wrap_s = BitExtract(var1, 2, 30);
	wrap_t = BitExtract(var2, 2, 30);

	min_filter = (BitExtract(var1, 3, 27) + 1) & 7;
	mag_filter = (BitExtract(var2, 1, 29) + 1) & 1;
}