Nugget
Loading...
Searching...
No Matches
quads.hh
Go to the documentation of this file.
1/*
2
3MIT License
4
5Copyright (c) 2022 PCSX-Redux authors
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26
27#pragma once
28
29#include <stdint.h>
30
31#include "psyqo/gte-kernels.hh"
34
35namespace psyqo {
36
37namespace Prim {
38
52struct Quad {
53 Quad() : command(0x28000000) {}
54 Quad(Color c) : command(0x28000000 | (c.packed & 0x00ffffff)) {}
55 Quad(const Quad& other, Color c) : command(other.command | (c.packed & 0x00ffffff)) {}
57 uint32_t wasSemiTrans = command & 0x02000000;
58 command = 0x28000000 | (c.packed & 0x00ffffff) | wasSemiTrans;
59 return *this;
60 }
61 Color getColor() const { return Color{.packed = command & 0x00ffffff}; }
63 command &= ~0x02000000;
64 return *this;
65 }
67 command |= 0x02000000;
68 return *this;
69 }
70 bool isSemiTrans() const { return command & 0x02000000; }
72 pointA = v;
73 return *this;
74 }
76 pointB = v;
77 return *this;
78 }
80 pointC = v;
81 return *this;
82 }
84 pointD = v;
85 return *this;
86 }
87
88 private:
89 uint32_t command;
90
91 public:
96};
97static_assert(sizeof(Quad) == (sizeof(uint32_t) * 5), "Quad is not 5 words");
98
111 TexturedQuad() : command(0x2c808080) {}
112 TexturedQuad(Color c) : command(0x2c000000 | (c.packed & 0x00ffffff)) {}
113 TexturedQuad(const TexturedQuad& other, Color c) : command(other.command | (c.packed & 0x00ffffff)) {}
115 uint32_t wasSemiTrans = command & 0x02000000;
116 command = 0x2c000000 | (c.packed & 0x00ffffff) | wasSemiTrans;
117 return *this;
118 }
119 Color getColor() const { return Color{.packed = command & 0x00ffffff}; }
121 command &= ~0x02000000;
122 return *this;
123 }
125 command |= 0x02000000;
126 return *this;
127 }
128 bool isSemiTrans() const { return command & 0x02000000; }
129
130 private:
131 uint32_t command;
132
133 public:
144};
145static_assert(sizeof(TexturedQuad) == (sizeof(uint32_t) * 9), "TexturedQuad is not 9 words");
146
156 GouraudQuad() : command(0x38000000) {}
157 GouraudQuad(Color c) : command(0x38000000 | (c.packed & 0x00ffffff)) {}
158 GouraudQuad(const GouraudQuad& other, Color c) : command(other.command | (c.packed & 0x00ffffff)) {}
160 uint32_t wasSemiTrans = command & 0x02000000;
161 command = 0x38000000 | (c.packed & 0x00ffffff) | wasSemiTrans;
162 return *this;
163 }
165 colorB = c;
166 return *this;
167 }
169 colorC = c;
170 return *this;
171 }
173 colorD = c;
174 return *this;
175 }
176 Color getColorA() const { return Color{.packed = command & 0x00ffffff}; }
177 Color getColorB() const { return colorB; }
178 Color getColorC() const { return colorC; }
179 Color getColorD() const { return colorD; }
181 command &= ~0x02000000;
182 return *this;
183 }
195 uint32_t getCommandWord() const { return command & 0xff000000; }
204 command = packed;
205 return *this;
206 }
208 command |= 0x02000000;
209 return *this;
210 }
211 bool isSemiTrans() const { return command & 0x02000000; }
213 pointA = v;
214 return *this;
215 }
217 pointB = v;
218 return *this;
219 }
221 pointC = v;
222 return *this;
223 }
225 pointD = v;
226 return *this;
227 }
228 template <Transparency transparency = Transparency::Auto>
229 void interpolateColors(const Color* a, const Color* b, const Color* c, const Color* d) {
230 uint32_t rgb;
231 if constexpr (transparency == Transparency::Auto) {
232 rgb = (a->packed & 0xffffff) | (command & 0xff000000);
233 } else if constexpr (transparency == Transparency::Opaque) {
234 rgb = (a->packed & 0xffffff) | 0x38000000;
235 } else if constexpr (transparency == Transparency::SemiTransparent) {
236 rgb = (a->packed & 0xffffff) | 0x3a000000;
237 }
238 GTE::write<GTE::Register::RGB, GTE::Safe>(rgb);
239 GTE::Kernels::dpcs();
240 GTE::read<GTE::Register::RGB2>(&command);
241 GTE::write<GTE::Register::RGB0, GTE::Unsafe>(&b->packed);
242 GTE::write<GTE::Register::RGB1, GTE::Unsafe>(&c->packed);
243 GTE::write<GTE::Register::RGB2, GTE::Safe>(&d->packed);
244 GTE::Kernels::dpct();
245 GTE::read<GTE::Register::RGB0>(&colorB.packed);
246 GTE::read<GTE::Register::RGB1>(&colorC.packed);
247 GTE::read<GTE::Register::RGB2>(&colorD.packed);
248 }
249 template <Transparency transparency = Transparency::Auto>
251 uint32_t rgb;
252 if constexpr (transparency == Transparency::Auto) {
253 rgb = (a.packed & 0xffffff) | (command & 0xff000000);
254 } else if constexpr (transparency == Transparency::Opaque) {
255 rgb = (a.packed & 0xffffff) | 0x38000000;
256 } else if constexpr (transparency == Transparency::SemiTransparent) {
257 rgb = (a.packed & 0xffffff) | 0x3a000000;
258 }
259 GTE::write<GTE::Register::RGB, GTE::Safe>(rgb);
260 GTE::Kernels::dpcs();
261 GTE::read<GTE::Register::RGB2>(&command);
262 GTE::write<GTE::Register::RGB0, GTE::Unsafe>(b.packed);
263 GTE::write<GTE::Register::RGB1, GTE::Unsafe>(c.packed);
264 GTE::write<GTE::Register::RGB2, GTE::Safe>(d.packed);
265 GTE::Kernels::dpct();
266 GTE::read<GTE::Register::RGB0>(&colorB.packed);
267 GTE::read<GTE::Register::RGB1>(&colorC.packed);
268 GTE::read<GTE::Register::RGB2>(&colorD.packed);
269 }
270
271 private:
272 uint32_t command;
273
274 public:
282};
283static_assert(sizeof(GouraudQuad) == (sizeof(uint32_t) * 8), "GouraudQuad is not 8 words");
284
301 GouraudTexturedQuad() : command(0x3c000000) {}
302 GouraudTexturedQuad(Color c) : command(0x3c000000 | (c.packed & 0x00ffffff)) {}
303 GouraudTexturedQuad(const GouraudTexturedQuad& other, Color c) : command(other.command | (c.packed & 0x00ffffff)) {}
305 uint32_t wasSemiTrans = command & 0x02000000;
306 command = 0x3c000000 | (c.packed & 0x00ffffff) | wasSemiTrans;
307 return *this;
308 }
310 colorB = c;
311 return *this;
312 }
314 colorC = c;
315 return *this;
316 }
318 colorD = c;
319 return *this;
320 }
321 Color getColorA() const { return Color{.packed = command & 0x00ffffff}; }
322 Color getColorB() const { return colorB; }
323 Color getColorC() const { return colorC; }
324 Color getColorD() const { return colorD; }
326 command &= ~0x02000000;
327 return *this;
328 }
336 uint32_t getCommandWord() const { return command & 0xff000000; }
345 command = packed;
346 return *this;
347 }
349 command |= 0x02000000;
350 return *this;
351 }
352 bool isSemiTrans() const { return command & 0x02000000; }
353 template <Transparency transparency = Transparency::Auto>
354 void interpolateColors(const Color* a, const Color* b, const Color* c, const Color* d) {
355 uint32_t rgb;
356 if constexpr (transparency == Transparency::Auto) {
357 rgb = (a->packed & 0xffffff) | (command & 0xff000000);
358 } else if constexpr (transparency == Transparency::Opaque) {
359 rgb = (a->packed & 0xffffff) | 0x3c000000;
360 } else if constexpr (transparency == Transparency::SemiTransparent) {
361 rgb = (a->packed & 0xffffff) | 0x3e000000;
362 }
363 GTE::write<GTE::Register::RGB, GTE::Safe>(rgb);
364 GTE::Kernels::dpcs();
365 GTE::read<GTE::Register::RGB2>(&command);
366 GTE::write<GTE::Register::RGB0, GTE::Unsafe>(&b->packed);
367 GTE::write<GTE::Register::RGB1, GTE::Unsafe>(&c->packed);
368 GTE::write<GTE::Register::RGB2, GTE::Safe>(&d->packed);
369 GTE::Kernels::dpct();
370 GTE::read<GTE::Register::RGB0>(&colorB.packed);
371 GTE::read<GTE::Register::RGB1>(&colorC.packed);
372 GTE::read<GTE::Register::RGB2>(&colorD.packed);
373 }
374 template <Transparency transparency = Transparency::Auto>
376 uint32_t rgb;
377 if constexpr (transparency == Transparency::Auto) {
378 rgb = (a.packed & 0xffffff) | (command & 0xff000000);
379 } else if constexpr (transparency == Transparency::Opaque) {
380 rgb = (a.packed & 0xffffff) | 0x3c000000;
381 } else if constexpr (transparency == Transparency::SemiTransparent) {
382 rgb = (a.packed & 0xffffff) | 0x3e000000;
383 }
384 GTE::write<GTE::Register::RGB, GTE::Safe>(rgb);
385 GTE::Kernels::dpcs();
386 GTE::read<GTE::Register::RGB2>(&command);
387 GTE::write<GTE::Register::RGB0, GTE::Unsafe>(b.packed);
388 GTE::write<GTE::Register::RGB1, GTE::Unsafe>(c.packed);
389 GTE::write<GTE::Register::RGB2, GTE::Safe>(d.packed);
390 GTE::Kernels::dpct();
391 GTE::read<GTE::Register::RGB0>(&colorB.packed);
392 GTE::read<GTE::Register::RGB1>(&colorC.packed);
393 GTE::read<GTE::Register::RGB2>(&colorD.packed);
394 }
395
396 private:
397 uint32_t command;
398
399 public:
413};
414static_assert(sizeof(GouraudTexturedQuad) == (sizeof(uint32_t) * 12), "GouraudTexturedQuad is not 12 words");
415
416} // namespace Prim
417
418} // namespace psyqo
uint8_t b
Definition gte-depthcue.c:39
Definition lua.hh:38
A primitive's CLUT command.
Definition common.hh:121
A primitive's tpage attribute.
Definition common.hh:188
A primitive's UV coordinates attribute.
Definition common.hh:295
A primitive's UV coordinates attribute.
Definition common.hh:284
A gouraud-shaded quad.
Definition quads.hh:155
GouraudQuad & setSemiTrans()
Definition quads.hh:207
Color getColorC() const
Definition quads.hh:178
GouraudQuad & setPointA(Vertex v)
Definition quads.hh:212
GouraudQuad()
Definition quads.hh:156
bool isSemiTrans() const
Definition quads.hh:211
Color getColorD() const
Definition quads.hh:179
GouraudQuad & setColorD(Color c)
Definition quads.hh:172
Vertex pointC
Definition quads.hh:279
Color colorB
Definition quads.hh:276
Vertex pointD
Definition quads.hh:281
Color colorD
Definition quads.hh:280
Color getColorA() const
Definition quads.hh:176
GouraudQuad & setColorC(Color c)
Definition quads.hh:168
GouraudQuad & setColorAPacked(uint32_t packed)
Sets the command word and vertex A's colour in one go.
Definition quads.hh:203
GouraudQuad & setPointC(Vertex v)
Definition quads.hh:220
GouraudQuad(Color c)
Definition quads.hh:157
void interpolateColors(const Color *a, const Color *b, const Color *c, const Color *d)
Definition quads.hh:229
Vertex pointB
Definition quads.hh:277
GouraudQuad & setOpaque()
Definition quads.hh:180
Color getColorB() const
Definition quads.hh:177
GouraudQuad & setColorA(Color c)
Definition quads.hh:159
Vertex pointA
Definition quads.hh:275
void interpolateColors(Color a, Color b, Color c, Color d)
Definition quads.hh:250
GouraudQuad & setPointD(Vertex v)
Definition quads.hh:224
GouraudQuad & setPointB(Vertex v)
Definition quads.hh:216
Color colorC
Definition quads.hh:278
uint32_t getCommandWord() const
The GP0 command word, minus any colour.
Definition quads.hh:195
GouraudQuad(const GouraudQuad &other, Color c)
Definition quads.hh:158
GouraudQuad & setColorB(Color c)
Definition quads.hh:164
A textured, blended quad.
Definition quads.hh:300
GouraudTexturedQuad(Color c)
Definition quads.hh:302
GouraudTexturedQuad & setColorD(Color c)
Definition quads.hh:317
GouraudTexturedQuad & setColorA(Color c)
Definition quads.hh:304
Vertex pointD
Definition quads.hh:411
Color getColorB() const
Definition quads.hh:322
Color getColorD() const
Definition quads.hh:324
Color colorD
Definition quads.hh:410
Color getColorA() const
Definition quads.hh:321
GouraudTexturedQuad & setColorB(Color c)
Definition quads.hh:309
Color colorC
Definition quads.hh:407
PrimPieces::UVCoordsPadded uvC
Definition quads.hh:409
GouraudTexturedQuad()
Definition quads.hh:301
PrimPieces::TPageAttr tpage
Definition quads.hh:406
GouraudTexturedQuad & setColorC(Color c)
Definition quads.hh:313
Vertex pointA
Definition quads.hh:400
GouraudTexturedQuad(const GouraudTexturedQuad &other, Color c)
Definition quads.hh:303
GouraudTexturedQuad & setSemiTrans()
Definition quads.hh:348
GouraudTexturedQuad & setColorAPacked(uint32_t packed)
Sets the command word and vertex A's colour in one go.
Definition quads.hh:344
void interpolateColors(Color a, Color b, Color c, Color d)
Definition quads.hh:375
PrimPieces::UVCoords uvA
Definition quads.hh:401
PrimPieces::UVCoords uvB
Definition quads.hh:405
Color colorB
Definition quads.hh:403
PrimPieces::UVCoordsPadded uvD
Definition quads.hh:412
Vertex pointC
Definition quads.hh:408
void interpolateColors(const Color *a, const Color *b, const Color *c, const Color *d)
Definition quads.hh:354
uint32_t getCommandWord() const
The GP0 command word, minus any colour.
Definition quads.hh:336
Color getColorC() const
Definition quads.hh:323
bool isSemiTrans() const
Definition quads.hh:352
Vertex pointB
Definition quads.hh:404
PrimPieces::ClutIndex clutIndex
Definition quads.hh:402
GouraudTexturedQuad & setOpaque()
Definition quads.hh:325
A flat-colored quad.
Definition quads.hh:52
Vertex pointD
Definition quads.hh:95
bool isSemiTrans() const
Definition quads.hh:70
Vertex pointA
Definition quads.hh:92
Quad(const Quad &other, Color c)
Definition quads.hh:55
Quad(Color c)
Definition quads.hh:54
Quad()
Definition quads.hh:53
Quad & setSemiTrans()
Definition quads.hh:66
Vertex pointC
Definition quads.hh:94
Quad & setOpaque()
Definition quads.hh:62
Quad & setPointC(Vertex v)
Definition quads.hh:79
Color getColor() const
Definition quads.hh:61
Quad & setPointA(Vertex v)
Definition quads.hh:71
Quad & setPointB(Vertex v)
Definition quads.hh:75
Quad & setColor(Color c)
Definition quads.hh:56
Quad & setPointD(Vertex v)
Definition quads.hh:83
Vertex pointB
Definition quads.hh:93
A textured quad.
Definition quads.hh:110
bool isSemiTrans() const
Definition quads.hh:128
TexturedQuad(Color c)
Definition quads.hh:112
PrimPieces::ClutIndex clutIndex
Definition quads.hh:136
TexturedQuad()
Definition quads.hh:111
TexturedQuad(const TexturedQuad &other, Color c)
Definition quads.hh:113
TexturedQuad & setOpaque()
Definition quads.hh:120
Vertex pointB
Definition quads.hh:137
TexturedQuad & setSemiTrans()
Definition quads.hh:124
Vertex pointC
Definition quads.hh:140
PrimPieces::UVCoords uvB
Definition quads.hh:138
PrimPieces::UVCoordsPadded uvD
Definition quads.hh:143
PrimPieces::UVCoords uvA
Definition quads.hh:135
Color getColor() const
Definition quads.hh:119
PrimPieces::TPageAttr tpage
Definition quads.hh:139
Vertex pointD
Definition quads.hh:142
Vertex pointA
Definition quads.hh:134
TexturedQuad & setColor(Color c)
Definition quads.hh:114
PrimPieces::UVCoordsPadded uvC
Definition quads.hh:141
static int c
Definition syscalls.h:122
void uint32_t(classId, spec)
The Color struct.
Definition common.hh:91
uint32_t packed
Definition common.hh:95
The Vertex struct.
Definition common.hh:47