From ca1e937daee9cd01e0188646a4b45a8b6f76eef4 Mon Sep 17 00:00:00 2001 From: Jaby Date: Sat, 27 May 2023 15:14:19 +0200 Subject: [PATCH] Support LINE_F --- examples/PoolBox/application/src/main.cpp | 10 +++ .../GPU/Primitives/primitive_line_types.hpp | 73 +++++++++++++++++++ .../GPU/Primitives/primitive_poly_types.hpp | 22 +++--- include/PSX/GPU/gpu.hpp | 5 ++ include/PSX/GPU/gpu_primitives.hpp | 1 + 5 files changed, 100 insertions(+), 11 deletions(-) create mode 100644 include/PSX/GPU/Primitives/primitive_line_types.hpp diff --git a/examples/PoolBox/application/src/main.cpp b/examples/PoolBox/application/src/main.cpp index e42f1ed7..e2675cb3 100644 --- a/examples/PoolBox/application/src/main.cpp +++ b/examples/PoolBox/application/src/main.cpp @@ -22,6 +22,8 @@ static constexpr auto RectangleArea = JabyEngine::GPU::AreaI16({0, TriangleArea 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 LineColor = JabyEngine::GPU::Color24(0xFF, 0x0, 0x0); + static constexpr const auto triangle1 = JabyEngine::GPU::POLY_F3({ {TriangleArea.position.x, TriangleArea.position.y}, {TriangleArea.size.width, TriangleArea.size.height}, @@ -85,6 +87,12 @@ static constexpr const auto rectangle5 = JabyEngine::GPU::POLY_GT4( JabyEngine::GPU::Color24::White()} ).set_semi_transparent(true); +static constexpr const JabyEngine::GPU::LINE_F line1[] = { + JabyEngine::GPU::LINE_F::new_line(LineColor, false), + JabyEngine::GPU::LINE_F::new_point({0, 0}), + JabyEngine::GPU::LINE_F::new_point({JabyEngine::GPU::Display::Width, JabyEngine::GPU::Display::Height}) +}; + static void load_assets() { static const JabyEngine::CDFile Assets[] = { JabyEngine::CDFileBuilder::simple_tim(LBA::FONT, JabyEngine::SimpleTIM(320, 0, 320, 511)), @@ -130,6 +138,8 @@ void main() { JabyEngine::GPU::render(rectangle4); JabyEngine::GPU::render(rectangle5); + JabyEngine::GPU::render(line1); + JabyEngine::GPU::swap_buffers_vsync(2); } } diff --git a/include/PSX/GPU/Primitives/primitive_line_types.hpp b/include/PSX/GPU/Primitives/primitive_line_types.hpp new file mode 100644 index 00000000..3ceabe6b --- /dev/null +++ b/include/PSX/GPU/Primitives/primitive_line_types.hpp @@ -0,0 +1,73 @@ +#ifndef __JABY_ENGINE_PRIMITIVE_LINE_TYPES_HPP__ +#define __JABY_ENGINE_PRIMITIVE_LINE_TYPES_HPP__ +#include "primitive_support_types.hpp" + +namespace JabyEngine { + namespace GPU { + namespace internal { + struct LineCode : public CodeBase { + static constexpr uint8_t CmdValue = 0b010; + + static constexpr auto GouraudShading = Bit(28 - BitCorrection); + 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 + struct LineCodeInterface { + typedef ::JabyEngine::GPU::internal::LineCode Code; + + constexpr T& set_poly_line(bool set = true) { + if(set) { + static_cast(this)->head.code.set(Code::PolyLine); + } + else { + static_cast(this)->head.code.set(Code::SingleLine); + } + return *static_cast(this); + } + + 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); + } + return *static_cast(this); + } + }; + } + + struct LINE_F : public internal::IsPrimitive, public internal::LineCodeInterface { + struct Head { + static constexpr auto IdentityCode = Code().set(Code::FlatShading).set(Code::SingleLine).set(Code::NonTransparent); + + Color24 color; + Code code = IdentityCode; + }; + + union { + Head head; + Vertex vertex; + }; + + static constexpr LINE_F new_line(const Color24& color, bool is_poly) { + return LINE_F{.head = {.color = color, .code = Head::IdentityCode}}.set_poly_line(is_poly); + } + + static constexpr LINE_F new_point(const Vertex& vertex) { + return {.vertex = vertex}; + } + + static constexpr LINE_F new_terminate() { + return {.vertex = {static_cast(0xF000), static_cast(0xF000u)}}; + } + }; + } +} + +#endif //!__JABY_ENGINE_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 8b02ff88..59b0965d 100644 --- a/include/PSX/GPU/Primitives/primitive_poly_types.hpp +++ b/include/PSX/GPU/Primitives/primitive_poly_types.hpp @@ -5,7 +5,7 @@ namespace JabyEngine { namespace GPU { namespace internal { - struct Code : public CodeBase { + struct PolyCode : public CodeBase { static constexpr uint8_t CmdValue = 0b001; static constexpr auto GouraudShading = Bit(28 - BitCorrection); @@ -21,8 +21,8 @@ namespace JabyEngine { }; template - struct CodeInterface { - typedef ::JabyEngine::GPU::internal::Code Code; + struct PolyCodeInterface { + typedef ::JabyEngine::GPU::internal::PolyCode Code; constexpr T& set_semi_transparent(bool set = true) { if(set) { @@ -51,7 +51,7 @@ namespace JabyEngine { / \ 3 - 2 */ - struct POLY_F3 : public internal::IsPrimitive, public internal::CodeInterface { + struct POLY_F3 : public internal::IsPrimitive, public internal::PolyCodeInterface { static constexpr auto IdentityCode = Code().set(Code::FlatShading).set(Code::TriVertics).set(Code::Untextured).set(Code::NonTransparent); Color24 color; // a @@ -69,7 +69,7 @@ namespace JabyEngine { } }; - struct POLY_FT3 : public internal::IsPrimitive, public internal::CodeInterface { + struct POLY_FT3 : public internal::IsPrimitive, public internal::PolyCodeInterface { struct VertexEx { Vertex position; PagePosition page; @@ -100,7 +100,7 @@ namespace JabyEngine { vertex2(vertices_ex[2].position), page2(vertices_ex[2].page), padded2(0) {} }; - struct POLY_G3 : public internal::IsPrimitive, public internal::CodeInterface { + struct POLY_G3 : public internal::IsPrimitive, public internal::PolyCodeInterface { struct VertexEx { Vertex position; Color24 color; @@ -128,7 +128,7 @@ namespace JabyEngine { color2(verticies_ex[2].color), pad2(0), vertex2(verticies_ex[2].position) {} }; - struct POLY_GT3 : public internal::IsPrimitive, public internal::CodeInterface { + struct POLY_GT3 : public internal::IsPrimitive, public internal::PolyCodeInterface { struct VertexEx { Vertex position; PagePosition page; @@ -168,7 +168,7 @@ namespace JabyEngine { | | 3 - 4 */ - struct POLY_F4 : public internal::IsPrimitive, public internal::CodeInterface { + struct POLY_F4 : public internal::IsPrimitive, public internal::PolyCodeInterface { static constexpr auto IdentityCode = Code(POLY_F3::IdentityCode).set(Code::QuadVertics); Color24 color; // a @@ -193,7 +193,7 @@ namespace JabyEngine { color) {} }; - struct POLY_FT4 : public internal::IsPrimitive, public internal::CodeInterface { + struct POLY_FT4 : public internal::IsPrimitive, public internal::PolyCodeInterface { typedef POLY_FT3::VertexEx VertexEx; static constexpr auto IdentityCode = Code(POLY_FT3::IdentityCode).set(Code::QuadVertics); @@ -233,7 +233,7 @@ namespace JabyEngine { ) {} }; - struct POLY_G4 : public internal::IsPrimitive, public internal::CodeInterface { + struct POLY_G4 : public internal::IsPrimitive, public internal::PolyCodeInterface { typedef POLY_G3::VertexEx VertexEx; static constexpr auto IdentityCode = Code(POLY_G3::IdentityCode).set(Code::QuadVertics); @@ -270,7 +270,7 @@ namespace JabyEngine { ) {} }; - struct POLY_GT4 : public internal::IsPrimitive, public internal::CodeInterface { + struct POLY_GT4 : public internal::IsPrimitive, public internal::PolyCodeInterface { typedef POLY_GT3::VertexEx VertexEx; static constexpr auto IdentityCode = Code(POLY_GT3::IdentityCode).set(Code::QuadVertics); diff --git a/include/PSX/GPU/gpu.hpp b/include/PSX/GPU/gpu.hpp index 1ac7fa16..75344e05 100644 --- a/include/PSX/GPU/gpu.hpp +++ b/include/PSX/GPU/gpu.hpp @@ -45,6 +45,11 @@ namespace JabyEngine { internal::render(reinterpret_cast(&primitive), sizeof(T)/sizeof(uint32_t)); } + template + static void render(const LINE_F (&line)[N]) { + internal::render(reinterpret_cast(&line), N); + } + uint8_t swap_buffers_vsync(uint8_t syncs, bool clear_screen = true); } } diff --git a/include/PSX/GPU/gpu_primitives.hpp b/include/PSX/GPU/gpu_primitives.hpp index 80a96602..9c6ba90b 100644 --- a/include/PSX/GPU/gpu_primitives.hpp +++ b/include/PSX/GPU/gpu_primitives.hpp @@ -1,4 +1,5 @@ #ifndef __JABYENGINE_GPU_PRIMITIVES_HPP__ #define __JABYENGINE_GPU_PRIMITIVES_HPP__ +#include "Primitives/primitive_line_types.hpp" #include "Primitives/primitive_poly_types.hpp" #endif // !__JABYENGINE_GPU_PRIMITIVES_HPP__ \ No newline at end of file