From cc77237150de0fe71dafdc0a7193972b17fb2dfb Mon Sep 17 00:00:00 2001 From: Jaby Date: Mon, 5 Jun 2023 22:44:45 +0200 Subject: [PATCH] Support all primitives --- examples/PoolBox/application/src/main.cpp | 19 +++++-- .../GPU/Primitives/primitive_gpu_commands.hpp | 21 ++++++++ .../Primitives/primitive_rectangle_types.hpp | 50 +++++++++++-------- .../Primitives/primitive_support_types.hpp | 4 -- include/PSX/GPU/gpu_primitives.hpp | 1 + include/PSX/GPU/gpu_types.hpp | 13 +++++ include/PSX/System/IOPorts/gpu_io.hpp | 30 ++++++----- 7 files changed, 92 insertions(+), 46 deletions(-) create mode 100644 include/PSX/GPU/Primitives/primitive_gpu_commands.hpp diff --git a/examples/PoolBox/application/src/main.cpp b/examples/PoolBox/application/src/main.cpp index a788a404..0eedd2b7 100644 --- a/examples/PoolBox/application/src/main.cpp +++ b/examples/PoolBox/application/src/main.cpp @@ -110,10 +110,16 @@ static constexpr const auto line4 = GPU::LINE_G::create( 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 constexpr const auto rect1 = GPU::TILE(GPU::AreaI16({GPU::Display::Width - 32, GPU::Display::Height - 32}, {32, 32}), GPU::Color24::Green()); +static constexpr const auto rect2 = GPU::TILE_16({GPU::Display::Width - 16, GPU::Display::Height - 16}, GPU::Color24::Blue()); +static constexpr const auto rect3 = GPU::TILE_8({GPU::Display::Width - 8, GPU::Display::Height - 8}, GPU::Color24::Yellow()); +static constexpr const auto rect4 = GPU::TILE_1({GPU::Display::Width - 1, GPU::Display::Height - 1}, GPU::Color24::Red()); + +static constexpr const auto texpage = GPU::TexPage({320, 0}, GPU::TexturePageColor::$4bit); +static constexpr const auto rect5 = GPU::SPRT(GPU::AreaI16({0, GPU::Display::Height - 32}, {32, 32}), {{0, 0}, TriangleClut}, GPU::Color24::Green()); +static constexpr const auto rect6 = GPU::SPRT_16({0, GPU::Display::Height - 16}, {{0, 0}, TriangleClut}, GPU::Color24::Blue()); +static constexpr const auto rect7 = GPU::SPRT_8({0, GPU::Display::Height - 8}, {{0, 0}, TriangleClut}, GPU::Color24::Yellow()); +static constexpr const auto rect8 = GPU::SPRT_1({0, GPU::Display::Height - 1}, {{0, 0}, TriangleClut}, GPU::Color24::Red()); static void load_assets() { static const CDFile Assets[] = { @@ -163,6 +169,11 @@ void main() { 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); diff --git a/include/PSX/GPU/Primitives/primitive_gpu_commands.hpp b/include/PSX/GPU/Primitives/primitive_gpu_commands.hpp new file mode 100644 index 00000000..693855a2 --- /dev/null +++ b/include/PSX/GPU/Primitives/primitive_gpu_commands.hpp @@ -0,0 +1,21 @@ +#ifndef __JABYENGINE_PRIMITIVE_GPU_COMMANDS_HPP__ +#define __JABYENGINE_PRIMITIVE_GPU_COMMANDS_HPP__ +#include "../../System/IOPorts/gpu_io.hpp" +#include "primitive_support_types.hpp" + +namespace JabyEngine { + namespace GPU { + struct TexPage { + GPU_IO::GP0_t value; + + constexpr TexPage(const PositionU16& tex_pos, TexturePageColor tex_color, SemiTransparency transparency = SemiTransparency::B_Half_add_F_Half, bool dither = false) : value{ + GPU_IO::Command::TexPage(tex_pos, transparency, tex_color, dither, false)} {} + }; + + namespace internal { + __jaby_engine_declare_render_primitive(TexPage); + } + } +} + +#endif // !__JABYENGINE_PRIMITIVE_GPU_COMMANDS_HPP__ \ No newline at end of file diff --git a/include/PSX/GPU/Primitives/primitive_rectangle_types.hpp b/include/PSX/GPU/Primitives/primitive_rectangle_types.hpp index b45cdfe5..6e43b9a5 100644 --- a/include/PSX/GPU/Primitives/primitive_rectangle_types.hpp +++ b/include/PSX/GPU/Primitives/primitive_rectangle_types.hpp @@ -4,6 +4,11 @@ namespace JabyEngine { namespace GPU { + struct PagePositionClut { + PagePosition page; + PageClut clut; + }; + namespace internal { struct RectCode : public CodeBase { enum struct Size : uint8_t { @@ -37,7 +42,7 @@ namespace JabyEngine { Vertex position; constexpr RECT_F() = default; - constexpr RECT_F(const Color24& color, const Vertex& position) : color(color), code(IdentityCode), position(position) { + constexpr RECT_F(const Vertex& position, const Color24& color) : color(color), code(IdentityCode), position(position) { } }; @@ -50,45 +55,46 @@ namespace JabyEngine { Code code; Vertex position; PagePosition page; + PageClut clut; constexpr RECT_T() = default; - constexpr RECT_T(const Color24& color, const Vertex& position, const PagePosition& page) : color(color), code(IdentityCode), position(position), page(page) { + constexpr RECT_T(const Vertex& position, const PagePositionClut& page, const Color24& color = Color24::Grey()) : color(color), code(IdentityCode), position(position), page(page.page), clut(page.clut) { } }; } - 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 { + typedef internal::RECT_F TILE_1; + typedef internal::RECT_F TILE_8; + typedef internal::RECT_F TILE_16; + struct TILE : 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.get_bottom_left()) { + constexpr TILE() = default; + constexpr TILE(const AreaI16& area, const Color24& color) : RECT_F(area.position, color), position_bottom_right(area.get_bottom_left()) { } }; - typedef internal::RECT_T RECT_T1; - typedef internal::RECT_T RECT_T8; - typedef internal::RECT_T RECT_T16; - struct RECT_TVAR : public internal::RECT_T { + typedef internal::RECT_T SPRT_1; + typedef internal::RECT_T SPRT_8; + typedef internal::RECT_T SPRT_16; + struct SPRT : public internal::RECT_T { Vertex position_bottom_right; - constexpr RECT_TVAR() = default; - constexpr RECT_TVAR(const Color24& color, const AreaI16& area, const PagePosition& page) : RECT_T(color, area.position, page), position_bottom_right(area.get_bottom_left()) { + constexpr SPRT() = default; + constexpr SPRT(const AreaI16& area, const PagePositionClut& page, const Color24& color = Color24::Grey()) : RECT_T(area.position, page, color), position_bottom_right(area.get_bottom_left()) { } }; 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); + __jaby_engine_declare_render_primitive(TILE_1); + __jaby_engine_declare_render_primitive(TILE_8); + __jaby_engine_declare_render_primitive(TILE_16); + __jaby_engine_declare_render_primitive(TILE); - __jaby_engine_declare_render_primitive(RECT_T1); - __jaby_engine_declare_render_primitive(RECT_T8); - __jaby_engine_declare_render_primitive(RECT_T16); - __jaby_engine_declare_render_primitive(RECT_TVAR); + __jaby_engine_declare_render_primitive(SPRT_1); + __jaby_engine_declare_render_primitive(SPRT_8); + __jaby_engine_declare_render_primitive(SPRT_16); + __jaby_engine_declare_render_primitive(SPRT); } } } diff --git a/include/PSX/GPU/Primitives/primitive_support_types.hpp b/include/PSX/GPU/Primitives/primitive_support_types.hpp index d8ba0ade..315c4fe5 100644 --- a/include/PSX/GPU/Primitives/primitive_support_types.hpp +++ b/include/PSX/GPU/Primitives/primitive_support_types.hpp @@ -71,10 +71,6 @@ namespace JabyEngine { } } - // Reexport for easier use - typedef JabyEngine::GPU_IO::SemiTransparency SemiTransparency; - typedef JabyEngine::GPU_IO::TexturePageColor TexturePageColor; - struct PageClut { uint16_t value = 0; diff --git a/include/PSX/GPU/gpu_primitives.hpp b/include/PSX/GPU/gpu_primitives.hpp index f0415ef5..2cbf3ff2 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_gpu_commands.hpp" #include "Primitives/primitive_line_types.hpp" #include "Primitives/primitive_rectangle_types.hpp" #include "Primitives/primitive_poly_types.hpp" diff --git a/include/PSX/GPU/gpu_types.hpp b/include/PSX/GPU/gpu_types.hpp index d09387a8..68e320e0 100644 --- a/include/PSX/GPU/gpu_types.hpp +++ b/include/PSX/GPU/gpu_types.hpp @@ -32,6 +32,19 @@ namespace JabyEngine { }; } + enum struct SemiTransparency { + B_Half_add_F_Half = 0, + B_add_F = 1, + B_sub_F = 2, + B_add_F_Quarter = 3, + }; + + enum struct TexturePageColor { + $4bit = 0, + $8bit = 1, + $15bit = 2, + }; + struct Color24 { uint8_t red = 0; uint8_t green = 0; diff --git a/include/PSX/System/IOPorts/gpu_io.hpp b/include/PSX/System/IOPorts/gpu_io.hpp index 1213ba90..c916fafa 100644 --- a/include/PSX/System/IOPorts/gpu_io.hpp +++ b/include/PSX/System/IOPorts/gpu_io.hpp @@ -6,24 +6,11 @@ namespace JabyEngine { namespace GPU_IO { - enum struct SemiTransparency { - B_Half_add_F_Half = 0, - B_add_F = 1, - B_sub_F = 2, - B_add_F_Quarter = 3, - }; - enum struct DisplayAreaColorDepth { $15bit = 0, $24bit = 1, }; - enum struct TexturePageColor { - $4bit = 0, - $8bit = 1, - $15bit = 2, - }; - enum struct HorizontalResolution { $256 = 0, $320 = 1, @@ -114,9 +101,20 @@ namespace JabyEngine { return {(0b101u << 29)}; } - /*static constexpr GP0_t DrawMode(const GPU::PositionU16& page_pos, SemiTransparency transparency, TexturePageColor tex_color, bool dither) { + static constexpr GP0_t TexPage(const GPU::PositionU16& page_pos, GPU::SemiTransparency transparency, GPU::TexturePageColor tex_color, bool dither, bool draw_on_display_area) { + constexpr auto TexXRange = BitRange::from_to(0, 3); + constexpr auto TexYRange = BitRange::from_to(4, 4); + constexpr auto TransparencyRange = BitRange::from_to(5, 6); + constexpr auto TextureColorRange = BitRange::from_to(7, 8); + constexpr auto DitherBit = BitRange::from_to(9, 9); + constexpr auto DrawOnDisplayAreaBit = BitRange::from_to(10, 10); - }*/ + return {Helper::construct_cmd(0xE1, + TexXRange.as_value(page_pos.x >> 6) | TexYRange.as_value(page_pos.y >> 7) | + TransparencyRange.as_value(static_cast(transparency)) | TextureColorRange.as_value(static_cast(tex_color)) | + DitherBit.as_value(static_cast(dither)) | DrawOnDisplayAreaBit.as_value(static_cast(draw_on_display_area)) + )}; + } static constexpr GP0_t DrawAreaTopLeft(const GPU::PositionU16& position) { return Helper::DrawAreaTemplate(0xE3, position.x, position.y); @@ -126,7 +124,7 @@ namespace JabyEngine { return Helper::DrawAreaTemplate(0xE4, position.x, position.y); } - static GP0_t SetDrawOffset(const GPU::PositionI16& offset) { + static constexpr GP0_t SetDrawOffset(const GPU::PositionI16& offset) { constexpr auto X = BitRange::from_to(0, 10); constexpr auto Y = BitRange::from_to(11, 21);