N64® Functions Menu

al - Audio Library Functions
gDP - DP GBI Macros
gdSP - General GBI Macros
gSP - SP GBI Macros
gt - Turbo Microcode RDP
gu - Graphics Utilities
Math - Math Functions
nuSys - NuSystem
os - N64 Operating System
sp - Sprite Library Functions
uh - Host to Target IO
64DD - N64 Disk Drive

Nintendo® Confidential

   

gspSprite2D Microcode
gspSprite2D.dram Microcode
gspSprite2D.fifo Microcode

The gspSprite2D microcode is optimized for rendering 2D sprite images. Sprites are implemented as textured screen rectangles. gspSprite2D does not support 3D lines, 3D triangles, vertex operations, matrix operations, lighting, or fog. All of the DP commands such as blender modes, and color combiner modes are supported. Z-Buffering can be used to arrange the order of the sprites from front to back.

In other words, this is the optimized, high-quality, full-featured 2D sprite geometry microcode. It supports automatic subdivision and loads any size of all of the texture format sizes and types supported in the command, and sends it directly to the RDP. Additionally, images can be scaled up or inverted in the X or Y directions.

Commands

The sprite microcode is accessed through a combination of four functions/macros as follows:
  • guSprite2DInit initializes a specified a sprite structure.It allows the application to be run without directly initializing the sprite structure.
  • gSPSprite2DBase sends the sprite microcode to the sprite structure to start actual processing. It initializes the common sprite parameters. It does not perform actual screen drawing.
  • gSPSprite2DScaleFlip is used to specify the X/Y scaling and/or flipping parameters for a sprite. It does not perform actual screen drawing.
  • gSPSprite2DDraw specifies the screen coordinates where the sprite is to be drawn, and starts actual screen drawing using the parameters specified by gSPSprite2DBase and gSPSprite2DScaleFlip.

Simple Code for Displaying a Sprite

#include "gu.h"

#include "gbi.h"
     uSprite MySprite;
     guSprite2DInit(Mysprite, ImagePointer,
        TlutPointer, ImageWidth,
        RectangleWidth, RetangleHeight, 
        ImageType, ImageSize, 
        TextureStartS, TextureStartT);

gSPSprite2DBase(glistp++,
    OS_K0_TO_PHYSICAL(MySprite));

gSPSprite2DScaleFlip (glistp++, ScaleX, ScaleY, 
   FlipTextureX, FlipTextureY); 

gSPSprite2DDraw (glistp++, PScreenX, PScreenY)

typedef struct {
     void *SourceImagePointer;
     void *TlutPointer;
     short Stride;
     short SubImageWidth;
     short SubImageHeight;
     char  SourceImageType;
     char  SourceImageBitSize;
     short SourceImageOffsetS;
     short SourceImageOffsetT;
   /* 20 bytes for above */
 
   /* padding to bring structure size to
      64-bit alignment */;
     char dummy[4];
 
} uSprite_t;
 
typedef union {
     uSprite_t  s;
    /* Ensure this is 64-bit aligned */;
     long long int force_structure_alignment[3];
} uSprite;
 
     void guSprite2DInit(uSprite *SpritePointer,
     void *SourceImagePointer,
     void *TlutPointer,
     int Stride,
     int SubImageWidth,
     int SubImageHeight,
     int SourceImageType,
     int SourceImageBitSize,
     int SourceImageOffsetS,
     int SourceImageOffsetT);

