Skip to content

Commit

Permalink
Merge pull request #1788 from nicolasnoble/prim-color-interpolate
Browse files Browse the repository at this point in the history
Adding interpolateColors to gouraud primitives.
  • Loading branch information
nicolasnoble authored Oct 23, 2024
2 parents 4b98d6b + d4f7ad6 commit e9dc935
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/mips/psyqo/primitives/common.hh
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ enum SemiTrans { HalfBackAndHalfFront, FullBackAndFullFront, FullBackSubFullFron
enum ColorMode { Tex4Bits, Tex8Bits, Tex16Bits };
} // namespace Prim::TPageAttr

namespace Prim {
enum class Transparency { Auto, Opaque, SemiTransparent };
}

namespace PrimPieces {

/**
Expand Down
86 changes: 86 additions & 0 deletions src/mips/psyqo/primitives/quads.hh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ SOFTWARE.

#include <stdint.h>

#include "psyqo/gte-kernels.hh"
#include "psyqo/gte-registers.hh"
#include "psyqo/primitives/common.hh"

namespace psyqo {
Expand Down Expand Up @@ -188,6 +190,48 @@ struct GouraudQuad {
pointD = v;
return *this;
}
template <Transparency transparency = Transparency::Auto>
void interpolateColors(const Color* a, const Color* b, const Color* c, const Color* d) {
uint32_t rgb;
if constexpr (transparency == Transparency::Auto) {
rgb = (a->packed & 0xffffff) | (command & 0xff000000);
} else if constexpr (transparency == Transparency::Opaque) {
rgb = (a->packed & 0xffffff) | 0x38000000;
} else if constexpr (transparency == Transparency::SemiTransparent) {
rgb = (a->packed & 0xffffff) | 0x3a000000;
}
GTE::write<GTE::Register::RGB, GTE::Safe>(rgb);
GTE::Kernels::dpcs();
GTE::read<GTE::Register::RGB2>(&command);
GTE::write<GTE::Register::RGB0, GTE::Unsafe>(&b->packed);
GTE::write<GTE::Register::RGB1, GTE::Unsafe>(&c->packed);
GTE::write<GTE::Register::RGB2, GTE::Unsafe>(&d->packed);
GTE::Kernels::dpct();
GTE::read<GTE::Register::RGB0>(&colorB.packed);
GTE::read<GTE::Register::RGB1>(&colorC.packed);
GTE::read<GTE::Register::RGB2>(&colorD.packed);
}
template <Transparency transparency = Transparency::Auto>
void interpolateColors(Color a, Color b, Color c, Color d) {
uint32_t rgb;
if constexpr (transparency == Transparency::Auto) {
rgb = (a.packed & 0xffffff) | (command & 0xff000000);
} else if constexpr (transparency == Transparency::Opaque) {
rgb = (a.packed & 0xffffff) | 0x38000000;
} else if constexpr (transparency == Transparency::SemiTransparent) {
rgb = (a.packed & 0xffffff) | 0x3a000000;
}
GTE::write<GTE::Register::RGB, GTE::Safe>(rgb);
GTE::Kernels::dpcs();
GTE::read<GTE::Register::RGB2>(&command);
GTE::write<GTE::Register::RGB0, GTE::Unsafe>(b.packed);
GTE::write<GTE::Register::RGB1, GTE::Unsafe>(c.packed);
GTE::write<GTE::Register::RGB2, GTE::Unsafe>(d.packed);
GTE::Kernels::dpct();
GTE::read<GTE::Register::RGB0>(&colorB.packed);
GTE::read<GTE::Register::RGB1>(&colorC.packed);
GTE::read<GTE::Register::RGB2>(&colorD.packed);
}

private:
uint32_t command;
Expand Down Expand Up @@ -246,6 +290,48 @@ struct GouraudTexturedQuad {
command |= 0x02000000;
return *this;
}
template <Transparency transparency = Transparency::Auto>
void interpolateColors(const Color* a, const Color* b, const Color* c, const Color* d) {
uint32_t rgb;
if constexpr (transparency == Transparency::Auto) {
rgb = (a->packed & 0xffffff) | (command & 0xff000000);
} else if constexpr (transparency == Transparency::Opaque) {
rgb = (a->packed & 0xffffff) | 0x3c000000;
} else if constexpr (transparency == Transparency::SemiTransparent) {
rgb = (a->packed & 0xffffff) | 0x3e000000;
}
GTE::write<GTE::Register::RGB, GTE::Safe>(rgb);
GTE::Kernels::dpcs();
GTE::read<GTE::Register::RGB2>(&command);
GTE::write<GTE::Register::RGB0, GTE::Unsafe>(&b->packed);
GTE::write<GTE::Register::RGB1, GTE::Unsafe>(&c->packed);
GTE::write<GTE::Register::RGB2, GTE::Unsafe>(&d->packed);
GTE::Kernels::dpct();
GTE::read<GTE::Register::RGB0>(&colorB.packed);
GTE::read<GTE::Register::RGB1>(&colorC.packed);
GTE::read<GTE::Register::RGB2>(&colorD.packed);
}
template <Transparency transparency = Transparency::Auto>
void interpolateColors(Color a, Color b, Color c, Color d) {
uint32_t rgb;
if constexpr (transparency == Transparency::Auto) {
rgb = (a.packed & 0xffffff) | (command & 0xff000000);
} else if constexpr (transparency == Transparency::Opaque) {
rgb = (a.packed & 0xffffff) | 0x3c000000;
} else if constexpr (transparency == Transparency::SemiTransparent) {
rgb = (a.packed & 0xffffff) | 0x3e000000;
}
GTE::write<GTE::Register::RGB, GTE::Safe>(rgb);
GTE::Kernels::dpcs();
GTE::read<GTE::Register::RGB2>(&command);
GTE::write<GTE::Register::RGB0, GTE::Unsafe>(b.packed);
GTE::write<GTE::Register::RGB1, GTE::Unsafe>(c.packed);
GTE::write<GTE::Register::RGB2, GTE::Unsafe>(d.packed);
GTE::Kernels::dpct();
GTE::read<GTE::Register::RGB0>(&colorB.packed);
GTE::read<GTE::Register::RGB1>(&colorC.packed);
GTE::read<GTE::Register::RGB2>(&colorD.packed);
}

private:
uint32_t command;
Expand Down
70 changes: 70 additions & 0 deletions src/mips/psyqo/primitives/triangles.hh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ SOFTWARE.

#include <stdint.h>

#include "psyqo/gte-kernels.hh"
#include "psyqo/gte-registers.hh"
#include "psyqo/primitives/common.hh"

namespace psyqo {
Expand Down Expand Up @@ -167,6 +169,40 @@ struct GouraudTriangle {
pointC = v;
return *this;
}
template <Transparency transparency = Transparency::Auto>
void interpolateColors(const Color* a, const Color* b, const Color* c) {
GTE::write<GTE::Register::RGB0, GTE::Unsafe>(&a->packed);
GTE::write<GTE::Register::RGB1, GTE::Unsafe>(&b->packed);
GTE::write<GTE::Register::RGB2, GTE::Unsafe>(&c->packed);
if constexpr (transparency == Transparency::Auto) {
GTE::write<GTE::Register::RGB, GTE::Safe>(&command);
} else if constexpr (transparency == Transparency::Opaque) {
GTE::write<GTE::Register::RGB, GTE::Safe>(0x30000000);
} else if constexpr (transparency == Transparency::SemiTransparent) {
GTE::write<GTE::Register::RGB, GTE::Safe>(0x32000000);
}
GTE::Kernels::dpct();
GTE::read<GTE::Register::RGB0>(&command);
GTE::read<GTE::Register::RGB1>(&colorB.packed);
GTE::read<GTE::Register::RGB2>(&colorC.packed);
}
template <Transparency transparency = Transparency::Auto>
void interpolateColors(Color a, Color b, Color c) {
GTE::write<GTE::Register::RGB0, GTE::Unsafe>(a.packed);
GTE::write<GTE::Register::RGB1, GTE::Unsafe>(b.packed);
GTE::write<GTE::Register::RGB2, GTE::Unsafe>(c.packed);
if constexpr (transparency == Transparency::Auto) {
GTE::write<GTE::Register::RGB, GTE::Safe>(&command);
} else if constexpr (transparency == Transparency::Opaque) {
GTE::write<GTE::Register::RGB, GTE::Safe>(0x30000000);
} else if constexpr (transparency == Transparency::SemiTransparent) {
GTE::write<GTE::Register::RGB, GTE::Safe>(0x32000000);
}
GTE::Kernels::dpct();
GTE::read<GTE::Register::RGB0>(&command);
GTE::read<GTE::Register::RGB1>(&colorB.packed);
GTE::read<GTE::Register::RGB2>(&colorC.packed);
}

private:
uint32_t command;
Expand Down Expand Up @@ -218,6 +254,40 @@ struct GouraudTexturedTriangle {
command |= 0x02000000;
return *this;
}
template <Transparency transparency = Transparency::Auto>
void interpolateColors(const Color* a, const Color* b, const Color* c) {
GTE::write<GTE::Register::RGB0, GTE::Unsafe>(&a->packed);
GTE::write<GTE::Register::RGB1, GTE::Unsafe>(&b->packed);
GTE::write<GTE::Register::RGB2, GTE::Unsafe>(&c->packed);
if constexpr (transparency == Transparency::Auto) {
GTE::write<GTE::Register::RGB, GTE::Safe>(&command);
} else if constexpr (transparency == Transparency::Opaque) {
GTE::write<GTE::Register::RGB, GTE::Safe>(0x34000000);
} else if constexpr (transparency == Transparency::SemiTransparent) {
GTE::write<GTE::Register::RGB, GTE::Safe>(0x36000000);
}
GTE::Kernels::dpct();
GTE::read<GTE::Register::RGB0>(&command);
GTE::read<GTE::Register::RGB1>(&colorB.packed);
GTE::read<GTE::Register::RGB2>(&colorC.packed);
}
template <Transparency transparency = Transparency::Auto>
void interpolateColors(Color a, Color b, Color c) {
GTE::write<GTE::Register::RGB0, GTE::Unsafe>(a.packed);
GTE::write<GTE::Register::RGB1, GTE::Unsafe>(b.packed);
GTE::write<GTE::Register::RGB2, GTE::Unsafe>(c.packed);
if constexpr (transparency == Transparency::Auto) {
GTE::write<GTE::Register::RGB, GTE::Safe>(&command);
} else if constexpr (transparency == Transparency::Opaque) {
GTE::write<GTE::Register::RGB, GTE::Safe>(0x34000000);
} else if constexpr (transparency == Transparency::SemiTransparent) {
GTE::write<GTE::Register::RGB, GTE::Safe>(0x36000000);
}
GTE::Kernels::dpct();
GTE::read<GTE::Register::RGB0>(&command);
GTE::read<GTE::Register::RGB1>(&colorB.packed);
GTE::read<GTE::Register::RGB2>(&colorC.packed);
}

private:
uint32_t command;
Expand Down

0 comments on commit e9dc935

Please sign in to comment.