diff --git a/include/PSX/GPU/Primitives/primitive_poly_types.hpp b/include/PSX/GPU/Primitives/primitive_poly_types.hpp index 945a9c2b..8c155fbd 100644 --- a/include/PSX/GPU/Primitives/primitive_poly_types.hpp +++ b/include/PSX/GPU/Primitives/primitive_poly_types.hpp @@ -32,6 +32,35 @@ namespace JabyEngine { return *static_cast(this); } }; + + template + struct Poly3Interface {}; + + template + struct Poly4Interface { + constexpr T& set_rect_size(const SizeI16& size) { + static_cast(this)->vertex1 = static_cast(this)->vertex0.add(size.width, 0); + static_cast(this)->vertex2 = static_cast(this)->vertex0.add(0, size.height); + static_cast(this)->vertex3 = static_cast(this)->vertex0.add(size.width, size.height); + + return *static_cast(this); + } + + constexpr T& set_rect_size_fast(const SizeI16& size) { + static_cast(this)->vertex1.x = static_cast(this)->vertex0.x + size.width; + static_cast(this)->vertex2.y = static_cast(this)->vertex0.y + size.height; + static_cast(this)->vertex3 = static_cast(this)->vertex0.add(size.width, size.height); + + return *static_cast(this); + } + + constexpr SizeI16 get_rect_size() const { + return SizeI16::create( + static_cast(this)->vertex1.x - static_cast(this)->vertex0.x, + static_cast(this)->vertex2.y - static_cast(this)->vertex0.y + ); + } + }; } /* @@ -39,9 +68,9 @@ namespace JabyEngine { / \ 3 - 2 */ - struct POLY_F3 : public internal::RenderPrimitive, public internal::PolyCodeInterface, public internal::LinkedElementCreator { + struct POLY_F3 : public internal::RenderPrimitive, public internal::PolyCodeInterface, public internal::Poly3Interface, public internal::LinkedElementCreator { static constexpr auto IdentityCode = Code::create().set(Code::FlatShading).set(Code::TriVertics).set(Code::Untextured).set(Code::NonTransparent); - + Color24 color; // a Code code; // a Vertex vertex0; // b @@ -58,7 +87,7 @@ namespace JabyEngine { } }; - struct POLY_FT3 : public internal::RenderPrimitive, public internal::PolyCodeInterface, public internal::LinkedElementCreator { + struct POLY_FT3 : public internal::RenderPrimitive, public internal::PolyCodeInterface, public internal::Poly3Interface, public internal::LinkedElementCreator { struct VertexEx { Vertex position; PageOffset tex_offset; @@ -94,7 +123,7 @@ namespace JabyEngine { } }; - struct POLY_G3 : public internal::RenderPrimitive, public internal::PolyCodeInterface, public internal::LinkedElementCreator { + struct POLY_G3 : public internal::RenderPrimitive, public internal::PolyCodeInterface, public internal::Poly3Interface, public internal::LinkedElementCreator { static constexpr auto IdentityCode = Code(POLY_F3::IdentityCode).set(Code::GouraudShading); Color24 color0; // a @@ -124,7 +153,7 @@ namespace JabyEngine { } }; - struct POLY_GT3 : public internal::RenderPrimitive, public internal::PolyCodeInterface, public internal::LinkedElementCreator { + struct POLY_GT3 : public internal::RenderPrimitive, public internal::PolyCodeInterface, public internal::Poly3Interface, public internal::LinkedElementCreator { struct VertexEx { Vertex position; PageOffset tex_offset; @@ -170,7 +199,7 @@ namespace JabyEngine { | | 3 - 4 */ - struct POLY_F4 : public internal::RenderPrimitive, public internal::PolyCodeInterface, public internal::LinkedElementCreator { + struct POLY_F4 : public internal::RenderPrimitive, public internal::PolyCodeInterface, public internal::Poly4Interface, public internal::LinkedElementCreator { static constexpr auto IdentityCode = Code(POLY_F3::IdentityCode).set(Code::QuadVertics); Color24 color; // a @@ -200,7 +229,7 @@ namespace JabyEngine { } }; - struct POLY_FT4 : public internal::RenderPrimitive, public internal::PolyCodeInterface, public internal::LinkedElementCreator { + struct POLY_FT4 : public internal::RenderPrimitive, public internal::PolyCodeInterface, public internal::Poly4Interface, public internal::LinkedElementCreator { typedef POLY_FT3::VertexEx VertexEx; static constexpr auto IdentityCode = Code(POLY_FT3::IdentityCode).set(Code::QuadVertics); @@ -248,7 +277,7 @@ namespace JabyEngine { } }; - struct POLY_G4 : public internal::RenderPrimitive, public internal::PolyCodeInterface, public internal::LinkedElementCreator { + struct POLY_G4 : public internal::RenderPrimitive, public internal::PolyCodeInterface, public internal::Poly4Interface, public internal::LinkedElementCreator { static constexpr auto IdentityCode = Code(POLY_G3::IdentityCode).set(Code::QuadVertics); Color24 color0; // a @@ -292,7 +321,7 @@ namespace JabyEngine { } }; - struct POLY_GT4 : public internal::RenderPrimitive, public internal::PolyCodeInterface, public internal::LinkedElementCreator { + struct POLY_GT4 : public internal::RenderPrimitive, public internal::PolyCodeInterface, public internal::Poly4Interface, public internal::LinkedElementCreator { typedef POLY_GT3::VertexEx VertexEx; static constexpr auto IdentityCode = Code(POLY_GT3::IdentityCode).set(Code::QuadVertics);