summaryrefslogtreecommitdiff
path: root/lyt/materials/tevstage.cpp
blob: 768e25209ad5654b6fa413fbc48e3fbc3a82374d (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
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
/*******************************************************************************
  This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio)
  Copyright (c) 2010 Treeki (treeki@gmail.com)

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, version 2.0.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License 2.0 for more details.

  You should have received a copy of the GNU General Public License 2.0
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/

#include "tevstage.h"
#include "../layout.h"

LYTTevStage::LYTTevStage() {
}

void LYTTevStage::dumpToDebug() const {
	qDebug() << "LYTTevStage @" << (void*)this;
	qDebug() << "TEV order: texCoord" << texCoord << ", colour" << colour << ", texMap" << texMap;
	qDebug() << "SwapMode: ras" << rasSwapMode << ", tex" << texSwapMode;

	qDebug() << "Colour In:" << colourInA << colourInB << colourInC << colourInD;
	qDebug() << "Op:" << colourOp << ", Bias:" << colourBias << ", Scale:" << colourScale;
	qDebug() << "Clamp:" << colourClamp << ", OutReg:" << colourOutReg;

	qDebug() << "Alpha In:" << alphaInA << alphaInB << alphaInC << alphaInD;
	qDebug() << "Op:" << alphaOp << ", Bias:" << alphaBias << ", Scale:" << alphaScale;
	qDebug() << "Clamp:" << alphaClamp << ", OutReg:" << alphaOutReg;

	qDebug() << "Colour Const:" << colourConst << ", Alpha Const:" << alphaConst;

	qDebug() << "Indirect Stage:" << indStage << ", Format:" << indFormat;
	qDebug() << "Bias:" << indBias << ", Matrix:" << indMatrix;
	qDebug() << "WrapS:" << indWrapS << ", WrapT:" << indWrapT << ", AddPrev:" << indAddPrev;
	qDebug() << "UtcLod:" << indUtcLod << ", AlphaSel:" << indAlphaSel;
}


void LYTTevStage::writeToDataStream(QDataStream &out) const {
	char data[0x10];
	qMemSet(data, 0, 0x10);

	// TEV order:
	data[0] = texCoord;
	data[1] = colour;
	data[2] = texMap & 0xFF;
	data[3] = BitInsert(data[3], texMap >> 8, 1, 32 - 1);

	// SwapMode:
	data[3] = BitInsert(data[3], rasSwapMode, 2, 32 - 3);
	data[3] = BitInsert(data[3], texSwapMode, 2, 32 - 5);

	// Colour In:
	data[4] = BitInsert(data[4], colourInA, 4, 32 - 4);
	data[4] = BitInsert(data[4], colourInB, 4, 32 - 8);
	data[5] = BitInsert(data[5], colourInC, 4, 32 - 4);
	data[5] = BitInsert(data[5], colourInD, 4, 32 - 8);

	// Colour Op:
	data[6] = BitInsert(data[6], colourOp, 4, 32 - 4);
	data[6] = BitInsert(data[6], colourBias, 2, 32 - 6);
	data[6] = BitInsert(data[6], colourScale, 2, 32 - 8);
	data[7] = BitInsert(data[7], colourClamp, 1, 32 - 1);
	data[7] = BitInsert(data[7], colourOutReg, 2, 32 - 3);

	// Alpha In:
	data[8] = BitInsert(data[8], alphaInA, 4, 32 - 4);
	data[8] = BitInsert(data[8], alphaInB, 4, 32 - 8);
	data[9] = BitInsert(data[9], alphaInC, 4, 32 - 4);
	data[9] = BitInsert(data[9], alphaInD, 4, 32 - 8);

	// Alpha Op:
	data[10] = BitInsert(data[10], alphaOp, 4, 32 - 4);
	data[10] = BitInsert(data[10], alphaBias, 2, 32 - 6);
	data[10] = BitInsert(data[10], alphaScale, 2, 32 - 8);
	data[11] = BitInsert(data[11], alphaClamp, 1, 32 - 1);
	data[11] = BitInsert(data[11], alphaOutReg, 2, 32 - 3);

	// Constants:
	data[7] = BitInsert(data[7], colourConst, 5, 32 - 8);
	data[11] = BitInsert(data[11], alphaConst, 5, 32 - 8);

	// Indirect:
	data[12] = indStage;
	data[15] = BitInsert(data[15], indFormat, 2, 32 - 2);
	data[13] = BitInsert(data[13], indBias, 3, 32 - 3);
	data[13] = BitInsert(data[13], indMatrix, 4, 32 - 7);
	data[14] = BitInsert(data[14], indWrapS, 3, 32 - 3);
	data[14] = BitInsert(data[14], indWrapT, 3, 32 - 6);
	data[15] = BitInsert(data[15], indAddPrev, 1, 32 - 3);
	data[15] = BitInsert(data[15], indUtcLod, 1, 32 - 4);
	data[15] = BitInsert(data[15], indAlphaSel, 2, 32 - 6);

	out.writeRawData(data, 0x10);
}


void LYTTevStage::readFromDataStream(QDataStream &in) {
	// not fun. at all.

	char data[0x10];
	in.readRawData(data, 0x10);

	// TEV order:
	texCoord = data[0];
	colour = data[1];
	texMap = data[2] | (BitExtract(data[3], 1, 32 - 1) << 8);

	// SwapMode:
	rasSwapMode = BitExtract(data[3], 2, 32 - 3);
	texSwapMode = BitExtract(data[3], 2, 32 - 5);

	// Colour In:
	colourInA = BitExtract(data[4], 4, 32 - 4);
	colourInB = BitExtract(data[4], 4, 32 - 8);
	colourInC = BitExtract(data[5], 4, 32 - 4);
	colourInD = BitExtract(data[5], 4, 32 - 8);

	// Colour Op:
	colourOp = BitExtract(data[6], 4, 32 - 4);
	colourBias = BitExtract(data[6], 2, 32 - 6);
	colourScale = BitExtract(data[6], 2, 32 - 8);
	colourClamp = BitExtract(data[7], 1, 32 - 1);
	colourOutReg = BitExtract(data[7], 2, 32 - 3);

	// Alpha In:
	alphaInA = BitExtract(data[8], 4, 32 - 4);
	alphaInB = BitExtract(data[8], 4, 32 - 8);
	alphaInC = BitExtract(data[9], 4, 32 - 4);
	alphaInD = BitExtract(data[9], 4, 32 - 8);

	// Alpha Op:
	alphaOp = BitExtract(data[10], 4, 32 - 4);
	alphaBias = BitExtract(data[10], 2, 32 - 6);
	alphaScale = BitExtract(data[10], 2, 32 - 8);
	alphaClamp = BitExtract(data[11], 1, 32 - 1);
	alphaOutReg = BitExtract(data[11], 2, 32 - 3);

	// Constants:
	colourConst = BitExtract(data[7], 5, 32 - 8);
	alphaConst = BitExtract(data[11], 5, 32 - 8);

	// Indirect:
	indStage = data[12];
	indFormat = BitExtract(data[15], 2, 32 - 2);
	indBias = BitExtract(data[13], 3, 32 - 3);
	indMatrix = BitExtract(data[13], 4, 32 - 7);
	indWrapS = BitExtract(data[14], 3, 32 - 3);
	indWrapT = BitExtract(data[14], 3, 32 - 6);
	indAddPrev = BitExtract(data[15], 1, 32 - 3);
	indUtcLod = BitExtract(data[15], 1, 32 - 4);
	indAlphaSel = BitExtract(data[15], 2, 32 - 6);
}