From 16cca95d9b441d5c59f47b281166b9cf3d96fb8a Mon Sep 17 00:00:00 2001 From: Jaby Date: Tue, 30 May 2023 22:06:38 +0200 Subject: [PATCH] Support RectF --- examples/PoolBox/application/src/main.cpp | 162 ++++++++++-------- .../GPU/Primitives/primitive_line_types.hpp | 15 +- .../GPU/Primitives/primitive_poly_types.hpp | 20 +-- .../Primitives/primitive_rectangle_types.hpp | 65 +++++++ .../Primitives/primitive_support_types.hpp | 24 +++ include/PSX/GPU/gpu_primitives.hpp | 1 + include/PSX/GPU/gpu_types.hpp | 4 + 7 files changed, 187 insertions(+), 104 deletions(-) create mode 100644 include/PSX/GPU/Primitives/primitive_rectangle_types.hpp diff --git a/examples/PoolBox/application/src/main.cpp b/examples/PoolBox/application/src/main.cpp index 3cb85b96..a788a404 100644 --- a/examples/PoolBox/application/src/main.cpp +++ b/examples/PoolBox/application/src/main.cpp @@ -11,26 +11,28 @@ enum LBA { __jabyengine_end_lba_request }; +using namespace JabyEngine; + // Some default values for the objects -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, 511); +static constexpr auto TriangleColor = GPU::Color24(0x0, 0xFF, 0xFF); +static constexpr auto TriangleArea = GPU::AreaI16({0, 0}, {64, 64}); +static constexpr auto TriangleTPage = GPU::TPage(320, 0, GPU::SemiTransparency::B_Half_add_F_Half, GPU::TexturePageColor::$4bit); +static constexpr auto TriangleClut = 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, 510); +static constexpr auto RectangleColor = GPU::Color24(0x80, 0x80, 0xFF); +static constexpr auto RectangleArea = GPU::AreaI16({0, TriangleArea.size.height}, {80, 80}); +static constexpr auto RectangleTPage = GPU::TPage(320, 256, GPU::SemiTransparency::B_Half_add_F_Half, GPU::TexturePageColor::$4bit); +static constexpr auto RectangleClut = GPU::PageClut(320, 510); -static constexpr auto LineColor = JabyEngine::GPU::Color24(0xFF, 0x0, 0x0); +static constexpr auto LineColor = GPU::Color24(0xFF, 0x0, 0x0); -static constexpr const auto triangle1 = JabyEngine::GPU::POLY_F3({ +static constexpr const auto triangle1 = GPU::POLY_F3({ {TriangleArea.position.x, TriangleArea.position.y}, {TriangleArea.size.width, TriangleArea.size.height}, {TriangleArea.position.x, TriangleArea.size.height}}, TriangleColor ); -static constexpr const auto triangle2 = JabyEngine::GPU::POLY_FT3({ +static constexpr const auto triangle2 = GPU::POLY_FT3({ {TriangleArea.position.x, TriangleArea.position.y}, {TriangleArea.size.width, TriangleArea.position.y}, {TriangleArea.size.width, TriangleArea.size.height}},{ @@ -40,96 +42,101 @@ static constexpr const auto triangle2 = JabyEngine::GPU::POLY_FT3({ {TriangleArea.size.width, TriangleArea.size.height}}, TriangleTPage, TriangleClut, - JabyEngine::GPU::Color24::Grey() + GPU::Color24::Grey() ); -static constexpr const auto triangle3 = JabyEngine::GPU::POLY_G3({ - {triangle1.vertex0.move(TriangleArea.size.width, 0), JabyEngine::GPU::Color24::Red()}, - {triangle1.vertex1.move(TriangleArea.size.width, 0), JabyEngine::GPU::Color24::Green()}, - {triangle1.vertex2.move(TriangleArea.size.width, 0), JabyEngine::GPU::Color24::Blue()}} +static constexpr const auto triangle3 = GPU::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 = JabyEngine::GPU::POLY_GT3({ - {triangle2.vertex0.move(TriangleArea.size.width, 0), triangle2.page0, JabyEngine::GPU::Color24::Red()}, - {triangle2.vertex1.move(TriangleArea.size.width, 0), triangle2.page1, JabyEngine::GPU::Color24::Blue()}, - {triangle2.vertex2.move(TriangleArea.size.width, 0), triangle2.page2, JabyEngine::GPU::Color24::Green()}}, +static constexpr const auto triangle4 = GPU::POLY_GT3({ + {triangle2.vertex0.move(TriangleArea.size.width, 0), triangle2.page0, GPU::Color24::Red()}, + {triangle2.vertex1.move(TriangleArea.size.width, 0), triangle2.page1, GPU::Color24::Blue()}, + {triangle2.vertex2.move(TriangleArea.size.width, 0), triangle2.page2, GPU::Color24::Green()}}, TriangleTPage, TriangleClut ); -static constexpr const auto rectangle1 = JabyEngine::GPU::POLY_F4(RectangleArea, RectangleColor); -static constexpr const auto rectangle2 = JabyEngine::GPU::POLY_FT4({ +static constexpr const auto rectangle1 = GPU::POLY_F4(RectangleArea, RectangleColor); +static constexpr const auto rectangle2 = GPU::POLY_FT4({ RectangleArea.position.move(RectangleArea.size.width, 0), RectangleArea.size}, {0, 0}, RectangleTPage, RectangleClut, - JabyEngine::GPU::Color24::Grey() + GPU::Color24::Grey() ); -static constexpr const auto rectangle3 = JabyEngine::GPU::POLY_G4( +static constexpr const auto rectangle3 = GPU::POLY_G4( {RectangleArea.position.move(RectangleArea.size.width*2, 0), RectangleArea.size}, { - JabyEngine::GPU::Color24::Red(), - JabyEngine::GPU::Color24::Blue(), - JabyEngine::GPU::Color24::Green(), - JabyEngine::GPU::Color24::White()}); -static constexpr const auto rectangle4 = JabyEngine::GPU::POLY_GT4( + GPU::Color24::Red(), + GPU::Color24::Blue(), + GPU::Color24::Green(), + GPU::Color24::White()}); +static constexpr const auto rectangle4 = GPU::POLY_GT4( {RectangleArea.position.move(RectangleArea.size.width*3, 0), RectangleArea.size}, {0, 0}, RectangleTPage, RectangleClut, { - JabyEngine::GPU::Color24::Red(), - JabyEngine::GPU::Color24::Blue(), - JabyEngine::GPU::Color24::Green(), - JabyEngine::GPU::Color24::White()} + GPU::Color24::Red(), + GPU::Color24::Blue(), + GPU::Color24::Green(), + GPU::Color24::White()} ); -static constexpr const auto rectangle5 = JabyEngine::GPU::POLY_GT4( +static constexpr const auto rectangle5 = GPU::POLY_GT4( {RectangleArea.position.move(0, RectangleArea.size.height), RectangleArea.size}, {0, 0}, RectangleTPage, RectangleClut, { - JabyEngine::GPU::Color24::Red(), - JabyEngine::GPU::Color24::Blue(), - JabyEngine::GPU::Color24::Green(), - JabyEngine::GPU::Color24::White()} + GPU::Color24::Red(), + GPU::Color24::Blue(), + GPU::Color24::Green(), + GPU::Color24::White()} ).set_semi_transparent(true); -static constexpr const auto line1 = JabyEngine::GPU::LINE_F::create(LineColor, +static constexpr const auto line1 = GPU::LINE_F::create(LineColor, {0, 0}, - {JabyEngine::GPU::Display::Width, JabyEngine::GPU::Display::Height} + {GPU::Display::Width, GPU::Display::Height} ); -static constexpr const auto line2 = JabyEngine::GPU::LINE_F::create(LineColor.invert(), - JabyEngine::GPU::Vertex(0, 0), - JabyEngine::GPU::Vertex(16, 0), - JabyEngine::GPU::Vertex(16, 16), - JabyEngine::GPU::Vertex(0, 0) +static constexpr const auto line2 = GPU::LINE_F::create(LineColor.invert(), + GPU::Vertex(0, 0), + GPU::Vertex(16, 0), + GPU::Vertex(16, 16), + GPU::Vertex(0, 0) ); -static constexpr const auto line3 = JabyEngine::GPU::LINE_G::create( - {LineColor, {JabyEngine::GPU::Display::Width, 0}}, - {LineColor.invert(), {0, JabyEngine::GPU::Display::Height}} +static constexpr const auto line3 = GPU::LINE_G::create( + {LineColor, {GPU::Display::Width, 0}}, + {LineColor.invert(), {0, GPU::Display::Height}} ); -static constexpr const auto line4 = JabyEngine::GPU::LINE_G::create( - JabyEngine::GPU::ColorVertex{JabyEngine::GPU::Color24::Red(), {0, 0}}, - JabyEngine::GPU::ColorVertex{JabyEngine::GPU::Color24::Green(), {0, 16}}, - JabyEngine::GPU::ColorVertex{JabyEngine::GPU::Color24::Blue(), {16, 16}}, - JabyEngine::GPU::ColorVertex{JabyEngine::GPU::Color24::White(), {0, 0}} +static constexpr const auto line4 = GPU::LINE_G::create( + GPU::ColorVertex{GPU::Color24::Red(), {0, 0}}, + GPU::ColorVertex{GPU::Color24::Green(), {0, 16}}, + GPU::ColorVertex{GPU::Color24::Blue(), {16, 16}}, + GPU::ColorVertex{GPU::Color24::White(), {0, 0}} ); +static constexpr const auto rect1 = GPU::RECT_FVAR(GPU::Color24::Green(), GPU::AreaI16({GPU::Display::Width - 32, GPU::Display::Height - 32}, {32, 32})); +static constexpr const auto rect2 = GPU::RECT_F16(GPU::Color24::Blue(), {GPU::Display::Width - 16, GPU::Display::Height - 16}); +static constexpr const auto rect3 = GPU::RECT_F8(GPU::Color24::Yellow(), {GPU::Display::Width - 8, GPU::Display::Height - 8}); +static constexpr const auto rect4 = GPU::RECT_F1(GPU::Color24::Red(), {GPU::Display::Width - 1, GPU::Display::Height - 1}); + static void load_assets() { - static const JabyEngine::CDFile Assets[] = { - JabyEngine::CDFileBuilder::simple_tim(LBA::FONT, JabyEngine::SimpleTIM(320, 0, 320, 511)), - JabyEngine::CDFileBuilder::simple_tim(LBA::ICON, JabyEngine::SimpleTIM(320, 256, 320, 510)), + 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 = JabyEngine::CDFileProcessor::BufferConfiguration::new_default(); - JabyEngine::CDFileProcessor file_processor; + 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 JabyEngine::Progress::InProgress: + case Progress::InProgress: break; - case JabyEngine::Progress::Done: + case Progress::Done: if(!file_processor.next(lba, buffer_cfg)) { return; } break; - case JabyEngine::Progress::Error: + case Progress::Error: printf("Error detected! Aborting load\n"); return; } @@ -141,23 +148,28 @@ void main() { load_assets(); while(true) { - JabyEngine::GPU::render(triangle1); - JabyEngine::GPU::render(triangle2); - JabyEngine::GPU::render(triangle3); - JabyEngine::GPU::render(triangle4); + GPU::render(triangle1); + GPU::render(triangle2); + GPU::render(triangle3); + GPU::render(triangle4); - JabyEngine::GPU::render(rectangle1); - JabyEngine::GPU::render(rectangle2); - JabyEngine::GPU::render(rectangle3); - JabyEngine::GPU::render(rectangle4); - JabyEngine::GPU::render(rectangle5); + GPU::render(rectangle1); + GPU::render(rectangle2); + GPU::render(rectangle3); + GPU::render(rectangle4); + GPU::render(rectangle5); - JabyEngine::GPU::render(line1); - JabyEngine::GPU::render(line2); - JabyEngine::GPU::render(line3); - JabyEngine::GPU::render(line4); + GPU::render(rect1); + GPU::render(rect2); + GPU::render(rect3); + GPU::render(rect4); - JabyEngine::GPU::swap_buffers_vsync(2); + GPU::render(line1); + GPU::render(line2); + GPU::render(line3); + GPU::render(line4); + + GPU::swap_buffers_vsync(2); } } __declare_lba_header(LBA); \ No newline at end of file diff --git a/include/PSX/GPU/Primitives/primitive_line_types.hpp b/include/PSX/GPU/Primitives/primitive_line_types.hpp index d80c8b85..5cb254e3 100644 --- a/include/PSX/GPU/Primitives/primitive_line_types.hpp +++ b/include/PSX/GPU/Primitives/primitive_line_types.hpp @@ -1,5 +1,5 @@ -#ifndef __JABY_ENGINE_PRIMITIVE_LINE_TYPES_HPP__ -#define __JABY_ENGINE_PRIMITIVE_LINE_TYPES_HPP__ +#ifndef __JABYENGINE_PRIMITIVE_LINE_TYPES_HPP__ +#define __JABYENGINE_PRIMITIVE_LINE_TYPES_HPP__ #include "primitive_support_types.hpp" namespace JabyEngine { @@ -12,8 +12,6 @@ namespace JabyEngine { static constexpr auto FlatShading = !GouraudShading; static constexpr auto PolyLine = Bit(27 - BitCorrection); static constexpr auto SingleLine = !PolyLine; - static constexpr auto SemiTransparent = Bit(25 - BitCorrection); - static constexpr auto NonTransparent = !SemiTransparent; }; template @@ -21,12 +19,7 @@ namespace JabyEngine { typedef ::JabyEngine::GPU::internal::LineCode Code; constexpr T& set_semi_transparent(bool set = true) { - if(set) { - static_cast(this)->head.code.set(Code::SemiTransparent); - } - else { - static_cast(this)->head.code.set(Code::NonTransparent); - } + static_cast(this)->head.code.set_tenary(set, Code::SemiTransparent, Code::NonTransparent); return *static_cast(this); } }; @@ -123,4 +116,4 @@ namespace JabyEngine { } } -#endif //!__JABY_ENGINE_PRIMITIVE_LINE_TYPES_HPP__ \ No newline at end of file +#endif //!__JABYENGINE_PRIMITIVE_LINE_TYPES_HPP__ \ No newline at end of file diff --git a/include/PSX/GPU/Primitives/primitive_poly_types.hpp b/include/PSX/GPU/Primitives/primitive_poly_types.hpp index 3081842d..65520a77 100644 --- a/include/PSX/GPU/Primitives/primitive_poly_types.hpp +++ b/include/PSX/GPU/Primitives/primitive_poly_types.hpp @@ -12,12 +12,6 @@ namespace JabyEngine { static constexpr auto FlatShading = !GouraudShading; static constexpr auto QuadVertics = Bit(27 - BitCorrection); static constexpr auto TriVertics = !QuadVertics; - static constexpr auto Textured = Bit(26 - BitCorrection); - static constexpr auto Untextured = !Textured; - static constexpr auto SemiTransparent = Bit(25 - BitCorrection); - static constexpr auto NonTransparent = !SemiTransparent; - static constexpr auto NoBlendTexture = Bit(24 - BitCorrection); - static constexpr auto BlendTexture = !NoBlendTexture; }; template @@ -25,22 +19,12 @@ namespace JabyEngine { typedef ::JabyEngine::GPU::internal::PolyCode Code; constexpr T& set_semi_transparent(bool set = true) { - if(set) { - static_cast(this)->code.set(Code::SemiTransparent); - } - else { - static_cast(this)->code.set(Code::NonTransparent); - } + static_cast(this)->code.set_tenary(set, Code::SemiTransparent, Code::NonTransparent); return *static_cast(this); } constexpr T& set_texture_blending(bool set = true) { - if(set) { - static_cast(this)->code.set(Code::BlendTexture); - } - else { - static_cast(this)->code.set(Code::NoBlendTexture); - } + static_cast(this)->code.set_tenary(set, Code::BlendTexture, Code::NoBlendTexture); return *static_cast(this); } }; diff --git a/include/PSX/GPU/Primitives/primitive_rectangle_types.hpp b/include/PSX/GPU/Primitives/primitive_rectangle_types.hpp new file mode 100644 index 00000000..a74e67a9 --- /dev/null +++ b/include/PSX/GPU/Primitives/primitive_rectangle_types.hpp @@ -0,0 +1,65 @@ +#ifndef __JABYENGINE_PRIMITIVE_RECTANGLE_TYPES_HPP__ +#define __JABYENGINE_PRIMITIVE_RECTANGLE_TYPES_HPP__ +#include "primitive_support_types.hpp" + +namespace JabyEngine { + namespace GPU { + namespace internal { + struct RectCode : public CodeBase { + enum struct Size : uint8_t { + Variable = 0, + Pixel1x1 = 1, + Sprite8x8 = 2, + Sprite16x16 = 3 + }; + static constexpr uint8_t CmdValue = 0b011; + + static constexpr auto Size = BitRange::from_to(27 - BitCorrection, 28 - BitCorrection); + }; + + template + struct RectCodeInterface { + typedef typename ::JabyEngine::GPU::internal::RectCode Code; + + constexpr T& set_semi_transparent(bool set = true) { + static_cast(this)->code.set_tenary(set, Code::SemiTransparent, Code::NonTransparent); + return *static_cast(this); + } + }; + + template + struct RECT_F : public RectCodeInterface> { + typedef RECT_F::Code Code; + static constexpr auto IdentityCode = Code().set(Code::Size.with(static_cast(Size))).set(Code::Untextured).set(Code::NonTransparent); + + Color24 color; + Code code; + Vertex position; + + constexpr RECT_F() = default; + constexpr RECT_F(const Color24& color, const Vertex& position) : color(color), code(IdentityCode), position(position) { + } + }; + } + + typedef internal::RECT_F RECT_F1; + typedef internal::RECT_F RECT_F8; + typedef internal::RECT_F RECT_F16; + struct RECT_FVAR : public internal::RECT_F { + Vertex position_bottom_right; + + constexpr RECT_FVAR() = default; + constexpr RECT_FVAR(const Color24& color, const AreaI16& area) : RECT_F(color, area.position), position_bottom_right(area.position.move(area.size.width, area.size.height)) { + } + }; + + namespace internal { + __jaby_engine_declare_render_primitive(RECT_F1); + __jaby_engine_declare_render_primitive(RECT_F8); + __jaby_engine_declare_render_primitive(RECT_F16); + __jaby_engine_declare_render_primitive(RECT_FVAR); + } + } +} + +#endif //!__JABYENGINE_PRIMITIVE_RECTANGLE_TYPES_HPP__ \ No newline at end of file diff --git a/include/PSX/GPU/Primitives/primitive_support_types.hpp b/include/PSX/GPU/Primitives/primitive_support_types.hpp index 98e47810..d8ba0ade 100644 --- a/include/PSX/GPU/Primitives/primitive_support_types.hpp +++ b/include/PSX/GPU/Primitives/primitive_support_types.hpp @@ -13,6 +13,14 @@ namespace JabyEngine { uint8_t value = bit::value::set_normalized(0u, CmdID.with(T::CmdValue)); + // Common values for all the primitves + static constexpr auto Textured = Bit(26 - BitCorrection); + static constexpr auto Untextured = !Textured; + static constexpr auto SemiTransparent = Bit(25 - BitCorrection); + static constexpr auto NonTransparent = !SemiTransparent; + static constexpr auto NoBlendTexture = Bit(24 - BitCorrection); + static constexpr auto BlendTexture = !NoBlendTexture; + constexpr CodeBase() = default; constexpr CodeBase(const T& code) : value(code.value) { } @@ -26,6 +34,22 @@ namespace JabyEngine { this->value = bit::set(this->value, bit); return static_cast(*this); } + + constexpr T& set(BitRange::RangeValuePair value_pair) { + this->value = bit::value::set_normalized(this->value, value_pair); + return static_cast(*this); + } + + template + constexpr T& set_tenary(bool use_first, const S& first, const R& second) { + if(use_first) { + return this->set(first); + } + + else { + return this->set(second); + } + } }; // Concept for now diff --git a/include/PSX/GPU/gpu_primitives.hpp b/include/PSX/GPU/gpu_primitives.hpp index 9c6ba90b..f0415ef5 100644 --- a/include/PSX/GPU/gpu_primitives.hpp +++ b/include/PSX/GPU/gpu_primitives.hpp @@ -1,5 +1,6 @@ #ifndef __JABYENGINE_GPU_PRIMITIVES_HPP__ #define __JABYENGINE_GPU_PRIMITIVES_HPP__ #include "Primitives/primitive_line_types.hpp" +#include "Primitives/primitive_rectangle_types.hpp" #include "Primitives/primitive_poly_types.hpp" #endif // !__JABYENGINE_GPU_PRIMITIVES_HPP__ \ No newline at end of file diff --git a/include/PSX/GPU/gpu_types.hpp b/include/PSX/GPU/gpu_types.hpp index bb9c5684..1271a052 100644 --- a/include/PSX/GPU/gpu_types.hpp +++ b/include/PSX/GPU/gpu_types.hpp @@ -69,6 +69,10 @@ namespace JabyEngine { return Color24(0x0, 0x0, 0xFF); } + static constexpr Color24 Yellow() { + return Color24(0xFF, 0xFF, 0x0); + } + constexpr Color24 invert() const { return Color24(0xFF - this->red, 0xFF - this->green, 0xFF - this->blue); }