Graphics Utility Library


Functions

void sceGuDepthBuffer (void *zbp, int zbw)
 Set depth buffer parameters.
void sceGuDispBuffer (int width, int height, void *dispbp, int dispbw)
 Set display buffer parameters.
void sceGuDrawBuffer (int psm, void *fbp, int fbw)
 Set draw buffer parameters (and store in context for buffer-swap).
void sceGuDrawBufferList (int psm, void *fbp, int fbw)
 Set draw buffer directly, not storing parameters in the context.
int sceGuDisplay (int state)
 Turn display on or off.
void sceGuDepthFunc (int function)
 Select which depth-test function to use.
void sceGuDepthMask (int mask)
 Mask depth buffer writes.
void sceGuDepthOffset (unsigned int offset)
void sceGuDepthRange (int near, int far)
 Set which range to use for depth calculations.
void sceGuFog (float near, float far, unsigned int color)
void sceGuInit (void)
 Initalize the GU system.
void sceGuTerm (void)
 Shutdown the GU system.
void sceGuBreak (int a0)
void sceGuContinue (void)
void * sceGuSetCallback (int signal, void(*callback)(int))
 Setup signal handler.
void sceGuSignal (int signal, int behavior)
 Trigger signal to call code from the command stream.
void sceGuSendCommandf (int cmd, float argument)
 Send raw float-command to the GE.
void sceGuSendCommandi (int cmd, int argument)
 Send raw command to the GE.
void * sceGuGetMemory (int size)
 Allocate memory on the current display list for temporary storage.
void sceGuStart (int cid, void *list)
 Start filling a new display-context.
int sceGuFinish (void)
 Finish current display list and go back to the parent context.
int sceGuFinishId (unsigned int id)
 Finish current display list and go back to the parent context, sending argument id for the finish callback.
void sceGuCallList (const void *list)
 Call previously generated display-list.
void sceGuCallMode (int mode)
 Set wether to use stack-based calls or signals to handle execution of called lists.
int sceGuCheckList (void)
 Check how large the current display-list is.
void sceGuSendList (int mode, const void *list, PspGeContext *context)
 Send a list to the GE directly.
void * sceGuSwapBuffers (void)
 Swap display and draw buffer.
int sceGuSync (int mode, int a1)
 Wait until display list has finished executing.
void sceGuDrawArray (int prim, int vtype, int count, const void *indices, const void *vertices)
 Draw array of vertices forming primitives.
void sceGuBeginObject (int vtype, int count, const void *indices, const void *vertices)
 Begin conditional rendering of object.
void sceGuEndObject (void)
 End conditional rendering of object.
void sceGuSetStatus (int state, int status)
 Enable or disable GE state.
int sceGuGetStatus (int state)
 Get if state is currently enabled or disabled.
void sceGuSetAllStatus (int status)
 Set the status on all 22 available states.
int sceGuGetAllStatus (void)
 Query status on all 22 available states.
void sceGuEnable (int state)
 Enable GE state.
void sceGuDisable (int state)
 Disable GE state.
void sceGuLight (int light, int type, int components, const ScePspFVector3 *position)
 Set light parameters.
void sceGuLightAtt (int light, float atten0, float atten1, float atten2)
 Set light attenuation.
void sceGuLightColor (int light, int component, unsigned int color)
 Set light color.
void sceGuLightMode (int mode)
 Set light mode.
void sceGuLightSpot (int light, const ScePspFVector3 *direction, float exponent, float cutoff)
 Set spotlight parameters.
void sceGuClear (int flags)
 Clear current drawbuffer.
void sceGuClearColor (unsigned int color)
 Set the current clear-color.
void sceGuClearDepth (unsigned int depth)
 Set the current clear-depth.
void sceGuClearStencil (unsigned int stencil)
 Set the current stencil clear value.
void sceGuPixelMask (unsigned int mask)
 Set mask for which bits of the pixels to write.
void sceGuColor (unsigned int color)
 Set current primitive color.
void sceGuColorFunc (int func, unsigned int color, unsigned int mask)
 Set the color test function.
