mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 19:45:23 -04:00
PS2: Implement double buffering
This commit is contained in:
parent
f486f74dcf
commit
212c5b23e2
@ -16,7 +16,7 @@
|
||||
#include <malloc.h>
|
||||
|
||||
static void* gfx_vertices;
|
||||
extern framebuffer_t fb_color;
|
||||
extern framebuffer_t fb_colors[2];
|
||||
extern zbuffer_t fb_depth;
|
||||
static float vp_hwidth, vp_hheight;
|
||||
|
||||
@ -87,7 +87,7 @@ static void InitDrawingEnv(void) {
|
||||
packet_t *packet = packet_init(30, PACKET_NORMAL); // TODO: is 30 too much?
|
||||
qword_t *q = packet->data;
|
||||
|
||||
q = draw_setup_environment(q, 0, &fb_color, &fb_depth);
|
||||
q = draw_setup_environment(q, 0, &fb_colors[0], &fb_depth);
|
||||
// GS can render from 0 to 4096, so set primitive origin to centre of that
|
||||
q = draw_primitive_xyoffset(q, 0, 2048 - vp_hwidth, 2048 - vp_hheight);
|
||||
|
||||
@ -165,9 +165,6 @@ static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8
|
||||
tex->log2_width = draw_log2(bmp->width);
|
||||
tex->log2_height = draw_log2(bmp->height);
|
||||
|
||||
cc_uintptr addr = (cc_uintptr)tex->pixels;
|
||||
Platform_Log1("ADDR: %x", &addr);
|
||||
|
||||
CopyTextureData(tex->pixels, bmp->width * 4, bmp, rowWidth << 2);
|
||||
return tex;
|
||||
}
|
||||
@ -272,8 +269,8 @@ void Gfx_SetAlphaArgBlend(cc_bool enabled) { }
|
||||
void Gfx_ClearBuffers(GfxBuffers buffers) {
|
||||
// TODO clear only some buffers
|
||||
q = draw_disable_tests(q, 0, &fb_depth);
|
||||
q = draw_clear(q, 0, 2048.0f - fb_color.width / 2.0f, 2048.0f - fb_color.height / 2.0f,
|
||||
fb_color.width, fb_color.height, clearR, clearG, clearB);
|
||||
q = draw_clear(q, 0, 2048.0f - fb_colors[0].width / 2.0f, 2048.0f - fb_colors[0].height / 2.0f,
|
||||
fb_colors[0].width, fb_colors[0].height, clearR, clearG, clearB);
|
||||
UpdateState(0);
|
||||
}
|
||||
|
||||
@ -624,23 +621,29 @@ void Gfx_BeginFrame(void) {
|
||||
}
|
||||
|
||||
void Gfx_EndFrame(void) {
|
||||
//Platform_LogConst("--- EF1 ---");
|
||||
Platform_LogConst("--- EF1 ---");
|
||||
// Double buffering
|
||||
graph_set_framebuffer_filtered(fb_colors[context].address,
|
||||
fb_colors[context].width,
|
||||
fb_colors[context].psm, 0, 0);
|
||||
|
||||
q = draw_framebuffer(q, 0, &fb_colors[context ^ 1]);
|
||||
q = draw_finish(q);
|
||||
|
||||
// Fill out and then send DMA chain
|
||||
DMATAG_END(dma_tag, (q - current->data) - 1, 0, 0, 0);
|
||||
dma_wait_fast();
|
||||
dma_channel_send_chain(DMA_CHANNEL_GIF, current->data, q - current->data, 0, 0);
|
||||
//Platform_LogConst("--- EF2 ---");
|
||||
Platform_LogConst("--- EF2 ---");
|
||||
|
||||
draw_wait_finish();
|
||||
//Platform_LogConst("--- EF3 ---");
|
||||
Platform_LogConst("--- EF3 ---");
|
||||
|
||||
if (gfx_vsync) graph_wait_vsync();
|
||||
if (gfx_minFrameMs) LimitFPS();
|
||||
|
||||
FlipContext();
|
||||
//Platform_LogConst("--- EF4 ---");
|
||||
Platform_LogConst("--- EF4 ---");
|
||||
}
|
||||
|
||||
void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) {
|
||||
|
@ -29,7 +29,7 @@ static char padBuf1[256] __attribute__((aligned(64)));
|
||||
|
||||
struct _DisplayData DisplayInfo;
|
||||
struct _WindowData WindowInfo;
|
||||
framebuffer_t fb_color;
|
||||
framebuffer_t fb_colors[2];
|
||||
zbuffer_t fb_depth;
|
||||
|
||||
void Window_PreInit(void) {
|
||||
@ -68,19 +68,25 @@ static void ResetGfxState(void) {
|
||||
graph_shutdown();
|
||||
graph_vram_clear();
|
||||
|
||||
fb_color.width = DisplayInfo.Width;
|
||||
fb_color.height = DisplayInfo.Height;
|
||||
fb_color.mask = 0;
|
||||
fb_color.psm = GS_PSM_32;
|
||||
fb_color.address = graph_vram_allocate(fb_color.width, fb_color.height, fb_color.psm, GRAPH_ALIGN_PAGE);
|
||||
fb_colors[0].width = DisplayInfo.Width;
|
||||
fb_colors[0].height = DisplayInfo.Height;
|
||||
fb_colors[0].mask = 0;
|
||||
fb_colors[0].psm = GS_PSM_32;
|
||||
fb_colors[0].address = graph_vram_allocate(fb_colors[0].width, fb_colors[0].height, fb_colors[1].psm, GRAPH_ALIGN_PAGE);
|
||||
|
||||
fb_colors[1].width = DisplayInfo.Width;
|
||||
fb_colors[1].height = DisplayInfo.Height;
|
||||
fb_colors[1].mask = 0;
|
||||
fb_colors[1].psm = GS_PSM_32;
|
||||
fb_colors[1].address = graph_vram_allocate(fb_colors[1].width, fb_colors[1].height, fb_colors[1].psm, GRAPH_ALIGN_PAGE);
|
||||
|
||||
fb_depth.enable = 1;
|
||||
fb_depth.method = ZTEST_METHOD_ALLPASS;
|
||||
fb_depth.mask = 0;
|
||||
fb_depth.zsm = GS_ZBUF_32;
|
||||
fb_depth.address = graph_vram_allocate(fb_color.width, fb_color.height, fb_depth.zsm, GRAPH_ALIGN_PAGE);
|
||||
fb_depth.address = graph_vram_allocate(fb_colors[0].width, fb_colors[0].height, fb_depth.zsm, GRAPH_ALIGN_PAGE);
|
||||
|
||||
graph_initialize(fb_color.address, fb_color.width, fb_color.height, fb_color.psm, 0, 0);
|
||||
graph_initialize(fb_colors[1].address, fb_colors[1].width, fb_colors[1].height, fb_colors[1].psm, 0, 0);
|
||||
}
|
||||
|
||||
void Window_Create2D(int width, int height) {
|
||||
@ -219,9 +225,9 @@ void Window_AllocFramebuffer(struct Bitmap* bmp, int width, int height) {
|
||||
packet_t* packet = packet_init(100, PACKET_NORMAL);
|
||||
qword_t* q = packet->data;
|
||||
|
||||
q = draw_setup_environment(q, 0, &fb_color, &fb_depth);
|
||||
q = draw_setup_environment(q, 0, &fb_colors[1], &fb_depth);
|
||||
q = draw_clear(q, 0, 0, 0,
|
||||
fb_color.width, fb_color.height, 170, 170, 170);
|
||||
fb_colors[1].width, fb_colors[1].height, 170, 170, 170);
|
||||
q = draw_finish(q);
|
||||
|
||||
dma_channel_send_normal(DMA_CHANNEL_GIF, packet->data, q - packet->data, 0, 0);
|
||||
@ -238,7 +244,7 @@ void Window_DrawFramebuffer(Rect2D r, struct Bitmap* bmp) {
|
||||
qword_t* q = packet->data;
|
||||
|
||||
q = draw_texture_transfer(q, bmp->scan0, bmp->width, bmp->height, GS_PSM_32,
|
||||
fb_color.address, fb_color.width);
|
||||
fb_colors[1].address, fb_colors[1].width);
|
||||
q = draw_texture_flush(q);
|
||||
|
||||
dma_channel_send_chain(DMA_CHANNEL_GIF, packet->data, q - packet->data, 0, 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user