3.5 Clamp, Wrapping & Mirror

When texture mapping, there is no rule that says the texture must cover the entire polygon. For example, when mapping an orderly texture like bricks, it would be easier if you could do the mapping with a small texture that you could put down like sections of wallpaper. In fact, there is a mapping method that works this way, called "wrapping." You can specify this attribute using the gDPLoadTextureBlock command:

List 3-4

  /* Load texture (image rgba16sign1) */
  gDPLoadTextureBlock(glistp++,
          rgba16sign1,              /* pointer to texture image */
          G_IM_FMT_RGBA,            /* texel format */
          G_IM_SIZ_16b,             /* texel size */
          32, 32,                   /* image width & height  */
          0,                        /* LUT (palette) index (not used here)  */
          G_TX_WRAP, G_TX_WRAP,     /* s, t direction clamp-wrap-mirror flags */
          5, 5,                     /* s, t mask */
          G_TX_NOLOD, G_TX_NOLOD);  /* shift (no shift here)  */

In this example, the G_TX_WRAP constant is specified in the 8th and 9th arguments. When this is done, the wrapping attribute is set in the tile of the loaded texture. The four following constants have been defined for specification here:

  G_TX_WRAP Enable wrapping
  G_TX_CLAMP Do not wrap
  G_TX_MIRROR Enable mirror-image wrapping
  G_TX_NOMIRROR Do not mirror-image wrap

The next two arguments take the mask values carried out on the ST values. That is, the ST values passed to the RDP and a bitwise AND is done with the mask values to get the final ST values, on which the selection of texels is based.

In the gfx3.c sample program, you can change the wrapping flag (__CWS_S__, __CWS_T__) and mask value (__MASK_S__, __MASK_T__) as well as the maximum ST values for each face of the cube (__MAX_S__, __MAX_T__) with the macro definitions. Therefore, make a variety of changes to the settings to see what happens.