void sceGuColorMaterial (int components)
 Set which color components that the material will receive.
void sceGuAlphaFunc (int func, int value, int mask)
 Set the alpha test parameters.
void sceGuAmbient (unsigned int color)
void sceGuAmbientColor (unsigned int color)
void sceGuBlendFunc (int op, int src, int dest, unsigned int srcfix, unsigned int destfix)
 Set the blending-mode.
void sceGuMaterial (int mode, int color)
void sceGuModelColor (unsigned int emissive, unsigned int ambient, unsigned int diffuse, unsigned int specular)
void sceGuStencilFunc (int func, int ref, int mask)
 Set stencil function and reference value for stencil testing.
void sceGuStencilOp (int fail, int zfail, int zpass)
 Set the stencil test actions.
void sceGuSpecular (float power)
 Set the specular power for the material.
void sceGuFrontFace (int order)
 Set the current face-order (for culling).
void sceGuLogicalOp (int op)
 Set color logical operation.
void sceGuSetDither (const ScePspIMatrix4 *matrix)
 Set ordered pixel dither matrix.
void sceGuShadeModel (int mode)
 Set how primitives are shaded.
void sceGuCopyImage (int psm, int sx, int sy, int width, int height, int srcw, void *src, int dx, int dy, int destw, void *dest)
 Image transfer using the GE.
void sceGuTexEnvColor (unsigned int color)
 Specify the texture environment color.
void sceGuTexFilter (int min, int mag)
 Set how the texture is filtered.
void sceGuTexFlush (void)
 Flush texture page-cache.
void sceGuTexFunc (int tfx, int tcc)
 Set how textures are applied.
void sceGuTexImage (int mipmap, int width, int height, int tbw, const void *tbp)
 Set current texturemap.
void sceGuTexLevelMode (unsigned int a0, float f12)
void sceGuTexMapMode (int mode, unsigned int a1, unsigned int a2)
 Set the texture-mapping mode.
void sceGuTexMode (int tpsm, int maxmips, int a2, int swizzle)
 Set texture-mode parameters.
void sceGuTexOffset (float u, float v)
 Set texture offset.
void sceGuTexProjMapMode (int mode)
 Set texture projection-map mode.
void sceGuTexScale (float u, float v)
 Set texture scale.
void sceGuTexSlope (float slope)
void sceGuTexSync ()
 Synchronize rendering pipeline with image upload.
void sceGuTexWrap (int u, int v)
 Set if the texture should repeat or clamp.
void sceGuClutLoad (int num_blocks, const void *cbp)
 Upload CLUT (Color Lookup Table).
void sceGuClutMode (unsigned int cpsm, unsigned int a1, unsigned int a2, unsigned int a3)
 Set current CLUT mode.
void sceGuOffset (unsigned int x, unsigned int y)
 Set virtual coordinate offset.
void sceGuScissor (int x, int y, int w, int h)
 Set what to scissor within the current viewport.
void sceGuViewport (int cx, int cy, int width, int height)
 Set current viewport.
void sceGuDrawBezier (int vtype, int ucount, int vcount, const void *indices, const void *vertices)
 Draw bezier surface.
void sceGuPatchDivide (unsigned int ulevel, unsigned int vlevel)
 Set dividing for patches (beziers and splines).
void sceGuPatchFrontFace (unsigned int a0)
void sceGuPatchPrim (int prim)
 Set primitive for patches (beziers and splines).
void sceGuDrawSpline (int vtype, int ucount, int vcount, int uedge, int vedge, const void *indices, const void *vertices)
void sceGuSetMatrix (int type, const ScePspFMatrix4 *matrix)
 Set transform matrices.
void sceGuBoneMatrix (unsigned int index, const ScePspFMatrix4 *matrix)
 Specify skinning matrix entry.
void sceGuMorphWeight (int index, float weight)
 Specify morph weight entry.
void sceGuDrawArrayN (int primitive_type, int vertex_type, int count, int a3, const void *indices, const void *vertices)
void guSwapBuffersBehaviour (int behaviour)
 Set how the display should be set.
