diff --git a/examples/fragment_light/source/main.c b/examples/fragment_light/source/main.c index be14f15..853aee4 100644 --- a/examples/fragment_light/source/main.c +++ b/examples/fragment_light/source/main.c @@ -206,9 +206,8 @@ int main() // Main loop while (aptMainLoop()) { - gspWaitForVBlank(); // Synchronize with the start of VBlank - gfxSwapBuffersGpu(); // Swap the framebuffers so that the frame that we rendered last frame is now visible - hidScanInput(); // Read the user input + C3D_VideoSync(); + hidScanInput(); // Respond to user input u32 kDown = hidKeysDown(); @@ -231,9 +230,6 @@ int main() C3D_RenderBufTransfer(&rb, (u32*)gfxGetFramebuffer(GFX_TOP, GFX_RIGHT, NULL, NULL), DISPLAY_TRANSFER_FLAGS); C3D_RenderBufClear(&rb); } - - // Flush the framebuffers out of the data cache (not necessary with pure GPU rendering) - //gfxFlushBuffers(); } // Deinitialize the scene diff --git a/examples/gputest/source/main.c b/examples/gputest/source/main.c index 1e2c558..3c92a59 100644 --- a/examples/gputest/source/main.c +++ b/examples/gputest/source/main.c @@ -163,8 +163,7 @@ int main() // Main loop while (aptMainLoop()) { - gspWaitForVBlank(); - gfxSwapBuffersGpu(); + C3D_VideoSync(); hidScanInput(); u32 kDown = hidKeysDown(); diff --git a/examples/immediate/source/main.c b/examples/immediate/source/main.c index 2183475..42f74e9 100644 --- a/examples/immediate/source/main.c +++ b/examples/immediate/source/main.c @@ -88,9 +88,8 @@ int main() // Main loop while (aptMainLoop()) { - gspWaitForVBlank(); // Synchronize with the start of VBlank - gfxSwapBuffersGpu(); // Swap the framebuffers so that the frame that we rendered last frame is now visible - hidScanInput(); // Read the user input + C3D_VideoSync(); + hidScanInput(); // Respond to user input u32 kDown = hidKeysDown(); @@ -102,9 +101,6 @@ int main() C3D_Flush(); C3D_RenderBufTransfer(&rb, (u32*)gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL), DISPLAY_TRANSFER_FLAGS); C3D_RenderBufClear(&rb); - - // Flush the framebuffers out of the data cache (not necessary with pure GPU rendering) - gfxFlushBuffers(); } // Deinitialize the scene diff --git a/examples/simple_tri/source/main.c b/examples/simple_tri/source/main.c index 081857d..72e9153 100644 --- a/examples/simple_tri/source/main.c +++ b/examples/simple_tri/source/main.c @@ -106,9 +106,8 @@ int main() // Main loop while (aptMainLoop()) { - gspWaitForVBlank(); // Synchronize with the start of VBlank - gfxSwapBuffersGpu(); // Swap the framebuffers so that the frame that we rendered last frame is now visible - hidScanInput(); // Read the user input + C3D_VideoSync(); + hidScanInput(); // Respond to user input u32 kDown = hidKeysDown(); @@ -120,9 +119,6 @@ int main() C3D_Flush(); C3D_RenderBufTransfer(&rb, (u32*)gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL), DISPLAY_TRANSFER_FLAGS); C3D_RenderBufClear(&rb); - - // Flush the framebuffers out of the data cache (not necessary with pure GPU rendering) - gfxFlushBuffers(); } // Deinitialize the scene diff --git a/examples/textured_cube/source/main.c b/examples/textured_cube/source/main.c index ffa811e..54c4945 100644 --- a/examples/textured_cube/source/main.c +++ b/examples/textured_cube/source/main.c @@ -204,9 +204,8 @@ int main() // Main loop while (aptMainLoop()) { - gspWaitForVBlank(); // Synchronize with the start of VBlank - gfxSwapBuffersGpu(); // Swap the framebuffers so that the frame that we rendered last frame is now visible - hidScanInput(); // Read the user input + C3D_VideoSync(); + hidScanInput(); // Respond to user input u32 kDown = hidKeysDown(); @@ -218,9 +217,6 @@ int main() C3D_Flush(); C3D_RenderBufTransfer(&rb, (u32*)gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL), DISPLAY_TRANSFER_FLAGS); C3D_RenderBufClear(&rb); - - // Flush the framebuffers out of the data cache (not necessary with pure GPU rendering) - gfxFlushBuffers(); } // Deinitialize the scene diff --git a/include/c3d/base.h b/include/c3d/base.h index 91dbbd3..5a33d8c 100644 --- a/include/c3d/base.h +++ b/include/c3d/base.h @@ -37,6 +37,12 @@ static inline void C3D_Flush(void) C3D_FlushAwait(); } +static inline void C3D_VideoSync(void) +{ + gspWaitForEvent(GSPGPU_EVENT_VBlank0, false); + gfxSwapBuffersGpu(); +} + // Fixed vertex attributes C3D_FVec* C3D_FixedAttribGetWritePtr(int id);