void sf2d_end_frame(bool shouldTakeScreenShot)
{
GPU_FinishDrawing();
GPUCMD_Finalize();
GPUCMD_FlushAndRun(NULL);
gspWaitForP3D();
//Copy the GPU rendered FB to the screen FB
if (cur_screen == GFX_TOP) {
GX_SetDisplayTransfer(NULL, gpu_fb_addr, GX_BUFFER_DIM(240, 400),
(u32 *)gfxGetFramebuffer(GFX_TOP, cur_side, NULL, NULL),
GX_BUFFER_DIM(240, 400), 0x1000);
if(shouldTakeScreenShot){
const int dimx = 240, dimy = 400;
FILE *fp = fopen("top.ppm", "wb"); /* b - binary mode */
fprintf(fp, "P6\n%d %d\n255\n", dimx, dimy);
u8 * buf = gfxGetFramebuffer(GFX_TOP, cur_side, NULL, NULL);
int i;
/* Switch from BGR to RGB */
for(i=0; i < 240*400; i++){
u8 buf1 = buf[i*3+0];
buf[i*3+0] = buf[i*3+2];
buf[i*3+2] = buf1;
}
fwrite(buf, 240*400*3,1, fp);
fclose(fp);
}
} else {
GX_SetDisplayTransfer(NULL, gpu_fb_addr, GX_BUFFER_DIM(240, 320),
(u32 *)gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL),
GX_BUFFER_DIM(240, 320), 0x1000);
if(shouldTakeScreenShot){
const int dimx = 240, dimy = 320;
FILE *fp = fopen("bottom.ppm", "wb"); /* b - binary mode */
fprintf(fp, "P6\n%d %d\n255\n", dimx, dimy);
u8 * buf = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
int i;
/* Switch from BGR to RGB */
for(i=0; i < 240*320; i++){
u8 buf1 = buf[i*3+0];
buf[i*3+0] = buf[i*3+2];
buf[i*3+2] = buf1;
}
fwrite(buf, 240*320*3,1, fp);
fclose(fp);
}
}
gspWaitForPPF();
//Clear the screen
GX_SetMemoryFill(NULL, gpu_fb_addr, clear_color, &gpu_fb_addr[0x2EE00],
0x201, gpu_depth_fb_addr, 0x00000000, &gpu_depth_fb_addr[0x2EE00], 0x201);
gspWaitForPSC0();
}