void guSwapBuffersCallback (GuSwapBuffersCallback callback)
 Set a buffer swap callback to allow for more advanced buffer methods without hacking the library.


Function Documentation

void guSwapBuffersBehaviour ( int  behaviour  ) 

Set how the display should be set.

Available behaviours are:

Do remember that this swaps the pointers internally, regardless of setting, so be careful to wait until the next vertical blank or use another buffering algorithm (see guSwapBuffersCallback()).

void guSwapBuffersCallback ( GuSwapBuffersCallback  callback  ) 

Set a buffer swap callback to allow for more advanced buffer methods without hacking the library.

The GuSwapBuffersCallback is defined like this:

 void swapBuffersCallback(void** display, void** render);
and on entry they contain the variables that are to be set. To change the pointers that will be used, just write the new pointers. Example of a triple-buffering algorithm:
 void* doneBuffer;
 void swapBuffersCallback(void** display, void** render)
 {
  void* active = doneBuffer;
  doneBuffer = *display;
     *display = active;
 }

Parameters:
callback - Callback to access when buffers are swapped. Pass 0 to disable.

void sceGuAlphaFunc ( int  func,
int  value,
int  mask 
)

Set the alpha test parameters.

Available comparison functions are:

Parameters:
func - Specifies the alpha comparison function.
value - Specifies the reference value that incoming alpha values are compared to.
mask - Specifies the mask that both values are ANDed with before comparison.

void sceGuAmbient ( unsigned int  color  ) 

void sceGuAmbientColor ( unsigned int  color  ) 

void sceGuBeginObject ( int  vtype,
int  count,
const void *  indices,
const void *  vertices 
)

Begin conditional rendering of object.

If no vertices passed into this function are inside the scissor region, it will skip rendering the object. There can be up to 32 levels of conditional testing, and all levels HAVE to be terminated by sceGuEndObject().

Example: test a boundingbox against the frustum, and if visible, render object
Parameters:
vtype - Vertex type to process
count - Number of vertices to test
indices - Optional list to an index-list
vertices - Pointer to a vertex-list

void sceGuBlendFunc ( int  op,
int  src,
int  dest,
unsigned int  srcfix,
unsigned int  destfix 
)

Set the blending-mode.

Keys for the blending operations:

Available blending-operations are:

Available blending-functions are:

Parameters:
op - Blending Operation
src - Blending function for source operand
dest - Blending function for dest operand
srcfix - Fix value for GU_FIX (source operand)
destfix - Fix value for GU_FIX (dest operand)

void sceGuBoneMatrix ( unsigned int  index,
const ScePspFMatrix4 matrix 
)

Specify skinning matrix entry.

To enable vertex skinning, pass GU_WEIGHTS(n), where n is between 1-8, and pass available GU_WEIGHT_??? declaration. This will change the amount of weights passed in the vertex araay, and by setting the skinning, matrices, you will multiply each vertex every weight and vertex passed.

Please see sceGuDrawArray() for vertex format information.

Parameters:
index - Skinning matrix index (0-7)
matrix - Matrix to set

void sceGuBreak ( int  a0  ) 

void sceGuCallList ( const void *  list  ) 

Call previously generated display-list.

Parameters:
list - Display list to call

void sceGuCallMode ( int  mode  ) 

Set wether to use stack-based calls or signals to handle execution of called lists.

Parameters:
mode - GU_TRUE(1) to enable signals, GU_FALSE(0) to disable signals and use normal calls instead.

int sceGuCheckList ( void   ) 

Check how large the current display-list is.

Returns:
The size of the current display list

void sceGuClear ( int  flags  ) 

Clear current drawbuffer.

Available clear-flags are (OR them together to get final clear-mode):

Parameters:
flags - Which part of the buffer to clear

void sceGuClearColor ( unsigned int  color  ) 

Set the current clear-color.

Parameters:
color - Color to clear with

void sceGuClearDepth ( unsigned int  depth  ) 

Set the current clear-depth.

Parameters:
depth - Set which depth to clear with (0x0000-0xffff)

void sceGuClearStencil ( unsigned int  stencil  ) 

Set the current stencil clear value.

