RSX is the 3D accelerator processor of the PS3. Here are the basic steps to get it handle your 3D objects in your application.
You may also use basic RSX management for simple frame buffer management with double buffering .
Display management
The basic steps for managing the display are the following.
Initialization
- Create a RSX context (see rsxInit).
- Configure the video (video mode, color depth, aspect ratio). See videoConfigure for doing this. Default values can be obtained using videoGetState.
- Set flip mode (see gcmSetFlipMode). To prevent unpleasant flickering, you usually want to synchronize screen flipping with vertical refresh (use the GCM_FLIP_VSYNC value).
- Allocate buffers in video memory. If you want to perform double buffering, you need to allocate two buffers. In the most commonly used color depth mode (32-bit = 4 bytes), each buffer has a size of
screen_width*screen_height*4
. For each buffer, the steps are the following:
- Allocate a 64-byte aligned buffer in RSX memory with rsxMemalign.
- Generate an offset for the buffer address using rsxAddressToOffset.
- Setup the buffer using gcmSetDisplayBuffer, providing the buffer number (starting from 0) and the buffer offset generated from the previous step.
- Allocate a depth buffer, aligned to 64-byte boundary, which size can be
screen_width*screen_height*2
if using 16-bit depth mode. Use rsxMemalign for this. Generate an offset to that depth buffer with rsxAddressToOffset.
- Reset the flip status using gcmResetFlipStatus.
Setting the render target and flipping
For each frame to be drawn, the steps are the following:
- Write the pixel data to the buffer which is not being displayed. For instance, if buffer 0 is being displayed, write to buffer 1.
- Push a flip command using gcmSetFlip specifying the buffer to be displayed (the one you just updated).
- Flush the RSX buffer (rsxFlushBuffer).
- Force the RSX to wait for next flip (gcmSetWaitFlip).
- Set the new render target using rsxSetSurface. You'll have to provide that function a pointer to a gcmSurface structure you filled with proper color depth mode, buffer offset, depth buffer mode, etc. You can borrow proper valid values from the various graphics samples in the samples directory.
Then, before modifying the next buffer, ensure the flip actually has occurred by querying for the flip status (gcmGetFlipStatus) in a loop. Add timing after each negative query in order not to take too much CPU time. For this, a usleep(200)
call should be fine.
- Todo:
- Finish that page.