Implement buffered font loader
This commit is contained in:
parent
2464e67c59
commit
e916fc358b
|
@ -1,18 +1,32 @@
|
|||
#pragma once
|
||||
#include "../../System/IOPorts/gpu_io.hpp"
|
||||
#include "linked_elements.hpp"
|
||||
#include "primitive_support_types.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace GPU {
|
||||
struct TexPage : public internal::LinkedElementCreator<TexPage> {
|
||||
static constexpr bool is_render_primitive = true;
|
||||
|
||||
struct GPU_IO::GP0 value;
|
||||
|
||||
static constexpr TexPage create(const PositionU16& tex_pos, TexturePageColor tex_color, SemiTransparency transparency = SemiTransparency::B_Half_add_F_Half, bool dither = false) {
|
||||
return TexPage{.value = GPU_IO::Command::TexPage(tex_pos, transparency, tex_color, dither, false)};
|
||||
}
|
||||
};
|
||||
}
|
||||
#pragma once
|
||||
#include "../../System/IOPorts/gpu_io.hpp"
|
||||
#include "linked_elements.hpp"
|
||||
#include "primitive_support_types.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace GPU {
|
||||
struct TexPage : public internal::LinkedElementCreator<TexPage> {
|
||||
static constexpr bool is_render_primitive = true;
|
||||
|
||||
struct GPU_IO::GP0 value;
|
||||
|
||||
static constexpr TexPage create(const PositionU16& tex_pos, TexturePageColor tex_color, SemiTransparency transparency = SemiTransparency::B_Half_add_F_Half, bool dither = false) {
|
||||
return TexPage{.value = GPU_IO::Command::TexPage(tex_pos, transparency, tex_color, dither, false)};
|
||||
}
|
||||
};
|
||||
|
||||
struct CPU2VRAM {
|
||||
struct GPU_IO::GP0 cmd;
|
||||
struct GPU_IO::GP0 pos;
|
||||
struct GPU_IO::GP0 size;
|
||||
|
||||
static constexpr CPU2VRAM create(const AreaU16& dst) {
|
||||
return CPU2VRAM{
|
||||
.cmd = GPU_IO::Command::CPU2VRAM_Blitting(),
|
||||
.pos = GPU_IO::Command::TopLeftPosition(dst.position),
|
||||
.size = GPU_IO::Command::WidthHeight(dst.size)
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -54,13 +54,61 @@ namespace JabyEngine {
|
|||
}
|
||||
};
|
||||
|
||||
Line lines[FontSize.height];
|
||||
|
||||
void load_char(const uint16_t* bit_map) {
|
||||
for(auto& cur_line : this->lines) {
|
||||
cur_line.load(__builtin_bswap16(*bit_map++));
|
||||
struct Letter : public GPU::internal::LinkedElementCreator<Letter> {
|
||||
CPU2VRAM cmd;
|
||||
Line lines[FontSize.height];
|
||||
|
||||
void setup(const SizeU16& size) {
|
||||
this->cmd.cmd = GPU_IO::Command::CPU2VRAM_Blitting();
|
||||
this->cmd.size = GPU_IO::Command::WidthHeight(size);
|
||||
}
|
||||
|
||||
void load_to(const PositionU16& pos, const uint16_t* bit_map) {
|
||||
this->cmd.pos = GPU_IO::Command::TopLeftPosition(pos);
|
||||
for(auto& cur_line : this->lines) {
|
||||
cur_line.load(__builtin_bswap16(*bit_map++));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Letter::Linked letter_buffer[2][4];
|
||||
uint8_t cur_buffer;
|
||||
uint8_t free_idx;
|
||||
|
||||
void setup() {
|
||||
for(auto& buffer : this->letter_buffer) {
|
||||
for(auto& letter : buffer) {
|
||||
letter->setup(SizeU16::create(16, 16));
|
||||
letter.set_link_identitiy();
|
||||
}
|
||||
}
|
||||
|
||||
this->cur_buffer = 0;
|
||||
this->free_idx = 0;
|
||||
}
|
||||
|
||||
void load_to(const PositionU16& pos, const uint16_t* bit_map) {
|
||||
auto& cur_letter = this->letter_buffer[this->cur_buffer][this->free_idx++];
|
||||
|
||||
cur_letter->load_to(pos, bit_map);
|
||||
if(this->free_idx == 4) {
|
||||
cur_letter.terminate();
|
||||
GPU::render(this->letter_buffer[this->cur_buffer][0]);
|
||||
this->free_idx = 0;
|
||||
this->cur_buffer ^= 1;
|
||||
}
|
||||
|
||||
else {
|
||||
cur_letter.concat(this->letter_buffer[this->cur_buffer][this->free_idx]);
|
||||
}
|
||||
}
|
||||
|
||||
void flush() {
|
||||
if(this->free_idx > 0) {
|
||||
this->letter_buffer[this->cur_buffer][this->free_idx - 1].terminate();
|
||||
GPU::render(this->letter_buffer[this->cur_buffer][0]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct SpecialChar {
|
||||
|
@ -94,23 +142,16 @@ namespace JabyEngine {
|
|||
static const auto LowerCaseLetter = RangeChar{{0x81, 64}, 26};
|
||||
|
||||
void load() {
|
||||
FontBuffer buffer[2];
|
||||
// Linkd create here
|
||||
FontBuffer font_buffer;
|
||||
|
||||
font_buffer.setup();
|
||||
|
||||
GPU::internal::DMA::Receive::prepare();
|
||||
for(size_t n = 0; n < 4; n++) {
|
||||
auto& cur_buffer = buffer[n&0x1];
|
||||
const auto vram_pos = PositionU16::create(16*n, 0);
|
||||
|
||||
cur_buffer.load_char(SysCall::Krom2RawAdd(0x8200 | (UpperCaseLetter.start_char.base_offset + n)));
|
||||
|
||||
GPU::internal::DMA::wait();
|
||||
GPU::internal::DMA::Receive::set_dst(vram_pos, SizeU16::create(16, 16));
|
||||
GPU::internal::DMA::Receive::set_src(reinterpret_cast<const uintptr_t>(&cur_buffer.lines));
|
||||
GPU::internal::DMA::Receive::start(sizeof(FontBuffer)/4/16);
|
||||
for(size_t n = 0; n < 5; n++) {
|
||||
font_buffer.load_to(PositionU16::create(16*n, 0), SysCall::Krom2RawAdd(0x8200 | (UpperCaseLetter.start_char.base_offset + n)));
|
||||
}
|
||||
|
||||
GPU::internal::DMA::wait();
|
||||
GPU::internal::DMA::end();
|
||||
font_buffer.flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue