Establish VSyncCallback rendering
This commit is contained in:
@@ -24,6 +24,7 @@ namespace JabyEngine {
|
||||
|
||||
static uint32_t exchange_buffer_and_display();
|
||||
};
|
||||
extern bool vsync_lock_callback;
|
||||
|
||||
void wait_vsync(uint8_t syncs);
|
||||
|
||||
@@ -70,10 +71,12 @@ namespace JabyEngine {
|
||||
|
||||
static void wait() {
|
||||
DMA_IO::GPU.wait();
|
||||
vsync_lock_callback = false;
|
||||
}
|
||||
|
||||
static void end() {
|
||||
reset_cmd_buffer();
|
||||
vsync_lock_callback = false;
|
||||
}
|
||||
|
||||
struct Receive {
|
||||
@@ -100,6 +103,7 @@ namespace JabyEngine {
|
||||
static void start(uint16_t blockCount, uint16_t wordsPerBlock = 0x10) {
|
||||
using SyncMode1 = DMA_IO_Values::BCR::SyncMode1;
|
||||
|
||||
vsync_lock_callback = true;
|
||||
#ifdef __SUPPORT_PS3__
|
||||
DMA_IO::GPU.set_adr(MADR);
|
||||
DMA::MADR += (blockCount * wordsPerBlock) << 2;
|
||||
|
@@ -15,8 +15,10 @@ namespace JabyEngine {
|
||||
static SysCall::InterruptVerifierResult interrupt_verifier();
|
||||
static void interrupt_handler(uint32_t);
|
||||
|
||||
static uint8_t vsync_counter = 0;
|
||||
auto irq_callback = SysCall::InterruptCallback::from(interrupt_verifier, interrupt_handler);
|
||||
auto irq_callback = SysCall::InterruptCallback::from(interrupt_verifier, interrupt_handler);
|
||||
VSyncCallback vsync_callback = nullptr; //< TODO: Typedef later
|
||||
static uint8_t vsync_counter = 0;
|
||||
bool vsync_lock_callback = false;
|
||||
|
||||
static SysCall::InterruptVerifierResult interrupt_verifier() {
|
||||
if(Interrupt::is_irq(Interrupt::VBlank)) {
|
||||
@@ -33,6 +35,9 @@ namespace JabyEngine {
|
||||
vsync_counter++;
|
||||
MasterTime::value++;
|
||||
|
||||
if(vsync_callback && !vsync_lock_callback) {
|
||||
vsync_callback();
|
||||
}
|
||||
//Callback::internal::VSync::execute();
|
||||
SysCall::ReturnFromException();
|
||||
}
|
||||
@@ -48,20 +53,19 @@ namespace JabyEngine {
|
||||
return draw_area_y;
|
||||
}
|
||||
|
||||
uint8_t dst_value = 0;
|
||||
|
||||
void wait_vsync(uint8_t syncs) {
|
||||
volatile auto& vsync_count = reinterpret_cast<volatile uint8_t&>(vsync_counter);
|
||||
|
||||
dst_value = vsync_count + syncs;
|
||||
while(vsync_count != dst_value);
|
||||
|
||||
const uint8_t vsync_dst_value = vsync_count + syncs;
|
||||
while(vsync_count != vsync_dst_value);
|
||||
}
|
||||
|
||||
void render(const uint32_t* data, size_t words) {
|
||||
wait_ready_for_CMD();
|
||||
#ifdef __SUPPORT_PS3__
|
||||
// TODO: Doesn't matter anymore...?
|
||||
// The PS3 needs explict change to FiFo
|
||||
GPU_IO::GP1.set_dma_direction(GPU_IO_Values::GPUSTAT::DMADirection::Fifo);
|
||||
//GPU_IO::GP1.set_dma_direction(GPU_IO_Values::GPUSTAT::DMADirection::Fifo);
|
||||
#endif // __SUPPORT_PS3__
|
||||
|
||||
for(size_t n = 0; n < words; n++) {
|
||||
@@ -98,16 +102,24 @@ namespace JabyEngine {
|
||||
GPU_IO::GP1.set_vertical_display_range( y, y + Display::Height + PS3_CorrectionY);
|
||||
}
|
||||
|
||||
uint8_t swap_buffers_vsync(uint8_t syncs, bool clear_screen) {
|
||||
// Waits for finish FIFO
|
||||
internal::wait_ready_for_CMD();
|
||||
void set_vsync_callback(VSyncCallback callback) {
|
||||
internal::vsync_callback = callback;
|
||||
}
|
||||
|
||||
internal::wait_vsync(syncs);
|
||||
void swap_buffers(bool clear_screen) {
|
||||
const int16_t draw_offset_y = internal::Display::exchange_buffer_and_display();
|
||||
internal::set_draw_offset(GPU::PositionI16::create(0, draw_offset_y));
|
||||
if(clear_screen) {
|
||||
internal::quick_fill_fast(Color24::Black(), AreaU16::create(0, static_cast<uint16_t>(draw_offset_y), Display::Width, Display::Height));
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t swap_buffers_vsync(uint8_t syncs, bool clear_screen) {
|
||||
// Waits for finish FIFO
|
||||
internal::wait_ready_for_CMD();
|
||||
internal::wait_vsync(syncs);
|
||||
|
||||
swap_buffers(clear_screen);
|
||||
return Display::current_id;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user