PS2 Linux Programming

 

Drawing 2D Primitive with a Static Packet

 

 

Introduction

 

In this tutorial the data will be compiled in the static packet area to draw the same four triangle primitives that were presented in the previous tutorial.

 

 

Example Code

 

In this case it is assumed that none of the data will change from frame to frame and the data will therefore be compiled into the static packet area before the program enters the render loop. An outline of the program is given below.

 

 

Main()

{

    .....

    // Get the address of the DMATag that we can call to later.

    int iStaticPacket = VIFStaticDMA.GetPointer();

 

    // Start DIRECT mode transfer

    VIFStaticDMA.StartDirect();

 

    // Compile graphics data

    ..........

 

    // End the direct mode

    VIFStaticDMA.EndDirect();

   

    // Return back to the dynamic chain

    VIFStaticDMA.DMARet();

 

    while(g_bLoop)

        {

        // Fire off the previous frame's buffer

        VIFDynamicDMA.Fire();

 

        // Clear the screen

        SPS2Manager.BeginScene();

 

        // Call the static packet

        VIFDynamicDMA.DMACall(iStaticPacket);

 

        // Swap the buffers

        SPS2Manager.EndScene();

        }

   

    return 0;

}

 

VIFStaticDMA.GetPointer() returns a pointer to the current DMATag which is needed in order to "call" the static packet area in a manner similar to calling a program subroutine. DIRECT mode is started, the graphics data is compiled and DIRECT mode is ended in a manner similar to that of the previous tutorial. Note in this case however that the VIFStaticDMA class methods are being called instead of VIFDynamicDMA class methods. At the end of the packet compilation process, VIFStaticDMA.DMARet() is called, this inserting a DMA return tag into memory, causing the DMAC to return from it's call.

 

In the main render loop, there is now one method, VIFDynamicDMA.DMACall(iStaticPacket), which calls the the static packet data which is situated at the address pointed to by iStaticPacket. This method is very efficient in that the CPU does not have to construct the vertex data every frame.

 

 

Conclusions

 

This tutorial has demonstrated the rendering of static data. When constructing a games program, much of the data is static and can be precompiled and arranged prior to the execution of the main game loop. Using static data in this manner greatly enhances the performance of a games application.

 

 

Dr Henry S Fortuna

University of Abertay Dundee

h.s.fortuna@abertay.ac.uk