From 4bf87bc85fa8b8746be6974f70b3adec1a34046c Mon Sep 17 00:00:00 2001 From: jaby Date: Wed, 20 Dec 2023 15:12:21 -0500 Subject: [PATCH] Change to double buffering and SPRT_16 --- include/PSX/GPU/gpu.hpp | 8 ++++++++ support/include/FontWriter/Type/types.hpp | 2 +- support/include/FontWriter/font_writer.hpp | 5 +++-- support/src/FontWriter/src/font_writer.cpp | 19 ++++++++++--------- .../src/global_primitive_buffer.cpp | 2 +- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/include/PSX/GPU/gpu.hpp b/include/PSX/GPU/gpu.hpp index 63b2b01e..4ccf6434 100644 --- a/include/PSX/GPU/gpu.hpp +++ b/include/PSX/GPU/gpu.hpp @@ -37,6 +37,14 @@ namespace JabyEngine { static void set_offset(uint16_t x, uint16_t y); }; + static uint32_t update_id() { + return Display::current_id; + } + + static uint32_t render_id() { + return Display::current_id ^ 1; + } + namespace internal { void render(const uint32_t* data, size_t words); void render_dma(const uint32_t* data); diff --git a/support/include/FontWriter/Type/types.hpp b/support/include/FontWriter/Type/types.hpp index b899f473..3cbe9439 100644 --- a/support/include/FontWriter/Type/types.hpp +++ b/support/include/FontWriter/Type/types.hpp @@ -4,7 +4,7 @@ #include namespace JabyEngine { - using FontPrimitive = GPU::SPRT::Linked; + using FontPrimitive = GPU::SPRT_16::Linked; struct FontInfo { GPU::SizeU16 texture_size; diff --git a/support/include/FontWriter/font_writer.hpp b/support/include/FontWriter/font_writer.hpp index df402ff5..a71554a5 100644 --- a/support/include/FontWriter/font_writer.hpp +++ b/support/include/FontWriter/font_writer.hpp @@ -11,7 +11,7 @@ namespace JabyEngine { FontWriter::write(state, str, color, wiggle, list); \ va_end(list) - GPU::TexPage::Linked tex_page; + GPU::TexPage::Linked tex_page[2]; GPU::SizeI16 font_size; GPU::PageClut clut; GPU::Link* last_primitive; @@ -22,7 +22,8 @@ namespace JabyEngine { static constexpr FontWriter empty() { FontWriter instance; - instance.tex_page = {0}; + instance.tex_page[0] = {0}; + instance.tex_page[1] = {0}; instance.font_size = Make::SizeI16(); instance.clut = Make::PageClut(); instance.last_primitive = nullptr; diff --git a/support/src/FontWriter/src/font_writer.cpp b/support/src/FontWriter/src/font_writer.cpp index 1d17dc98..8adcf1b4 100644 --- a/support/src/FontWriter/src/font_writer.cpp +++ b/support/src/FontWriter/src/font_writer.cpp @@ -48,10 +48,12 @@ namespace JabyEngine { } void FontWriter :: setup(const SimpleTIM& vram_dst, const GPU::SizeI16& font_size) { - this->tex_page = Make::TexPage(vram_dst.get_texture_position(), GPU::TexturePageColor::$4bit).linked(); + for(auto& tex_page : this->tex_page) { + tex_page = Make::TexPage(vram_dst.get_texture_position(), GPU::TexturePageColor::$4bit).linked(); + } this->font_size = font_size; this->clut = Make::PageClut(vram_dst.get_clut_position()); - this->last_primitive = &this->tex_page; + this->last_primitive = nullptr; } void FontWriter :: write(State& state, const char* str, GPU::Color24 color, Wiggle* wiggle, va_list list) { @@ -59,13 +61,15 @@ namespace JabyEngine { return {str + 1, new_str}; }; + if(!this->last_primitive) { + this->last_primitive = &this->tex_page[GPU::update_id()]; + } + const auto row_count = 256/font_size.width; const auto push_char = [&](State& state, char cur_char) -> bool { auto& primitive = GlobalPrimitiveFactory.new_primitive(); primitive->position = state.pos; - primitive->size = this->font_size; - if(wiggle) { const auto [off_x, off_y] = (*wiggle)[(state.wiggle_count++)&0x7]; primitive->position.move(off_x, off_y); @@ -131,12 +135,9 @@ namespace JabyEngine { } void FontWriter :: render() { - const auto update_id = GPU::Display::current_id; - const auto render_id = update_id ^ 1; - this->last_primitive->terminate(); - this->last_primitive = &this->tex_page; + this->last_primitive = nullptr; - GPU::render(this->tex_page); + GPU::render(this->tex_page[GPU::render_id()]); } } \ No newline at end of file diff --git a/support/src/FontWriter/src/global_primitive_buffer.cpp b/support/src/FontWriter/src/global_primitive_buffer.cpp index ed0c3786..72c1d820 100644 --- a/support/src/FontWriter/src/global_primitive_buffer.cpp +++ b/support/src/FontWriter/src/global_primitive_buffer.cpp @@ -8,7 +8,7 @@ namespace JabyEngine { const auto*const buffer_end = start + length; for(auto* cur_prim = start; cur_prim < buffer_end; cur_prim++) { - *cur_prim = FontPrimitive::create(GPU::SPRT::create(Make::AreaI16(), Make::OffsetPageWithClut())); + *cur_prim = FontPrimitive::create(Make::SPRT_16(Make::Vertex(), Make::OffsetPageWithClut())); } GlobalPrimitiveFactory = PrimitiveFactory::create(start, length);