PS2 Linux Programming


Drawing 2D Primitive with a Static Packet





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.






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

    int iStaticPacket = VIFStaticDMA.GetPointer();


    // Start DIRECT mode transfer



    // Compile graphics data



    // End the direct mode



    // Return back to the dynamic chain





        // Fire off the previous frame's buffer



        // Clear the screen



        // Call the static packet



        // Swap the buffers




    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.





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