Technical Note : SLE0001
Author : Scott Evans
Created/Modified : 16/9/97, 7/10/97
Description : Describes "double buffering"
 
If you want to program the Yaroze then understanding how double buffering is used and how it works should make the job a little easier. This document describes double buffering the way I see it and should not be taken as an official document on the subject.

What follows is a short description of double buffering and two sample Yaroze programs which show how to achieve double buffering using different techniques.

Double buffering is used on the Yaroze for three things. The screen, ordering table and the primitive/packet buffer.

Screen double buffering

Two areas in the frame buffer are set up with each area big enough for one screen. One area is designated the display area while the other is the drawing area. Anything that gets put into the display area will be seen on the TV screen, but the contents of the drawing area are not seen. While the display area is being shown the next frame is being drawn at the same time in the drawing area. As soon as drawing is complete the two areas are swapped and the new image will be seen. The old display area will be used as the new drawing area and the old drawing area will be the new display area. This is repeated 50 (PAL) or 60 (NTSC) times a second and is how all Yaroze programs achieve “display”.

The display and drawing areas are held in VRAM, which can be thought of as a 1024x512 pixel screen in which you can only see what is on this screen through the display area. So if you move the display area around in VRAM you will see the VRAM contents on your TV.

The two screen buffer areas can be set up using the GsDefDispBuff() function or using the lower level functions PutDrawEnv() and PutDispEnv() functions.

Once you have set up a display and drawing area you can then use GsSwapDispBuff() to swap the two areas. This is usually done after waiting for drawing to finish and waiting for the next frame using DrawSync()/ResetGraph() and VSync() functions. The PutDrawEnv() and PutDispEnv() functions can also be used to swap the two areas.

Ordering tables and packet buffers

The Yaroze also uses double buffering for ordering tables and packet buffers. The packet buffer is an area in which primitives are created. These primitives can then be executed directly by the GPU. The basic graphic types that you get with the Yaroze libraries are GsSPRITE, GsLINE/GsGLINE and GsBOXF. When these are sorted in the ordering table lower level primitives are created based on the information in these structures. These primitives are the ones that are linked to the ordering table and then executed by the GPU when you call GsDrawOt(). You need two packet buffers because the same packet buffer cannot be used by the CPU and the GPU at the same time, so while one buffer is being used by the GPU the other buffer is being filled with primitives by the CPU ready for the next frame.

The ordering table is simply a linked list of primitives. When the ordering table is drawn the primitives are drawn in the order they appear in the list. So primitives at the front of the list will appear to be behind primitives further along the list. This is used to implement Z sorting of primitives.

The same applies to the ordering table as it does to the packet buffer. Primitives cannot be placed in the ordering table if it is being used for drawing, so to eliminate any delay two ordering tables are used. As before while one is being used for drawing the other can be built at the same time.

Example programs

The following are the simplest Yaroze programs. They demonstrate two different ways of achieving the double buffering talked about above. All they do is turn the screen red and display a white box in the centre of the screen.
 

Double buffering example 1 (uses high level graphics functions) 
Double buffering example 2 (uses mostly low level graphics functions) 

This document in word format. 
This document in text format.