Parameters:
stencil - Set which stencil value to clear with (0-255)

void sceGuClutLoad ( int  num_blocks,
const void *  cbp 
)

Upload CLUT (Color Lookup Table).

Note:
Data must be aligned to 1 quad word (16 bytes)
Parameters:
num_blocks - How many blocks of 8 entries to upload (32*8 is 256 colors)
cbp - Pointer to palette (16 byte aligned)

void sceGuClutMode ( unsigned int  cpsm,
unsigned int  a1,
unsigned int  a2,
unsigned int  a3 
)

Set current CLUT mode.

Available pixel formats for palettes are:

Parameters:
cpsm - Which pixel format to use for the palette
a1 - Unknown, set to 0
a2 - Unknown, set to 0
a3 - Unknown, set to 0

void sceGuColor ( unsigned int  color  ) 

Set current primitive color.

Parameters:
color - Which color to use (overriden by vertex-colors)

void sceGuColorFunc ( int  func,
unsigned int  color,
unsigned int  mask 
)

Set the color test function.

The color test is only performed while GU_COLOR_TEST is enabled.

Available functions are:

Example: Reject any pixel that does not have 0 as the blue channel
 sceGuColorFunc(GU_EQUAL,0,0xff0000);
Parameters:
func - Color test function
color - Color to test against
mask - Mask ANDed against both source and destination when testing

void sceGuColorMaterial ( int  components  ) 

Set which color components that the material will receive.

The components are ORed together from the following values:

Parameters:
components - Which components to receive

void sceGuContinue ( void   ) 

void sceGuCopyImage ( int  psm,
int  sx,
int  sy,
int  width,
int  height,
int  srcw,
void *  src,
int  dx,
int  dy,
int  destw,
void *  dest 
)

Image transfer using the GE.

Note:
Data must be aligned to 1 quad word (16 bytes)
Example: Copy a fullscreen 32-bit image from RAM to VRAM
 sceGuCopyImage(GU_PSM_8888,0,0,480,272,512,pixels,0,0,512,(void*)(((unsigned int)framebuffer)+0x4000000));
Parameters:
psm - Pixel format for buffer
sx - Source X
sy - Source Y
width - Image width
height - Image height
srcw - Source buffer width (block aligned)
src - Source pointer
dx - Destination X
dy - Destination Y
destw - Destination buffer width (block aligned)
dest - Destination pointer

void sceGuDepthBuffer ( void *  zbp,
int  zbw 
)

Set depth buffer parameters.

Parameters:
zbp - VRAM pointer where the depthbuffer should start
zbw - The width of the depth-buffer (block-aligned)

void sceGuDepthFunc ( int  function  ) 

Select which depth-test function to use.

Valid choices for the depth-test are:

Parameters:
function - Depth test function to use

void sceGuDepthMask ( int  mask  ) 

Mask depth buffer writes.

Parameters:
mask - GU_TRUE(1) to disable Z writes, GU_FALSE(0) to enable

void sceGuDepthOffset ( unsigned int  offset  ) 

void sceGuDepthRange ( int  near,
int  far 
)

Set which range to use for depth calculations.

Note:
The depth buffer is inversed, and takes values from 65535 to 0.
Example: Use the entire depth-range for calculations:
 sceGuDepthRange(65535,0);

Parameters:
near - Value to use for the near plane
far - Value to use for the far plane

void sceGuDisable ( int  state  ) 

Disable GE state.

Look at sceGuEnable() for a list of states

Parameters:
state - Which state to disable

void sceGuDispBuffer ( int  width,
int  height,
void *  dispbp,
int  dispbw 
)

Set display buffer parameters.

Example: Setup a standard 16-bit display buffer
 sceGuDispBuffer(480,272,(void*)512*272*2,512); // 480*272, skipping the draw buffer located at address 0
Parameters:
width - Width of the display buffer in pixels
height - Width of the display buffer in pixels
dispbp - VRAM pointer to where the display-buffer starts
dispbw - Display buffer width (block aligned)

int sceGuDisplay ( int  state  ) 

Turn display on or off.

Available states are:

