From a0fed6f756d5784f10f61b3b21b781a86671f717 Mon Sep 17 00:00:00 2001 From: Jaby Date: Wed, 3 Jan 2024 22:07:39 -0600 Subject: [PATCH] Support original GPU test --- .../old/Overlay/GPUTests/gpu_tests.cpp | 192 ------------------ .../src/Overlay/GPUTest/gpu_test.cpp | 149 +++++++++++++- .../Primitives/primitive_support_types.hpp | 4 + include/PSX/GPU/make_gpu_primitives.hpp | 3 + 4 files changed, 155 insertions(+), 193 deletions(-) delete mode 100644 examples/PoolBox/application/old/Overlay/GPUTests/gpu_tests.cpp diff --git a/examples/PoolBox/application/old/Overlay/GPUTests/gpu_tests.cpp b/examples/PoolBox/application/old/Overlay/GPUTests/gpu_tests.cpp deleted file mode 100644 index ccb92147..00000000 --- a/examples/PoolBox/application/old/Overlay/GPUTests/gpu_tests.cpp +++ /dev/null @@ -1,192 +0,0 @@ -#include -#include -#include -#include -#include - -enum LBA { - __jabyengine_start_lba_request - __jabyengine_request_lba_for(FONT, "ASSETS/FONT.BIN"), - __jabyengine_request_lba_for(ICON, "ASSETS/ICON.BIN"), - __jabyengine_end_lba_request -}; - -using namespace JabyEngine; - -// Some default values for the objects -static constexpr auto TriangleColor = GPU::Color24::from_rgb(0x0, 0xFF, 0xFF); -static constexpr auto TriangleArea = Make::AreaI16(Make::PositionI16(0, 0), Make::SizeI16(64, 64)); -static constexpr auto TriangleTPage = Make::TPage(320, 0, GPU::SemiTransparency::B_Half_add_F_Half, GPU::TexturePageColor::$4bit); -static constexpr auto TriangleClut = Make::PageClut(320, 511); - -static constexpr auto RectangleColor = GPU::Color24::from_rgb(0x80, 0x80, 0xFF); -static constexpr auto RectangleArea = Make::AreaI16(Make::PositionI16(0, TriangleArea.size.height), Make::SizeI16(80, 80)); -static constexpr auto RectangleTPage = Make::TPage(320, 256, GPU::SemiTransparency::B_Half_add_F_Half, GPU::TexturePageColor::$4bit); -static constexpr auto RectangleClut = Make::PageClut(320, 510); - -static constexpr auto LineColor = GPU::Color24::from_rgb(0xFF, 0x0, 0x0); - -static constexpr const auto triangle1 = Make::POLY_F3({ - Make::Vertex(TriangleArea.position.x, TriangleArea.position.y), - Make::Vertex(TriangleArea.size.width, TriangleArea.size.height), - Make::Vertex(TriangleArea.position.x, TriangleArea.size.height) - }, TriangleColor -); -static constexpr const auto triangle2 = Make::POLY_FT3({ - Make::Vertex(TriangleArea.position.x, TriangleArea.position.y), - Make::Vertex(TriangleArea.size.width, TriangleArea.position.y), - Make::Vertex(TriangleArea.size.width, TriangleArea.size.height) - },{ - // Texture - Make::PageOffset(TriangleArea.position.x, TriangleArea.position.y), - Make::PageOffset(TriangleArea.size.width, TriangleArea.position.y), - Make::PageOffset(TriangleArea.size.width, TriangleArea.size.height) - }, TriangleTPage, TriangleClut, GPU::Color24::Grey() -); -static constexpr const auto triangle3 = Make::POLY_G3({ - {triangle1.vertex0.move(TriangleArea.size.width, 0), GPU::Color24::Red()}, - {triangle1.vertex1.move(TriangleArea.size.width, 0), GPU::Color24::Green()}, - {triangle1.vertex2.move(TriangleArea.size.width, 0), GPU::Color24::Blue()}} -); -static constexpr const auto triangle4 = Make::POLY_GT3({ - {triangle2.vertex0.move(TriangleArea.size.width, 0), triangle2.tex_offset0, GPU::Color24::Red()}, - {triangle2.vertex1.move(TriangleArea.size.width, 0), triangle2.tex_offset1, GPU::Color24::Blue()}, - {triangle2.vertex2.move(TriangleArea.size.width, 0), triangle2.tex_offset2, GPU::Color24::Green()}}, - TriangleTPage, - TriangleClut -); - -static constexpr const auto rectangle1 = Make::POLY_F4(RectangleArea, RectangleColor); -static constexpr const auto rectangle2 = Make::POLY_FT4(Make::AreaI16( - RectangleArea.position.move(RectangleArea.size.width, 0), RectangleArea.size), Make::PageOffset(0, 0), - RectangleTPage, - RectangleClut, - GPU::Color24::Grey() -); -static constexpr const auto rectangle3 = Make::POLY_G4( - {RectangleArea.position.move(RectangleArea.size.width*2, 0), RectangleArea.size}, { - GPU::Color24::Red(), - GPU::Color24::Blue(), - GPU::Color24::Green(), - GPU::Color24::White()}); -static constexpr const auto rectangle4 = Make::POLY_GT4(Make::AreaI16( - RectangleArea.position.move(RectangleArea.size.width*3, 0), RectangleArea.size), Make::PageOffset(0, 0), - RectangleTPage, - RectangleClut, { - GPU::Color24::Red(), - GPU::Color24::Blue(), - GPU::Color24::Green(), - GPU::Color24::White()} -); -static constexpr const auto rectangle5 = Make::POLY_GT4(Make::AreaI16( - RectangleArea.position.move(0, RectangleArea.size.height), RectangleArea.size), Make::PageOffset(0, 0), - RectangleTPage, - RectangleClut, { - GPU::Color24::Red(), - GPU::Color24::Blue(), - GPU::Color24::Green(), - GPU::Color24::White()} -).set_semi_transparent(true); - -static constexpr const auto line1 = Make::LINE_F(LineColor, - Make::Vertex(0, 0), - Make::Vertex(GPU::Display::Width, GPU::Display::Height) -); -static constexpr const auto line2 = Make::LINE_F(LineColor.invert(), - Make::Vertex(0, 0), - Make::Vertex(16, 0), - Make::Vertex(16, 16), - Make::Vertex(0, 0) -); -static constexpr const auto line3 = Make::LINE_G( - GPU::ColorVertex{LineColor, Make::Vertex(GPU::Display::Width, 0)}, - GPU::ColorVertex{LineColor.invert(), Make::Vertex(0, GPU::Display::Height)} -); -static constexpr const auto line4 = Make::LINE_G( - GPU::ColorVertex{GPU::Color24::Red(), Make::Vertex(0, 0)}, - GPU::ColorVertex{GPU::Color24::Green(), Make::Vertex(0, 16)}, - GPU::ColorVertex{GPU::Color24::Blue(), Make::Vertex(16, 16)}, - GPU::ColorVertex{GPU::Color24::White(), Make::Vertex(0, 0)} -); - -static constexpr const auto rect1 = Make::TILE(Make::AreaI16(Make::PositionI16(GPU::Display::Width - 32, GPU::Display::Height - 32), Make::SizeI16(32, 32)), GPU::Color24::Green()); -static constexpr const auto rect2 = Make::TILE_16(Make::PositionI16(GPU::Display::Width - 16, GPU::Display::Height - 16), GPU::Color24::Blue()); -static constexpr const auto rect3 = Make::TILE_8(Make::PositionI16(GPU::Display::Width - 8, GPU::Display::Height - 8), GPU::Color24::Yellow()); -static constexpr const auto rect4 = Make::TILE_1(Make::PositionI16(GPU::Display::Width - 1, GPU::Display::Height - 1), GPU::Color24::Red()); - -static constexpr const auto texpage = Make::TexPage(Make::PositionU16(320, 0), GPU::TexturePageColor::$4bit); -static constexpr const auto rect5 = Make::SPRT(Make::AreaI16(Make::PositionI16(0, GPU::Display::Height - 32), Make::SizeI16(32, 32)), {Make::PageOffset(0, 0), TriangleClut}, GPU::Color24::Green()); -static constexpr const auto rect6 = Make::SPRT_16(Make::Vertex(0, GPU::Display::Height - 16), Make::OffsetPageWithClut(Make::PageOffset(0, 0), TriangleClut), GPU::Color24::Blue()); -static constexpr const auto rect7 = Make::SPRT_8(Make::Vertex(0, GPU::Display::Height - 8), Make::OffsetPageWithClut(Make::PageOffset(0, 0), TriangleClut), GPU::Color24::Yellow()); -static constexpr const auto rect8 = Make::SPRT_1(Make::Vertex(0, GPU::Display::Height - 1), Make::OffsetPageWithClut(Make::PageOffset(0, 0), TriangleClut), GPU::Color24::Red()); - -static auto rect9 = Make::SPRT(Make::AreaI16(Make::PositionI16(GPU::Display::Width/2, GPU::Display::Height/2), Make::SizeI16(32, 32)).centered(), Make::OffsetPageWithClut(Make::PageOffset(0, 0), TriangleClut), GPU::Color24::Grey()).linked(); -static auto rect10 = Make::SPRT(Make::AreaI16(Make::PositionI16(GPU::Display::Width/2, GPU::Display::Height/2 - 32), Make::SizeI16(32, 32)).centered(), Make::OffsetPageWithClut(Make::PageOffset(0, 0), TriangleClut), GPU::Color24::Grey()).linked(); - -static void load_assets() { - static const CDFile Assets[] = { - CDFileBuilder::simple_tim(LBA::FONT, SimpleTIM(320, 0, 320, 511)), - CDFileBuilder::simple_tim(LBA::ICON, SimpleTIM(320, 256, 320, 510)), - }; - - const auto buffer_cfg = CDFileProcessor::BufferConfiguration::new_default(); - CDFileProcessor file_processor; - - file_processor.setup(lba, Assets, buffer_cfg); - while(true) { - switch(file_processor.process()) { - case Progress::InProgress: - break; - - case Progress::Done: - if(!file_processor.next(lba, buffer_cfg)) { - return; - } - break; - - case Progress::Error: - printf("Error detected! Aborting load\n"); - return; - } - } - printf("Done loading assets!\n"); -} - -void test_gpu() { - load_assets(); - - rect9.concat(rect10); - - while(true) { - GPU::render(triangle1); - GPU::render(triangle2); - GPU::render(triangle3); - GPU::render(triangle4); - - GPU::render(rectangle1); - GPU::render(rectangle2); - GPU::render(rectangle3); - GPU::render(rectangle4); - GPU::render(rectangle5); - - GPU::render(rect1); - GPU::render(rect2); - GPU::render(rect3); - GPU::render(rect4); - GPU::render(texpage); - GPU::render(rect5); - GPU::render(rect6); - GPU::render(rect7); - GPU::render(rect8); - - GPU::render(line1); - GPU::render(line2); - GPU::render(line3); - GPU::render(line4); - - GPU::render(rect9); - - GPU::swap_buffers_vsync(2); - } -} -__declare_lba_header(LBA); \ No newline at end of file diff --git a/examples/PoolBox/application/src/Overlay/GPUTest/gpu_test.cpp b/examples/PoolBox/application/src/Overlay/GPUTest/gpu_test.cpp index fc9bd348..b1ee5aa3 100644 --- a/examples/PoolBox/application/src/Overlay/GPUTest/gpu_test.cpp +++ b/examples/PoolBox/application/src/Overlay/GPUTest/gpu_test.cpp @@ -1,7 +1,154 @@ +#include "include/gpu_test_assets.hpp" +#include +#include #include namespace GPUTest { + using namespace JabyEngine; + + // Some default values for the objects + static constexpr auto TriangleColor = GPU::Color24::from_rgb(0x0, 0xFF, 0xFF); + static constexpr auto TriangleArea = Make::AreaI16(Make::PositionI16(0, 0), Make::SizeI16(64, 64)); + static constexpr auto TriangleTPage = Make::TPage(TexPageTIM.get_texture_position(), GPU::SemiTransparency::B_Half_add_F_Half, GPU::TexturePageColor::$4bit); + static constexpr auto TriangleClut = Make::PageClut(TexPageTIM.get_clut_position()); + + static constexpr auto RectangleColor = GPU::Color24::from_rgb(0x80, 0x80, 0xFF); + static constexpr auto RectangleArea = Make::AreaI16(Make::PositionI16(0, TriangleArea.size.height), Make::SizeI16(80, 80)); + static constexpr auto RectangleTPage = Make::TPage(IconTIM.get_texture_position(), GPU::SemiTransparency::B_Half_add_F_Half, GPU::TexturePageColor::$4bit); + static constexpr auto RectangleClut = Make::PageClut(IconTIM.get_clut_position()); + + static constexpr auto LineColor = GPU::Color24::from_rgb(0xFF, 0x0, 0x0); + + static constexpr const auto triangle1 = Make::POLY_F3({ + Make::Vertex(TriangleArea.position.x, TriangleArea.position.y), + Make::Vertex(TriangleArea.size.width, TriangleArea.size.height), + Make::Vertex(TriangleArea.position.x, TriangleArea.size.height) + }, TriangleColor + ); + static constexpr const auto triangle2 = Make::POLY_FT3({ + Make::Vertex(TriangleArea.position.x, TriangleArea.position.y), + Make::Vertex(TriangleArea.size.width, TriangleArea.position.y), + Make::Vertex(TriangleArea.size.width, TriangleArea.size.height) + },{ + // Texture + Make::PageOffset(TriangleArea.position.x, TriangleArea.position.y), + Make::PageOffset(TriangleArea.size.width, TriangleArea.position.y), + Make::PageOffset(TriangleArea.size.width, TriangleArea.size.height) + }, TriangleTPage, TriangleClut, GPU::Color24::Grey() + ); + static constexpr const auto triangle3 = Make::POLY_G3({ + {triangle1.vertex0.move(TriangleArea.size.width, 0), GPU::Color24::Red()}, + {triangle1.vertex1.move(TriangleArea.size.width, 0), GPU::Color24::Green()}, + {triangle1.vertex2.move(TriangleArea.size.width, 0), GPU::Color24::Blue()}} + ); + static constexpr const auto triangle4 = Make::POLY_GT3({ + {triangle2.vertex0.move(TriangleArea.size.width, 0), triangle2.tex_offset0, GPU::Color24::Red()}, + {triangle2.vertex1.move(TriangleArea.size.width, 0), triangle2.tex_offset1, GPU::Color24::Blue()}, + {triangle2.vertex2.move(TriangleArea.size.width, 0), triangle2.tex_offset2, GPU::Color24::Green()}}, + TriangleTPage, + TriangleClut + ); + + static constexpr const auto rectangle1 = Make::POLY_F4(RectangleArea, RectangleColor); + static constexpr const auto rectangle2 = Make::POLY_FT4(Make::AreaI16( + RectangleArea.position.move(RectangleArea.size.width, 0), RectangleArea.size), Make::PageOffset(0, 0), + RectangleTPage, + RectangleClut, + GPU::Color24::Grey() + ); + static constexpr const auto rectangle3 = Make::POLY_G4( + {RectangleArea.position.move(RectangleArea.size.width*2, 0), RectangleArea.size}, { + GPU::Color24::Red(), + GPU::Color24::Blue(), + GPU::Color24::Green(), + GPU::Color24::White()}); + static constexpr const auto rectangle4 = Make::POLY_GT4(Make::AreaI16( + RectangleArea.position.move(RectangleArea.size.width*3, 0), RectangleArea.size), Make::PageOffset(0, 0), + RectangleTPage, + RectangleClut, { + GPU::Color24::Red(), + GPU::Color24::Blue(), + GPU::Color24::Green(), + GPU::Color24::White()} + ); + static constexpr const auto rectangle5 = Make::POLY_GT4(Make::AreaI16( + RectangleArea.position.move(0, RectangleArea.size.height), RectangleArea.size), Make::PageOffset(0, 0), + RectangleTPage, + RectangleClut, { + GPU::Color24::Red(), + GPU::Color24::Blue(), + GPU::Color24::Green(), + GPU::Color24::White()} + ).set_semi_transparent(true); + + static constexpr const auto line1 = Make::LINE_F(LineColor, + Make::Vertex(0, 0), + Make::Vertex(GPU::Display::Width, GPU::Display::Height) + ); + static constexpr const auto line2 = Make::LINE_F(LineColor.invert(), + Make::Vertex(0, 0), + Make::Vertex(16, 0), + Make::Vertex(16, 16), + Make::Vertex(0, 0) + ); + static constexpr const auto line3 = Make::LINE_G( + GPU::ColorVertex{LineColor, Make::Vertex(GPU::Display::Width, 0)}, + GPU::ColorVertex{LineColor.invert(), Make::Vertex(0, GPU::Display::Height)} + ); + static constexpr const auto line4 = Make::LINE_G( + GPU::ColorVertex{GPU::Color24::Red(), Make::Vertex(0, 0)}, + GPU::ColorVertex{GPU::Color24::Green(), Make::Vertex(0, 16)}, + GPU::ColorVertex{GPU::Color24::Blue(), Make::Vertex(16, 16)}, + GPU::ColorVertex{GPU::Color24::White(), Make::Vertex(0, 0)} + ); + + static constexpr const auto rect1 = Make::TILE(Make::AreaI16(Make::PositionI16(GPU::Display::Width - 32, GPU::Display::Height - 32), Make::SizeI16(32, 32)), GPU::Color24::Green()); + static constexpr const auto rect2 = Make::TILE_16(Make::PositionI16(GPU::Display::Width - 16, GPU::Display::Height - 16), GPU::Color24::Blue()); + static constexpr const auto rect3 = Make::TILE_8(Make::PositionI16(GPU::Display::Width - 8, GPU::Display::Height - 8), GPU::Color24::Yellow()); + static constexpr const auto rect4 = Make::TILE_1(Make::PositionI16(GPU::Display::Width - 1, GPU::Display::Height - 1), GPU::Color24::Red()); + + static constexpr const auto texpage = Make::TexPage(TexPageTIM.get_texture_position(), GPU::TexturePageColor::$4bit); + static constexpr const auto rect5 = Make::SPRT(Make::AreaI16(Make::PositionI16(0, GPU::Display::Height - 32), Make::SizeI16(32, 32)), {Make::PageOffset(0, 0), TriangleClut}, GPU::Color24::Green()); + static constexpr const auto rect6 = Make::SPRT_16(Make::Vertex(0, GPU::Display::Height - 16), Make::OffsetPageWithClut(Make::PageOffset(0, 0), TriangleClut), GPU::Color24::Blue()); + static constexpr const auto rect7 = Make::SPRT_8(Make::Vertex(0, GPU::Display::Height - 8), Make::OffsetPageWithClut(Make::PageOffset(0, 0), TriangleClut), GPU::Color24::Yellow()); + static constexpr const auto rect8 = Make::SPRT_1(Make::Vertex(0, GPU::Display::Height - 1), Make::OffsetPageWithClut(Make::PageOffset(0, 0), TriangleClut), GPU::Color24::Red()); + + static auto rect9 = Make::SPRT(Make::AreaI16(Make::PositionI16(GPU::Display::Width/2, GPU::Display::Height/2), Make::SizeI16(32, 32)).centered(), Make::OffsetPageWithClut(Make::PageOffset(0, 0), TriangleClut), GPU::Color24::Grey()).linked(); + static auto rect10 = Make::SPRT(Make::AreaI16(Make::PositionI16(GPU::Display::Width/2, GPU::Display::Height/2 - 32), Make::SizeI16(32, 32)).centered(), Make::OffsetPageWithClut(Make::PageOffset(0, 0), TriangleClut), GPU::Color24::Grey()).linked(); + void main() { - printf("GPU: BlubbBlubbBlubb!!\n"); + rect9.concat(rect10); + + while(true) { + GPU::render(triangle1); + GPU::render(triangle2); + GPU::render(triangle3); + GPU::render(triangle4); + + GPU::render(rectangle1); + GPU::render(rectangle2); + GPU::render(rectangle3); + GPU::render(rectangle4); + GPU::render(rectangle5); + + GPU::render(rect1); + GPU::render(rect2); + GPU::render(rect3); + GPU::render(rect4); + GPU::render(texpage); + GPU::render(rect5); + GPU::render(rect6); + GPU::render(rect7); + GPU::render(rect8); + + GPU::render(line1); + GPU::render(line2); + GPU::render(line3); + GPU::render(line4); + + GPU::render(rect9); + + GPU::swap_buffers_vsync(2); + } } } diff --git a/include/PSX/GPU/Primitives/primitive_support_types.hpp b/include/PSX/GPU/Primitives/primitive_support_types.hpp index 3eb9c8f1..916be67f 100644 --- a/include/PSX/GPU/Primitives/primitive_support_types.hpp +++ b/include/PSX/GPU/Primitives/primitive_support_types.hpp @@ -89,6 +89,10 @@ namespace JabyEngine { static constexpr TPage create(uint16_t x, uint16_t y, ::JabyEngine::GPU::SemiTransparency transparency, TexturePageColor clut_color) { return TPage{static_cast(TexturePageX.as_value(x >> 6) | TexturePageY.as_value(y >> 8) | SemiTransparency.as_value(static_cast(transparency)) | TextureClut.as_value(static_cast(clut_color)))}; } + + static constexpr TPage create(const PositionU16& pos, ::JabyEngine::GPU::SemiTransparency transparency, TexturePageColor clut_color) { + return TPage::create(pos.x, pos.y, transparency, clut_color); + } }; } } \ No newline at end of file diff --git a/include/PSX/GPU/make_gpu_primitives.hpp b/include/PSX/GPU/make_gpu_primitives.hpp index fd5d28cd..e9ea094b 100644 --- a/include/PSX/GPU/make_gpu_primitives.hpp +++ b/include/PSX/GPU/make_gpu_primitives.hpp @@ -127,6 +127,9 @@ namespace JabyEngine { static constexpr GPU::TPage TPage(uint16_t x, uint16_t y, GPU::SemiTransparency transparency, GPU::TexturePageColor clut_color) { return creator_template(x, y, transparency, clut_color); } + static constexpr GPU::TPage TPage(const GPU::PositionU16& tex_pos, GPU::SemiTransparency transparency, GPU::TexturePageColor clut_color) { + return creator_template(tex_pos, transparency, clut_color); + } // ###################################################################