diff --git a/examples/PoolBox/application/src/main.cpp b/examples/PoolBox/application/src/main.cpp index cc0d3653..4f7be4fd 100644 --- a/examples/PoolBox/application/src/main.cpp +++ b/examples/PoolBox/application/src/main.cpp @@ -13,8 +13,8 @@ enum LBA { static void load_assets() { static const JabyEngine::CDFile Assets[] = { - JabyEngine::CDFileBuilder::simple_tim(LBA::FONT, JabyEngine::SimpleTIM(320, 0, 320, 510)), - JabyEngine::CDFileBuilder::simple_tim(LBA::ICON, JabyEngine::SimpleTIM(320, 256, 320, 511)), + JabyEngine::CDFileBuilder::simple_tim(LBA::FONT, JabyEngine::SimpleTIM(320, 0, 320, 511)), + JabyEngine::CDFileBuilder::simple_tim(LBA::ICON, JabyEngine::SimpleTIM(320, 256, 320, 510)), }; const auto buffer_cfg = JabyEngine::CDFileProcessor::BufferConfiguration::new_default(); @@ -44,12 +44,12 @@ void main() { static constexpr auto TriangleColor = JabyEngine::GPU::Color24(0x0, 0xFF, 0xFF); static constexpr auto TriangleArea = JabyEngine::GPU::AreaI16({0, 0}, {64, 64}); static constexpr auto TriangleTPage = JabyEngine::GPU::TPage(320, 0, JabyEngine::GPU::SemiTransparency::B_Half_add_F_Half, JabyEngine::GPU::TexturePageColor::$4bit); - static constexpr auto TriangleClut = JabyEngine::GPU::PageClut(320, 510); + static constexpr auto TriangleClut = JabyEngine::GPU::PageClut(320, 511); static constexpr auto RectangleColor = JabyEngine::GPU::Color24(0x80, 0x80, 0xFF); static constexpr auto RectangleArea = JabyEngine::GPU::AreaI16({0, TriangleArea.size.height}, {80, 80}); static constexpr auto RectangleTPage = JabyEngine::GPU::TPage(320, 256, JabyEngine::GPU::SemiTransparency::B_Half_add_F_Half, JabyEngine::GPU::TexturePageColor::$4bit); - static constexpr auto RectangleClut = JabyEngine::GPU::PageClut(320, 511); + static constexpr auto RectangleClut = JabyEngine::GPU::PageClut(320, 510); const JabyEngine::GPU::POLY_F3 triangle1({ {TriangleArea.position.x, TriangleArea.position.y}, @@ -67,7 +67,7 @@ void main() { {TriangleArea.size.width, TriangleArea.size.height}}, TriangleTPage, TriangleClut, - JabyEngine::GPU::Color24::White() + JabyEngine::GPU::Color24::Grey() ); const JabyEngine::GPU::POLY_G3 triangle3({ {triangle1.vertex0.move(TriangleArea.size.width, 0), JabyEngine::GPU::Color24::Red()}, @@ -82,7 +82,13 @@ void main() { TriangleClut ); - const JabyEngine::GPU::POLY_F4 rectangle(RectangleArea, RectangleColor); + const JabyEngine::GPU::POLY_F4 rectangle1(RectangleArea, RectangleColor); + const JabyEngine::GPU::POLY_FT4 rectangle2({ + RectangleArea.position.move(RectangleArea.size.width, 0), RectangleArea.size}, {0, 0}, + RectangleTPage, + RectangleClut, + JabyEngine::GPU::Color24::Grey() + ); load_assets(); @@ -92,7 +98,8 @@ void main() { JabyEngine::GPU::render(triangle3); JabyEngine::GPU::render(triangle4); - JabyEngine::GPU::render(rectangle); + JabyEngine::GPU::render(rectangle1); + JabyEngine::GPU::render(rectangle2); JabyEngine::GPU::swap_buffers_vsync(2); } diff --git a/include/PSX/GPU/gpu_primitives.hpp b/include/PSX/GPU/gpu_primitives.hpp index c61f229b..db0e357f 100644 --- a/include/PSX/GPU/gpu_primitives.hpp +++ b/include/PSX/GPU/gpu_primitives.hpp @@ -84,7 +84,7 @@ namespace JabyEngine { uint16_t value = 0; constexpr PageClut() = default; - constexpr PageClut(uint16_t x, uint16_t y) : value((y <<6 ) | ((x >> 4) & 0x3f)) { + constexpr PageClut(uint16_t x, uint16_t y) : value((y << 6) | ((x >> 4) & 0x3f)) { } }; @@ -142,7 +142,7 @@ namespace JabyEngine { TPage tpage; // e Vertex vertex2; // f PagePosition page2; // g - uint16_t padded; // g + uint16_t padded2; // g constexpr POLY_FT3() = default; constexpr POLY_FT3(const Vertex (&verticies)[3], const PagePosition (&page_pos)[3], TPage tpage, PageClut clut, Color24 color) : @@ -220,6 +220,13 @@ namespace JabyEngine { color2(verticies_ex[2].color), vertex2(verticies_ex[2].position), page2(verticies_ex[2].page) {} }; + + + /* + 1 - 2 + | | + 3 - 4 + */ struct POLY_F4 : public internal::IsPrimitive, public internal::CodeInterface { static constexpr auto IdentityCode = Code(POLY_F3::IdentityCode).set(Code::QuadVertics); @@ -245,19 +252,62 @@ namespace JabyEngine { color) {} }; + struct POLY_FT4 : public internal::IsPrimitive, public internal::CodeInterface { + typedef POLY_FT3::VertexEx VertexEx; + static constexpr auto IdentityCode = Code(POLY_FT3::IdentityCode).set(Code::QuadVertics); + + Color24 color; // a + Code code = IdentityCode; // a + Vertex vertex0; // b + PagePosition page0; // c + PageClut page_clut; // c + Vertex vertex1; // d + PagePosition page1; // e + TPage tpage; // e + Vertex vertex2; // f + PagePosition page2; // g + uint16_t padded2; // g + Vertex vertex3; // h + PagePosition page3; // i + uint16_t padded3; // i + + constexpr POLY_FT4() = default; + constexpr POLY_FT4(const Vertex (&verticies)[4], const PagePosition (&page_pos)[4], TPage tpage, PageClut clut, Color24 color) : + color(color), code(IdentityCode), + vertex0(verticies[0]), page0(page_pos[0]), page_clut(clut), + vertex1(verticies[1]), page1(page_pos[1]), tpage(tpage), + vertex2(verticies[2]), page2(page_pos[2]), + vertex3(verticies[3]), page3(page_pos[3]) {} + constexpr POLY_FT4(const VertexEx (&vertices_ex)[4], TPage tpage, PageClut clut, Color24 color) : + color(color), code(IdentityCode), + vertex0(vertices_ex[0].position), page0(vertices_ex[0].page), page_clut(clut), + vertex1(vertices_ex[1].position), page1(vertices_ex[1].page), tpage(tpage), + vertex2(vertices_ex[2].position), page2(vertices_ex[2].page), + vertex3(vertices_ex[3].position), page3(vertices_ex[3].page) {} + constexpr POLY_FT4(const AreaI16& area, const PagePosition& texture_pos, TPage tpage, PageClut clut, Color24 color) : POLY_FT4({ + {area.position, texture_pos}, + {area.position.move(area.size.width, 0), texture_pos.move(area.size.width, 0)}, + {area.position.move(0, area.size.height), texture_pos.move(0, area.size.height)}, + {area.position.move(area.size.width, area.size.height), texture_pos.move(area.size.width, area.size.height)}}, + tpage, clut, color + ) {} + }; + typedef POLY_F3 FlatTriangle; typedef POLY_FT3 FlatTexturedTriangle; typedef POLY_G3 GouraudTriangle; typedef POLY_GT3 GouraudTexturedTriangle; - typedef POLY_F4 FlatRectangle; + typedef POLY_F4 FlatRectangle; + typedef POLY_FT4 FlatTexturedRectangle; static_assert(sizeof(POLY_F3) == 16); static_assert(sizeof(POLY_FT3) == 28); static_assert(sizeof(POLY_G3) == 24); static_assert(sizeof(POLY_GT3) == 36); - static_assert(sizeof(POLY_F4) == 20); + static_assert(sizeof(POLY_F4) == 20); + static_assert(sizeof(POLY_FT4) == 36); } } diff --git a/include/PSX/GPU/gpu_types.hpp b/include/PSX/GPU/gpu_types.hpp index 2219b1cc..c03cc3c9 100644 --- a/include/PSX/GPU/gpu_types.hpp +++ b/include/PSX/GPU/gpu_types.hpp @@ -5,6 +5,33 @@ namespace JabyEngine { namespace GPU { + namespace internal { + template + struct XYMovement { + constexpr T& add(S dx, S dy) { + static_cast(this)->x += dx; + static_cast(this)->y += dy; + + return *static_cast(this); + } + + constexpr T& sub(S dx, S dy) { + static_cast(this)->x -= dx; + static_cast(this)->y -= dy; + + return *static_cast(this); + } + + constexpr T& move(S dx, S dy) { + return this->add(dx, dy); + } + + constexpr T move(S dx, S dy) const { + return T(static_cast(this)->x, static_cast(this)->y).move(dx, dy); + } + }; + } + struct Color24 { uint8_t red = 0; uint8_t green = 0; @@ -22,6 +49,10 @@ namespace JabyEngine { return Color24(0, 0, 0); } + static constexpr Color24 Grey() { + return Color24(0x80, 0x80, 0x80); + } + static constexpr Color24 White() { return Color24(0xFF, 0xFF, 0xFF); } @@ -74,24 +105,13 @@ namespace JabyEngine { }; template - struct Position { + struct Position : public internal::XYMovement, T> { T x = 0; T y = 0; constexpr Position() = default; constexpr Position(T x, T y) : x(x), y(y) { } - - constexpr Position& move(T dx, T dy) { - this->x += dx; - this->y += dy; - - return *this; - } - - constexpr Position move(T dx, T dy) const { - return Position(this->x, this->y).move(dx, dy); - } }; template @@ -117,9 +137,15 @@ namespace JabyEngine { }; // Type used for primitives - struct PagePosition { - uint8_t u = 0; - uint8_t v = 0; + struct PagePosition : public internal::XYMovement { + union { + uint8_t u = 0; + uint8_t x; + }; + union { + uint8_t v = 0; + uint8_t y; + }; constexpr PagePosition() = default; constexpr PagePosition(uint8_t u, uint8_t v) : u(u), v(v) {