Swapping Buffers |
In a double or triple buffered frame buffer, the next scene will be
rendered in a back buffer while the front buffer is being displayed. After
an image has been rendered, it is displayed with a call to grBufferSwap(),
which exchanges the front and back buffers in the Voodoo Graphics subsystem
after swapInterval vertical
retraces. If the swapInterval is 0,
then the buffer swap does not wait for vertical retrace. If the monitor
frequency is 60 Hz, for example, a swapInterval
of 3 results in a maximum frame rate of 20 Hz.
void grBufferSwap( int swapInterval ) |
A swapInterval of 0 may result in visual artefacts, such as ‘tearing’, since a buffer swap can occur during the middle of a screen refresh cycle. This setting is very useful in performance monitoring situations, as true rendering performance can be measured without including the time buffer swaps spend waiting for vertical retrace.
grBufferSwap() does not wait for the specified vertical blanking period; instead, it queues the buffer swap command and returns immediately. If the application is double buffering, the Voodoo Graphics subsystem will stop rendering and wait until the swap occurs before executing more commands. If the application is triple buffering and the third rendering buffer is available, then rendering commands will take place immediately in the third buffer.
A Glide application can poll the Voodoo Graphics subsystem using the
grBufferNumPending()
function to determine the number of buffers waiting to be viewed, although
this is generally not necessary.
int grBufferNumPending( void ) |
grBufferNumPending() returns the number of queued buffer swap requests. The maximum value returned is 7, even though there may be more buffer swap requests in the queue. To minimize rendering latency in response to interactive input, grBufferNumPending() should be called in a loop once per frame until the returned value is less than some small number such as 1, 2, or 3.
Synchronizing with Vertical Retrace
Synchronization to vertical retrace is supported with the grSstVRetraceOn()
and grSstVideoLine() functions.
grSstVRetraceOn() returns
FxBool grSstVRetraceOn( void ) |
grSstVideoLine() returns the current
line number of the display beam.
This number is 0 during vertical retrace and increases as the
display beam progresses down the screen. There are a small number of video
lines that are not displayed at the top of the screen: the vertical backporch.
Thus, grSstVideoLine() returns a small positive number when the
display beam is at the top of the screen; as the beam goes off the bottom
of the screen, the line number may exceed the number returned by grSstScreenHeight().
FxU32 grSstVideoLine( void ) |
The Glide 2.1 release was the first release to include grSstVideoLine(). Earlier versions used grSstVRetraceTicks(), now obsolete.
Note that an application does not need to explicitly synchronize to vertical retrace if it only wishes to remove tearing artefacts. grBufferSwap() will automatically synchronize to vertical retrace if desired.