Arguments

  • SpritePointer is the pointer to the sprite structure that sets the parameters.
  • SourceImagePointer is the base pointer of the texture image in memory containing the rectangle to be displayed.
  • TlutPointer is the pointer to the color index used for CI images. Set it to Null when CI images will not be used.
  • Stride is the texel width of the base image in memory.
  • SubImageWidth is the texel width of the image to be displayed.
  • SubImageHeight is the texel height of the image to be displayed.
  • SourceImageType specifies the format of the texture image in memory. All texture formats supported by the hardware are allowed, such as G_IM_FMT_RGB or G_IM_FMT_CI.
  • SourceImageBitSize is the number of bits per texel of the input image. All texture sizes supported by the hardware are allowed, such as G_IM_SIZ_32b or G_IM_SIZ_4b.
  • ScaleX specifies the scale in the X axis for the input screen image as a s 5.10 fixed-point number. A value of 1024 specifies 1 to 1 scaling. A value of 512 enlarges the input texels by 2 times in the output scaling pixels.
  • Scale values should be (1024 in order to avoid an unnatural feel. Scale values must be positive. Use the FlipTextureX variable to create negatively scaled images.
  • ScaleY specifies the scale in the Y axis for the input screen image as a s 5.10 fixed-point number. A value of 1024 specifies 1 to 1 scaling. A value of 512 enlarges the input texels by 2 times in the output scaling pixels. Scale values should be (1024 in order to avoid an unnatural feel. Scale values must be positive. Use the FlipTextureY variable to create negatively scaled images.
  • FlipTextureX specifies whether the image to be displayed should be inverted in the X direction.
  • FlipTextureY specifies whether the image to be displayed should be inverted in the Y direction.
  • SourceImageOffsetS is the offset in texel columns from the origin of the base image. It specifies the starting point of the rectangular region for texel display within the base image.
  • SourceImageOffsetT is the offset in texel lines from the origin of the base image. It specifies the starting point of the rectangular region for texel display within the base image.
  • PScreenX specifies the X location in the screen coordinates of the output image. The origin is in the upper-left corner of the screen.
  • PScreenY Specifies the Y location in the screen coordinates of the output image. The origin is in the upper-left corner of the screen.

GBI

The following GBI commands are not supported by this microcode:

Note

The sprite microcode does not directly support Z-Buffering. This is unnecessary as Z-Buffering can be accomplished outside of the sprite microcode by setting up the proper rendering mode and making use of the hardware primitive depth registers. Following is a code fragment that does Z-Buffering.
gDPSetRenderMode(glistp++,
   G_RM_AA_ZB_OPA_SURF,
   G_RM_AA_ZB_OPA_SURF2);

gDPSetDepthSource(glistp++,
   _ZS_PRIM);

gDPSetCombineMode(glistp++,
   G_CC_DECALRGB, G_CC_DECALRGB);

gDPSetPrimDepth(glistp++,
   ZBufferValue, 0);

guSprite2DInit(MySprite, ImagePointer,
   TlutPointer, ImageWidth,
   RectangleWidth, RectangleHeight, 
   ImageType, ImageSize, 
   TextureStartS, TextureStartT); 

gSPSprite2DBase(glistp++,
   OS_K0_TO_PHYSICAL(MySprite)); 

gSPSprite2DScaleFlip(glistp++,
   ScaleX, ScaleY, 
   FlipTextureX, FlipTextureY); 

gSPSprite2DDraw(glistp++, PScreenX, PScreenY);

Warnings, Limitations, and Workarounds

Images that have been non-unit scaled and flipped around the Y axis may not be smoothly converted in the vertical direction, depending on the quantity of sub-pixels. Jumping will occur at a certain quantity. The solution is to convert non-unit scaling to unit amounts in the vertical direction.

The Sprite Microcode was designed to be able to scale up images by any amount. Images can also be scaled down together with some attendant artifacts. Please note that, while the TextureScaleX and TextureScaleY parameters are s 5.10 fixed-point numbers, they are restricted to being positive. Consequently, the largest usable scale value is 32767, which corresponds to a texel to pixel ratio of 31.999.

Texture images that are either scaled in the Y axis or placed on a subpixel scanline boundary require filtering by the hardware texture filter unit. This filtering requires that at least one extra line in the screen image be loaded in the texture memory so that the filtering can occur.

The texture memory is limited to 4K bytes, so there are some restrictions:
  • 32 bit subrectangles that are scaled in the Y direction are clamped by the microcode to a maximum of 512 texels wide.
  • 32 bit subrectangles that are placed at the beginning of a subpixel boundary in the Y direction and that are larger than 512 texels in width are clamped by the microcode to being on an integral scan line boundary.
  • These filtering conditions also mean that, when displaying a Y-scaled image, you will need to add 1 to the T value to prevent filtering of texels outside the range.
  • Y flipped images that have been scaled vertically by a non-squared value will be slightly different in height than their non-flipped versions. If you are doing an animation involving scaled flipped and non-flipped textures, restrict the Y scale value to a squared value.
See Also
gspLine3D
gspTurbo3D
gspFast3D
osSpTaskStart
gSPSprite2DBase
gSPSprite2DScaleFlip
gSPSprite2DDraw



Nintendo® Confidential

Warning: all information in this document is confidential and covered by a non-disclosure agreement. You are responsible for keeping this information confidential and protected. Nintendo will vigorously enforce this responsibility.

Copyright © 1998
Nintendo of America Inc. All rights reserved
Nintendo and N64 are registered trademarks of Nintendo
Last updated January 1998