Parameters:
state - Turn display on or off
Returns:
State of the display prior to this call

void sceGuDrawArray ( int  prim,
int  vtype,
int  count,
const void *  indices,
const void *  vertices 
)

Draw array of vertices forming primitives.

Available primitive-types are:

The vertex-type decides how the vertices align and what kind of information they contain. The following flags are ORed together to compose the final vertex format:

Note:
Every vertex must align to 32 bits, which means that you HAVE to pad if it does not add up!
Vertex order: [for vertices(1-8)] [weights (0-8)] [texture uv] [color] [normal] [vertex] [/for]

Example: Render 400 triangles, with floating-point texture coordinates, and floating-point position, no indices
Parameters:
prim - What kind of primitives to render
vtype - Vertex type to process
count - How many vertices to process
indices - Optional pointer to an index-list
vertices - Pointer to a vertex-list

void sceGuDrawArrayN ( int  primitive_type,
int  vertex_type,
int  count,
int  a3,
const void *  indices,
const void *  vertices 
)

void sceGuDrawBezier ( int  vtype,
int  ucount,
int  vcount,
const void *  indices,
const void *  vertices 
)

Draw bezier surface.

Parameters:
vtype - Vertex type, look at sceGuDrawArray() for vertex definition
ucount - Number of vertices used in the U direction
vcount - Number of vertices used in the V direction
indices - Pointer to index buffer
vertices - Pointer to vertex buffer

void sceGuDrawBuffer ( int  psm,
void *  fbp,
int  fbw 
)

Set draw buffer parameters (and store in context for buffer-swap).

Available pixel formats are:

Example: Setup a standard 16-bit draw buffer
 sceGuDrawBuffer(GU_PSM_5551,(void*)0,512);
Parameters:
psm - Pixel format to use for rendering (and display)
fbp - VRAM pointer to where the draw buffer starts
fbw - Frame buffer width (block aligned)

void sceGuDrawBufferList ( int  psm,
void *  fbp,
int  fbw 
)

Set draw buffer directly, not storing parameters in the context.

Parameters:
psm - Pixel format to use for rendering
fbp - VRAM pointer to where the draw buffer starts
fbw - Frame buffer width (block aligned)

void sceGuDrawSpline ( int  vtype,
int  ucount,
int  vcount,
int  uedge,
int  vedge,
const void *  indices,
const void *  vertices 
)

void sceGuEnable ( int  state  ) 

Enable GE state.

The currently available states are:

Parameters:
state - Which state to enable

void sceGuEndObject ( void   ) 

End conditional rendering of object.

int sceGuFinish ( void   ) 

Finish current display list and go back to the parent context.

If the context is GU_DIRECT, the stall-address is updated so that the entire list will execute. Otherwise, only the terminating action is written to the list, depending on context-type.

The finish-callback will get a zero as argument when using this function.

This also restores control back to whatever context that was active prior to this call.

Returns:
Size of finished display list

int sceGuFinishId ( unsigned int  id  ) 

Finish current display list and go back to the parent context, sending argument id for the finish callback.

If the context is GU_DIRECT, the stall-address is updated so that the entire list will execute. Otherwise, only the terminating action is written to the list, depending on context-type.

Parameters:
id - Finish callback id (16-bit)
Returns:
Size of finished display list

void sceGuFog ( float  near,
float  far,
unsigned int  color 
)

void sceGuFrontFace ( int  order  ) 

Set the current face-order (for culling).

This only has effect when culling is enabled (GU_CULL_FACE)

Culling order can be:

Parameters:
order - Which order to use

int sceGuGetAllStatus ( void   ) 

Query status on all 22 available states.

Look at sceGuEnable() for a list of states

Returns:
Status of all 22 states as a bitmask (0-21)

void* sceGuGetMemory ( int  size  ) 

Allocate memory on the current display list for temporary storage.

Note:
This function is NOT for permanent memory allocation, the memory will be invalid as soon as you start filling the same display list again.
Parameters:
size - How much memory to allocate
Returns:
Memory-block ready for use

int sceGuGetStatus ( int  state  ) 

