| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include <array> |
| 7 |
|
| 8 |
#include "Common/EnumMap.h" |
| 9 |
#include "VideoCommon/BPMemory.h" |
| 10 |
|
| 11 |
class Tev |
| 12 |
{ |
| 13 |
struct TevColor |
| 14 |
{ |
| 15 |
constexpr TevColor() = default; |
| 16 |
constexpr explicit TevColor(s16 a_, s16 b_, s16 g_, s16 r_) : a(a_), b(b_), g(g_), r(r_) {} |
| 17 |
|
| 18 |
s16 a = 0; |
| 19 |
s16 b = 0; |
| 20 |
s16 g = 0; |
| 21 |
s16 r = 0; |
| 22 |
|
| 23 |
constexpr static TevColor All(s16 value) { return TevColor(value, value, value, value); } |
| 24 |
|
| 25 |
constexpr s16& operator[](int index) |
| 26 |
{ |
| 27 |
switch (index) |
| 28 |
{ |
| 29 |
case ALP_C: |
| 30 |
return a; |
| 31 |
case BLU_C: |
| 32 |
return b; |
| 33 |
case GRN_C: |
| 34 |
return g; |
| 35 |
case RED_C: |
| 36 |
return r; |
| 37 |
default: |
| 38 |
|
| 39 |
return a; |
| 40 |
} |
| 41 |
} |
| 42 |
}; |
| 43 |
|
| 44 |
struct TevColorRef |
| 45 |
{ |
| 46 |
constexpr explicit TevColorRef(const s16& r_, const s16& g_, const s16& b_) |
| 47 |
: r(r_), g(g_), b(b_) |
| 48 |
{ |
| 49 |
} |
| 50 |
|
| 51 |
const s16& r; |
| 52 |
const s16& g; |
| 53 |
const s16& b; |
| 54 |
|
| 55 |
constexpr static TevColorRef Color(const TevColor& color) |
| 56 |
{ |
| 57 |
return TevColorRef(color.r, color.g, color.b); |
| 58 |
} |
| 59 |
constexpr static TevColorRef All(const s16& value) { return TevColorRef(value, value, value); } |
| 60 |
constexpr static TevColorRef Alpha(const TevColor& color) { return All(color.a); } |
| 61 |
}; |
| 62 |
|
| 63 |
struct TevAlphaRef |
| 64 |
{ |
| 65 |
constexpr explicit TevAlphaRef(const TevColor& color) : a(color.a) {} |
| 66 |
constexpr explicit TevAlphaRef(const s16& a_) : a(a_) {} |
| 67 |
|
| 68 |
const s16& a; |
| 69 |
}; |
| 70 |
|
| 71 |
struct TevKonstRef |
| 72 |
{ |
| 73 |
constexpr explicit TevKonstRef(const s16& a_, const s16& r_, const s16& g_, const s16& b_) |
| 74 |
: a(a_), r(r_), g(g_), b(b_) |
| 75 |
{ |
| 76 |
} |
| 77 |
|
| 78 |
const s16& a; |
| 79 |
const s16& r; |
| 80 |
const s16& g; |
| 81 |
const s16& b; |
| 82 |
|
| 83 |
constexpr static TevKonstRef Value(const s16& value) |
| 84 |
{ |
| 85 |
return TevKonstRef(value, value, value, value); |
| 86 |
} |
| 87 |
constexpr static TevKonstRef Konst(const s16& alpha, const TevColor& color) |
| 88 |
{ |
| 89 |
return TevKonstRef(alpha, color.r, color.g, color.b); |
| 90 |
} |
| 91 |
}; |
| 92 |
|
| 93 |
struct InputRegType |
| 94 |
{ |
| 95 |
unsigned a : 8; |
| 96 |
unsigned b : 8; |
| 97 |
unsigned c : 8; |
| 98 |
signed d : 11; |
| 99 |
}; |
| 100 |
|
| 101 |
struct TextureCoordinateType |
| 102 |
{ |
| 103 |
signed s : 24; |
| 104 |
signed t : 24; |
| 105 |
}; |
| 106 |
|
| 107 |
|
| 108 |
Common::EnumMap<TevColor, TevOutput::Color2> Reg; |
| 109 |
std::array<TevColor, 4> KonstantColors; |
| 110 |
TevColor RawTexColor; |
| 111 |
TevColor TexColor; |
| 112 |
TevColor RasColor; |
| 113 |
TevColor StageKonst; |
| 114 |
|
| 115 |
|
| 116 |
static constexpr s16 V0 = 0; |
| 117 |
static constexpr s16 V1_8 = 32; |
| 118 |
static constexpr s16 V1_4 = 64; |
| 119 |
static constexpr s16 V3_8 = 96; |
| 120 |
static constexpr s16 V1_2 = 128; |
| 121 |
static constexpr s16 V5_8 = 159; |
| 122 |
static constexpr s16 V3_4 = 191; |
| 123 |
static constexpr s16 V7_8 = 223; |
| 124 |
static constexpr s16 V1 = 255; |
| 125 |
|
| 126 |
u8 AlphaBump = 0; |
| 127 |
u8 IndirectTex[4][4]{}; |
| 128 |
TextureCoordinateType TexCoord{}; |
| 129 |
|
| 130 |
const Common::EnumMap<TevColorRef, TevColorArg::Zero> m_ColorInputLUT{ |
| 131 |
TevColorRef::Color(Reg[TevOutput::Prev]), |
| 132 |
TevColorRef::Alpha(Reg[TevOutput::Prev]), |
| 133 |
TevColorRef::Color(Reg[TevOutput::Color0]), |
| 134 |
TevColorRef::Alpha(Reg[TevOutput::Color0]), |
| 135 |
TevColorRef::Color(Reg[TevOutput::Color1]), |
| 136 |
TevColorRef::Alpha(Reg[TevOutput::Color1]), |
| 137 |
TevColorRef::Color(Reg[TevOutput::Color2]), |
| 138 |
TevColorRef::Alpha(Reg[TevOutput::Color2]), |
| 139 |
TevColorRef::Color(TexColor), |
| 140 |
TevColorRef::Alpha(TexColor), |
| 141 |
TevColorRef::Color(RasColor), |
| 142 |
TevColorRef::Alpha(RasColor), |
| 143 |
TevColorRef::All(V1), |
| 144 |
TevColorRef::All(V1_2), |
| 145 |
TevColorRef::Color(StageKonst), |
| 146 |
TevColorRef::All(V0), |
| 147 |
}; |
| 148 |
const Common::EnumMap<TevAlphaRef, TevAlphaArg::Zero> m_AlphaInputLUT{ |
| 149 |
TevAlphaRef(Reg[TevOutput::Prev]), |
| 150 |
TevAlphaRef(Reg[TevOutput::Color0]), |
| 151 |
TevAlphaRef(Reg[TevOutput::Color1]), |
| 152 |
TevAlphaRef(Reg[TevOutput::Color2]), |
| 153 |
TevAlphaRef(TexColor), |
| 154 |
TevAlphaRef(RasColor), |
| 155 |
TevAlphaRef(StageKonst), |
| 156 |
TevAlphaRef(V0), |
| 157 |
}; |
| 158 |
const Common::EnumMap<TevKonstRef, KonstSel::K3_A> m_KonstLUT{ |
| 159 |
TevKonstRef::Value(V1), |
| 160 |
TevKonstRef::Value(V7_8), |
| 161 |
TevKonstRef::Value(V3_4), |
| 162 |
TevKonstRef::Value(V5_8), |
| 163 |
TevKonstRef::Value(V1_2), |
| 164 |
TevKonstRef::Value(V3_8), |
| 165 |
TevKonstRef::Value(V1_4), |
| 166 |
TevKonstRef::Value(V1_8), |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
TevKonstRef::Value(V0), TevKonstRef::Value(V0), TevKonstRef::Value(V0), |
| 171 |
TevKonstRef::Value(V0), |
| 172 |
|
| 173 |
|
| 174 |
TevKonstRef::Konst(V0, KonstantColors[0]), |
| 175 |
TevKonstRef::Konst(V0, KonstantColors[1]), |
| 176 |
TevKonstRef::Konst(V0, KonstantColors[2]), |
| 177 |
TevKonstRef::Konst(V0, KonstantColors[3]), |
| 178 |
|
| 179 |
TevKonstRef::Value(KonstantColors[0].r), |
| 180 |
TevKonstRef::Value(KonstantColors[1].r), |
| 181 |
TevKonstRef::Value(KonstantColors[2].r), |
| 182 |
TevKonstRef::Value(KonstantColors[3].r), |
| 183 |
TevKonstRef::Value(KonstantColors[0].g), |
| 184 |
TevKonstRef::Value(KonstantColors[1].g), |
| 185 |
TevKonstRef::Value(KonstantColors[2].g), |
| 186 |
TevKonstRef::Value(KonstantColors[3].g), |
| 187 |
TevKonstRef::Value(KonstantColors[0].b), |
| 188 |
TevKonstRef::Value(KonstantColors[1].b), |
| 189 |
TevKonstRef::Value(KonstantColors[2].b), |
| 190 |
TevKonstRef::Value(KonstantColors[3].b), |
| 191 |
TevKonstRef::Value(KonstantColors[0].a), |
| 192 |
TevKonstRef::Value(KonstantColors[1].a), |
| 193 |
TevKonstRef::Value(KonstantColors[2].a), |
| 194 |
TevKonstRef::Value(KonstantColors[3].a), |
| 195 |
}; |
| 196 |
static constexpr Common::EnumMap<s16, TevBias::Compare> s_BiasLUT{0, 128, -128, 0}; |
| 197 |
static constexpr Common::EnumMap<u8, TevScale::Divide2> s_ScaleLShiftLUT{0, 1, 2, 0}; |
| 198 |
static constexpr Common::EnumMap<u8, TevScale::Divide2> s_ScaleRShiftLUT{0, 0, 0, 1}; |
| 199 |
|
| 200 |
enum BufferBase |
| 201 |
{ |
| 202 |
DIRECT = 0, |
| 203 |
DIRECT_TFETCH = 16, |
| 204 |
INDIRECT = 32 |
| 205 |
}; |
| 206 |
|
| 207 |
void SetRasColor(RasColorChan colorChan, u32 swaptable); |
| 208 |
|
| 209 |
void DrawColorRegular(const TevStageCombiner::ColorCombiner& cc, const InputRegType inputs[4]); |
| 210 |
void DrawColorCompare(const TevStageCombiner::ColorCombiner& cc, const InputRegType inputs[4]); |
| 211 |
void DrawAlphaRegular(const TevStageCombiner::AlphaCombiner& ac, const InputRegType inputs[4]); |
| 212 |
void DrawAlphaCompare(const TevStageCombiner::AlphaCombiner& ac, const InputRegType inputs[4]); |
| 213 |
|
| 214 |
void Indirect(unsigned int stageNum, s32 s, s32 t); |
| 215 |
|
| 216 |
public: |
| 217 |
s32 Position[3]{}; |
| 218 |
u8 Color[2][4]{}; |
| 219 |
TextureCoordinateType Uv[8]{}; |
| 220 |
s32 IndirectLod[4]{}; |
| 221 |
bool IndirectLinear[4]{}; |
| 222 |
s32 TextureLod[16]{}; |
| 223 |
bool TextureLinear[16]{}; |
| 224 |
|
| 225 |
enum |
| 226 |
{ |
| 227 |
ALP_C, |
| 228 |
BLU_C, |
| 229 |
GRN_C, |
| 230 |
RED_C |
| 231 |
}; |
| 232 |
|
| 233 |
void SetKonstColors(); |
| 234 |
void Draw(); |
| 235 |
}; |