summaryrefslogtreecommitdiff
path: root/lyt/materials/material.h
blob: 643f656831f20dd0ffe2854ef6723fa9a5b2b7f0 (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
#ifndef LYTMATERIAL_H
#define LYTMATERIAL_H

#include <QtCore/QList>
#include <QtCore/QString>
#include <QtCore/QDataStream>
#include <QtCore/QDebug>

#include "../common.h"
#include "texmap.h"
#include "texsrt.h"
#include "texcoordgen.h"

class LYTLayout;


class LYTMaterialResourceNum {
public:
	quint32 value;

	inline  int getTexMapNum()		{ return BitExtract(value, 4, 28); }
	inline  int getTexSRTNum()		{ return BitExtract(value, 4, 24); }
	inline  int getTexCoordGenNum()	{ return BitExtract(value, 4, 20); }
	inline bool hasChanCtrl()		{ return BitExtract(value, 1, 6);  }
	inline bool hasMatCol()			{ return BitExtract(value, 1, 4);  }
	inline bool hasTevSwapTable()	{ return BitExtract(value, 1, 19); }
	inline bool hasAlphaCompare()	{ return BitExtract(value, 1, 8);  }
	inline bool hasBlendMode()		{ return BitExtract(value, 1, 7);  }
	inline  int getIndTexSRTNum()	{ return BitExtract(value, 2, 17); }
	inline  int getIndTexStageNum()	{ return BitExtract(value, 3, 14); }
	inline  int getTevStageNum()	{ return BitExtract(value, 5, 9);  }
};



class LYTChanCtrl {
public:
	void writeToDataStream(QDataStream &out);
	void readFromDataStream(QDataStream &in);

	void dumpToDebug();

	quint8 colourMatSrc;
	quint8 alphaMatSrc;
};

class LYTTevSwapMode {
public:
	void writeToDataStream(QDataStream &out);
	void readFromDataStream(QDataStream &in);

	void dumpToDebug();

	int red;
	int green;
	int blue;
	int alpha;
};

class LYTIndirectStage {
public:
	void writeToDataStream(QDataStream &out);
	void readFromDataStream(QDataStream &in);

	void dumpToDebug();

};

class LYTTevStage {
public:
	void writeToDataStream(QDataStream &out);
	void readFromDataStream(QDataStream &in);

	void dumpToDebug();

};

class LYTAlphaCompare {
public:
	void writeToDataStream(QDataStream &out);
	void readFromDataStream(QDataStream &in);

	void dumpToDebug();

};

class LYTBlendMode {
public:
	void writeToDataStream(QDataStream &out);
	void readFromDataStream(QDataStream &in);

	void dumpToDebug();

};




class LYTMaterial {
public:
	LYTMaterial(LYTLayout &layout);
	~LYTMaterial();


	void writeToDataStream(QDataStream &out);
	void readFromDataStream(QDataStream &in);

	void dumpToDebug();

	LYTLayout &layout() const;

	QString name;

	QColor colours[3];
	QColor tevKColour[4];

	QList<LYTTexMap> texMaps;
	QList<LYTTexSRT> texSRTs;
	QList<LYTTexCoordGen> texCoordGens;

	bool hasChanCtrl;
	LYTChanCtrl chanCtrl;

	bool hasMatCol;
	QColor matCol;

	bool hasTevSwapTable;
	LYTTevSwapMode tevSwapTable;

	bool hasAlphaCompare;
	LYTAlphaCompare alphaCompare;

	bool hasBlendMode;
	LYTBlendMode blendMode;

	QList<LYTIndirectStage> indTexStages;
	QList<LYTTexSRT> indTexSRTs;

	QList<LYTTevStage> tevStages;



protected:
	LYTLayout &m_layout;

	void readTexMap(QDataStream &in);
	void readTexSRT(QDataStream &in);
	void readTexCoordGen(QDataStream &in);
	void readChanCtrl(QDataStream &in);
	void readMatCol(QDataStream &in);
	void readTevSwapTable(QDataStream &in);
	void readAlphaCompare(QDataStream &in);
	void readBlendMode(QDataStream &in);
	void readIndirectStage(QDataStream &in);
	void readIndTexSRT(QDataStream &in);
	void readTevStage(QDataStream &in);
};

#endif // LYTMATERIAL_H