Get if state is currently enabled or disabled.

Look at sceGuEnable() for a list of states

Parameters:
state - Which state to query about
Returns:
Wether state is enabled or not

void sceGuInit ( void   ) 

Initalize the GU system.

This function MUST be called as the first function, otherwise state is undetermined.

void sceGuLight ( int  light,
int  type,
int  components,
const ScePspFVector3 position 
)

Set light parameters.

Available light types are:

Available light components are:

Parameters:
light - Light index
type - Light type
components - Light components
position - Light position

void sceGuLightAtt ( int  light,
float  atten0,
float  atten1,
float  atten2 
)

Set light attenuation.

Parameters:
light - Light index
atten0 - Constant attenuation factor
atten1 - Linear attenuation factor
atten2 - Quadratic attenuation factor

void sceGuLightColor ( int  light,
int  component,
unsigned int  color 
)

Set light color.

Available light components are:

Parameters:
light - Light index
component - Which component to set
color - Which color to use

void sceGuLightMode ( int  mode  ) 

Set light mode.

Available light modes are:

Separate specular colors are used to interpolate the specular component independently, so that it can be added to the fragment after the texture color.

Parameters:
mode - Light mode to use

void sceGuLightSpot ( int  light,
const ScePspFVector3 direction,
float  exponent,
float  cutoff 
)

Set spotlight parameters.

Parameters:
light - Light index
direction - Spotlight direction
exponent - Spotlight exponent
cutoff - Spotlight cutoff angle (in radians)

void sceGuLogicalOp ( int  op  ) 

Set color logical operation.

Available operations are:

This operation only has effect if GU_COLOR_LOGIC_OP is enabled.

Parameters:
op - Operation to execute

void sceGuMaterial ( int  mode,
int  color 
)

void sceGuModelColor ( unsigned int  emissive,
unsigned int  ambient,
unsigned int  diffuse,
unsigned int  specular 
)

void sceGuMorphWeight ( int  index,
float  weight 
)

Specify morph weight entry.

To enable vertex morphing, pass GU_VERTICES(n), where n is between 1-8. This will change the amount of vertices passed in the vertex array, and by setting the morph weights for every vertex entry in the array, you can blend between them.

Please see sceGuDrawArray() for vertex format information.

Parameters:
index - Morph weight index (0-7)
weight - Weight to set

void sceGuOffset ( unsigned int  x,
unsigned int  y 
)

Set virtual coordinate offset.

The PSP has a virtual coordinate-space of 4096x4096, this controls where rendering is performed

Example: Center the virtual coordinate range
 sceGuOffset(2048-(480/2),2048-(480/2));
Parameters:
x - Offset (0-4095)
y - Offset (0-4095)

void sceGuPatchDivide ( unsigned int  ulevel,
unsigned int  vlevel 
)

Set dividing for patches (beziers and splines).

Parameters:
ulevel - Number of division on u direction
vlevel - Number of division on v direction

void sceGuPatchFrontFace ( unsigned int  a0  ) 

void sceGuPatchPrim ( int  prim  ) 

Set primitive for patches (beziers and splines).

Parameters:
prim - Desired primitive type (GU_POINTS | GU_LINE_STRIP | GU_TRIANGLE_STRIP)

void sceGuPixelMask ( unsigned int  mask  ) 

Set mask for which bits of the pixels to write.

Parameters:
mask - Which bits to filter against writes

void sceGuScissor ( int  x,
int  y,
int  w,
int  h 
)

Set what to scissor within the current viewport.

Note that scissoring is only performed if the custom scissoring is enabled (GU_SCISSOR_TEST)

Parameters:
x - Left of scissor region
y - Top of scissor region
w - Width of scissor region
h - Height of scissor region

void sceGuSendCommandf ( int  cmd,
float  argument 
)

Send raw float-command to the GE.

The argument is converted into a 24-bit float before transfer.

Parameters:
cmd - Which command to send
argument - Argument to pass along

void sceGuSendCommandi ( int  cmd,
int  argument 
)

Send raw command to the GE.

Only the 24 lower bits of the argument is passed along.

Parameters: