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 }
185 command |= 0x02000000;
186 return *this;
187 }
188 bool isSemiTrans() const { return command & 0x02000000; }
190 pointA = v;
191 return *this;
192 }
194 pointB = v;
195 return *this;
196 }
198 pointC = v;
199 return *this;
200 }
202 pointD = v;
203 return *this;
204 }
205 template <Transparency transparency = Transparency::Auto>
206 void interpolateColors(const Color* a, const Color* b, const Color* c, const Color* d) {
207 uint32_t rgb;
208 if constexpr (transparency == Transparency::Auto) {
209 rgb = (a->packed & 0xffffff) | (command & 0xff000000);
210 } else if constexpr (transparency == Transparency::Opaque) {
211 rgb = (a->packed & 0xffffff) | 0x38000000;
212 } else if constexpr (transparency == Transparency::SemiTransparent) {
213 rgb = (a->packed & 0xffffff) | 0x3a000000;
214 }
215 GTE::write<GTE::Register::RGB, GTE::Safe>(rgb);
216 GTE::Kernels::dpcs();
217 GTE::read<GTE::Register::RGB2>(&command);
218 GTE::write<GTE::Register::RGB0, GTE::Unsafe>(&b->packed);
219 GTE::write<GTE::Register::RGB1, GTE::Unsafe>(&c->packed);
220 GTE::write<GTE::Register::RGB2, GTE::Safe>(&d->packed);
221 GTE::Kernels::dpct();
222 GTE::read<GTE::Register::RGB0>(&colorB.packed);
223 GTE::read<GTE::Register::RGB1>(&colorC.packed);
224 GTE::read<GTE::Register::RGB2>(&colorD.packed);
225 }
226 template <Transparency transparency = Transparency::Auto>
228 uint32_t rgb;
229 if constexpr (transparency == Transparency::Auto) {
230 rgb = (a.packed & 0xffffff) | (command & 0xff000000);
231 } else if constexpr (transparency == Transparency::Opaque) {
232 rgb = (a.packed & 0xffffff) | 0x38000000;
233 } else if constexpr (transparency == Transparency::SemiTransparent) {
234 rgb = (a.packed & 0xffffff) | 0x3a000000;
235 }
236 GTE::write<GTE::Register::RGB, GTE::Safe>(rgb);
237 GTE::Kernels::dpcs();
238 GTE::read<GTE::Register::RGB2>(&command);
239 GTE::write<GTE::Register::RGB0, GTE::Unsafe>(b.packed);
240 GTE::write<GTE::Register::RGB1, GTE::Unsafe>(c.packed);
241 GTE::write<GTE::Register::RGB2, GTE::Safe>(d.packed);
242 GTE::Kernels::dpct();
243 GTE::read<GTE::Register::RGB0>(&colorB.packed);
244 GTE::read<GTE::Register::RGB1>(&colorC.packed);
245 GTE::read<GTE::Register::RGB2>(&colorD.packed);
246 }
247
248 private:
249 uint32_t command;
250
251 public:
259};
260static_assert(sizeof(GouraudQuad) == (sizeof(uint32_t) * 8), "GouraudQuad is not 8 words");
261
278 GouraudTexturedQuad() : command(0x3c000000) {}
279 GouraudTexturedQuad(Color c) : command(0x3c000000 | (c.packed & 0x00ffffff)) {}
280 GouraudTexturedQuad(const GouraudTexturedQuad& other, Color c) : command(other.command | (c.packed & 0x00ffffff)) {}
282 uint32_t wasSemiTrans = command & 0x02000000;
283 command = 0x3c000000 | (c.packed & 0x00ffffff) | wasSemiTrans;
284 return *this;
285 }
287 colorB = c;
288 return *this;
289 }
291 colorC = c;
292 return *this;
293 }
295 colorD = c;
296 return *this;
297 }
298 Color getColorA() const { return Color{.packed = command & 0x00ffffff}; }
299 Color getColorB() const { return colorB; }
300 Color getColorC() const { return colorC; }
301 Color getColorD() const { return colorD; }
303 command &= ~0x02000000;
304 return *this;
305 }
307 command |= 0x02000000;
308 return *this;
309 }
310 bool isSemiTrans() const { return command & 0x02000000; }
311 template <Transparency transparency = Transparency::Auto>
312 void interpolateColors(const Color* a, const Color* b, const Color* c, const Color* d) {
313 uint32_t rgb;
314 if constexpr (transparency == Transparency::Auto) {
315 rgb = (a->packed & 0xffffff) | (command & 0xff000000);
316 } else if constexpr (transparency == Transparency::Opaque) {
317 rgb = (a->packed & 0xffffff) | 0x3c000000;
318 } else if constexpr (transparency == Transparency::SemiTransparent) {
319 rgb = (a->packed & 0xffffff) | 0x3e000000;
320 }
321 GTE::write<GTE::Register::RGB, GTE::Safe>(rgb);
322 GTE::Kernels::dpcs();
323 GTE::read<GTE::Register::RGB2>(&command);
324 GTE::write<GTE::Register::RGB0, GTE::Unsafe>(&b->packed);
325 GTE::write<GTE::Register::RGB1, GTE::Unsafe>(&c->packed);
326 GTE::write<GTE::Register::RGB2, GTE::Safe>(&d->packed);
327 GTE::Kernels::dpct();
328 GTE::read<GTE::Register::RGB0>(&colorB.packed);
329 GTE::read<GTE::Register::RGB1>(&colorC.packed);
330 GTE::read<GTE::Register::RGB2>(&colorD.packed);
331 }
332 template <Transparency transparency = Transparency::Auto>
334 uint32_t rgb;
335 if constexpr (transparency == Transparency::Auto) {
336 rgb = (a.packed & 0xffffff) | (command & 0xff000000);
337 } else if constexpr (transparency == Transparency::Opaque) {
338 rgb = (a.packed & 0xffffff) | 0x3c000000;
339 } else if constexpr (transparency == Transparency::SemiTransparent) {
340 rgb = (a.packed & 0xffffff) | 0x3e000000;
341 }
342 GTE::write<GTE::Register::RGB, GTE::Safe>(rgb);
343 GTE::Kernels::dpcs();
344 GTE::read<GTE::Register::RGB2>(&command);
345 GTE::write<GTE::Register::RGB0, GTE::Unsafe>(b.packed);
346 GTE::write<GTE::Register::RGB1, GTE::Unsafe>(c.packed);
347 GTE::write<GTE::Register::RGB2, GTE::Safe>(d.packed);
348 GTE::Kernels::dpct();
349 GTE::read<GTE::Register::RGB0>(&colorB.packed);
350 GTE::read<GTE::Register::RGB1>(&colorC.packed);
351 GTE::read<GTE::Register::RGB2>(&colorD.packed);
352 }
353
354 private:
355 uint32_t command;
356
357 public:
371};
372static_assert(sizeof(GouraudTexturedQuad) == (sizeof(uint32_t) * 12), "GouraudTexturedQuad is not 12 words");
373
374} // namespace Prim
375
376} // namespace psyqo
Definition cdrom-loader.hh:39
char b[9]
Definition string.c:47
A primitive's CLUT command.
Definition common.hh:121
A primitive's tpage attribute.
Definition common.hh:158
A primitive's UV coordinates attribute.
Definition common.hh:233
A primitive's UV coordinates attribute.
Definition common.hh:222
A gouraud-shaded quad.
Definition quads.hh:155
GouraudQuad & setSemiTrans()
Definition quads.hh:184
Color getColorC() const
Definition quads.hh:178
GouraudQuad & setPointA(Vertex v)
Definition quads.hh:189
GouraudQuad()
Definition quads.hh:156
bool isSemiTrans() const
Definition quads.hh:188
Color getColorD() const
Definition quads.hh:179
GouraudQuad & setColorD(Color c)
Definition quads.hh:172
Vertex pointC
Definition quads.hh:256
Color colorB
Definition quads.hh:253
Vertex pointD
Definition quads.hh:258
Color colorD
Definition quads.hh:257
Color getColorA() const
Definition quads.hh:176
GouraudQuad & setColorC(Color c)
Definition quads.hh:168
GouraudQuad & setPointC(Vertex v)
Definition quads.hh:197
GouraudQuad(Color c)
Definition quads.hh:157
void interpolateColors(const Color *a, const Color *b, const Color *c, const Color *d)
Definition quads.hh:206
Vertex pointB
Definition quads.hh:254
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:252
void interpolateColors(Color a, Color b, Color c, Color d)
Definition quads.hh:227
GouraudQuad & setPointD(Vertex v)
Definition quads.hh:201
GouraudQuad & setPointB(Vertex v)
Definition quads.hh:193
Color colorC
Definition quads.hh:255
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:277
GouraudTexturedQuad(Color c)
Definition quads.hh:279
GouraudTexturedQuad & setColorD(Color c)
Definition quads.hh:294
GouraudTexturedQuad & setColorA(Color c)
Definition quads.hh:281
Vertex pointD
Definition quads.hh:369
Color getColorB() const
Definition quads.hh:299
Color getColorD() const
Definition quads.hh:301
Color colorD
Definition quads.hh:368
Color getColorA() const
Definition quads.hh:298
GouraudTexturedQuad & setColorB(Color c)
Definition quads.hh:286
Color colorC
Definition quads.hh:365
PrimPieces::UVCoordsPadded uvC
Definition quads.hh:367
GouraudTexturedQuad()
Definition quads.hh:278
PrimPieces::TPageAttr tpage
Definition quads.hh:364
GouraudTexturedQuad & setColorC(Color c)
Definition quads.hh:290
Vertex pointA
Definition quads.hh:358
GouraudTexturedQuad(const GouraudTexturedQuad &other, Color c)
Definition quads.hh:280
GouraudTexturedQuad & setSemiTrans()
Definition quads.hh:306
void interpolateColors(Color a, Color b, Color c, Color d)
Definition quads.hh:333
PrimPieces::UVCoords uvA
Definition quads.hh:359
PrimPieces::UVCoords uvB
Definition quads.hh:363
Color colorB
Definition quads.hh:361
PrimPieces::UVCoordsPadded uvD
Definition quads.hh:370
Vertex pointC
Definition quads.hh:366
void interpolateColors(const Color *a, const Color *b, const Color *c, const Color *d)
Definition quads.hh:312
Color getColorC() const
Definition quads.hh:300
bool isSemiTrans() const
Definition quads.hh:310
Vertex pointB
Definition quads.hh:362
PrimPieces::ClutIndex clutIndex
Definition quads.hh:360
GouraudTexturedQuad & setOpaque()
Definition quads.hh:302
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:121
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