Table of Contents Glide Programming Guide


Figure Managing Texture Memory.5 Replacing a few rows of an LOD



Download 6.22 Mb.
Page76/106
Date03.02.2023
Size6.22 Mb.
#60547
1   ...   72   73   74   75   76   77   78   79   ...   106
GLIDEPGM
Figure Managing Texture Memory.5 Replacing a few rows of an LOD.
Suppose a mipmap has been loaded into TMU0 with the following command and data.
grTexDownloadMipMap(GR_TMU0, startAddress, GR_MIPMAPLEVELMASK_BOTH, info)

To replace GR_LOD_256 in chunks, use a series of calls to grTexDownloadMipMapLevelPartial():
for (row=0; row<256; row+=64)
grTexDownloadMipMapLevel( GR_TMU0, startAddress, GR_LOD_256, info®largeLod,
info®aspectRatio, info®format, GR_MIPMAPLEVELMASK_BOTH, newData, row, row + 63 );



9Identifying a Mipmap as the Texel Source


The final step is to register the newly loaded mipmap with the TMU as the source for texels. The Glide function grTexSource() provides this service.
void grTexSource( GrChipID_t tmu, FxU32 startAddress, FxU32 evenOdd, GrTexInfo *info )

grTexSource() sets up the area of texture memory that is to be used as a source for subsequent texture mapping operations. The starting address specified as argument startAddress should be the same one that was used as an argument to grTexDownloadMipMap(), or the starting address used for the largest mipmap level when using grTexDownloadMipMapLevel().
Here are the three examples from Chapter Chapter 9. , with additional lines of code to download the appropriate textures.
Example Managing Texture Memory.3 Downloading a texture for decal texture mapping.
The following code sets up the texture pipeline so that a texel is placed into the pixel pipeline without modification. The code assumes that the color combine unit is configured to use the texture color and/or alpha value.
FxU32 textureSize, startAddress;
GrTexInfo info;
FxU16 mipmap[256*256 + 128*128 + 64*64 + 32*32 + 256 + 64 + 16 + 4 + 1];

info.smallLod = GR_LOD_1;


info.largeLod = GR_LOD_256;
info.aspectRatio = GR_ASPECT_1x1;
info.format = GR_TEXFMT_1555;
info.data = mipmap;

textureSize = grTexTextureMemRequired(GR_MIPMAPLEVELMASK_BOTH, &info); .


startAddress = grTexMinAddress(GR_TMU0); .
if ((startAddress + textureSize)> grTexMaxAddress(GR_TMU0)) {
printf(“error: texture too big for TMU0\n”);
exit();
}

grTexDownloadMipMap(GR_TMU0, startAddress, GR_MIPMAPLEVELMASK_BOTH, &info);


grTexSource(GR_TMU0, startAddress, GR_MIPMAPLEVELMASK_BOTH, &info);

grTexCombine( GR_TMU0, GR_COMBINE_FUNCTION_LOCAL, GR_COMBINE_FACTOR_NONE,


GR_COMBINE_FUNCTION_LOCAL, GR_COMBINE_FACTOR_NONE,
FXFALSE, FXFALSE );
Example Managing Texture Memory.4 Downloading two textures for modulated or composite texture mapping.
The code segment below loads an intensity map for a spotlight in TMU0 and a source texture in TMU1. The resulting texture RGBA is a product of the texels chosen from the two textures. The color combine unit must be configured to use the output from the texture pipeline.
FxU32 textureSize[2], startAddress[2];
GrTexInfo src, spot;
FxU16 srcdata[256*256 + 128*128 + 64*64 + 32*32 + 256 + 64 + 16 + 4 + 1];
FxU8 spotdata[256*256 + 128*128 + 64*64 + 32*32 + 256 + 64 + 16 + 4 + 1];

src.smallLod = spot.smallLod = GR_LOD_1;


src.largeLod = spot.largeLod = GR_LOD_256;
src.aspectRatio = spot.aspectRatio = GR_ASPECT_1x1;
src.format = GR_TEXFMT_1555;
src.data = srcdata;
spot.format = GR_TEXFMT_INTENSITY_8;
spot.data = spotdata;

textureSize[0] = grTexTextureMemRequired(GR_MIPMAPLEVELMASK_BOTH, &spot);


startAddress[0] = grTexMinAddress(GR_TMU0);
if ((startAddress[0] + textureSize[0])> grTexMaxAddress(GR_TMU0)) {
printf(“error: spotlight texture too big for TMU0\n”);
exit();
}

textureSize[1] = grTexTextureMemRequired(GR_MIPMAPLEVELMASK_BOTH, &src);


startAddress[1] = grTexMinAddress(GR_TMU1);
if ((startAddress[1] + textureSize[1])> grTexMaxAddress(GR_TMU1)) {
printf(“error: source texture too big for TMU1\n”);
exit();
}
grTexDownloadMipMap(GR_TMU0,startAddress[0],GR_MIPMAPLEVELMASK_BOTH, &spot);
grTexSource(GR_TMU0,startAddress[0],GR_MIPMAPLEVELMASK_BOTH, &spot);
grTexCombine( GR_TMU0, GR_COMBINE_FUNCTION_SCALE_OTHER, GR_COMBINE_FACTOR_LOCAL,
GR_COMBINE_FUNCTION_SCALE_OTHER, GR_COMBINE_FACTOR_LOCAL,
FXFALSE, FXFALSE );

grTexDownloadMipMap(GR_TMU1,startAddress[1],GR_MIPMAPLEVELMASK_BOTH, &src);


grTexSource(GR_TMU1,startAddress[1],GR_MIPMAPLEVELMASK_BOTH, &src);
grTexCombine( GR_TMU1, GR_COMBINE_FUNCTION_LOCAL, GR_COMBINE_FACTOR_NONE,
GR_COMBINE_FUNCTION_LOCAL, GR_COMBINE_FACTOR_NONE,
FXFALSE, FXFALSE );
Example Managing Texture Memory.5 Splitting a texture across two TMUs for trilinear mipmapping.
The first code segment shows the texture combine unit configuration for trilinear mipmapping when the even LODs are stored in TMU0 and the odd ones are in TMU1. The code assumes that the color combine unit is configured to make use of the resulting RGBA value.
FxU32 textureSize[2], startAddress[2];
GrTexInfo tri;
FxU16 mipmap[256*256 + 128*128 + 64*64 + 32*32 + 256 + 64 + 16 + 4 + 1];

tri.smallLod = GR_LOD_1;


tri.largeLod = GR_LOD_256;
tri.aspectRatio = GR_ASPECT_1x1;
tri.format = GR_TEXFMT_1555;
tri.data = mipmap;

textureSize[0] = grTexTextureMemRequired(GR_MIPMAPLEVELMASK_EVEN, &tri);


startAddress[0] = grTexMinAddress(GR_TMU0);
if ((startAddress[0] + textureSize[0])> grTexMaxAddress(GR_TMU0)) {
printf(“error: even LODs of texture too big for TMU0\n”);
exit();
}

textureSize[1] = grTexTextureMemRequired(GR_MIPMAPLEVELMASK_ODD, &tri) ;


startAddress[1] = grTexMinAddress(GR_TMU1);
if ((startAddress[1] + textureSize[1])> grTexMaxAddress(GR_TMU1)) {
printf(“error: odd LODs of texture too big for TMU1\n”);
exit();
}
grTexDownloadMipMap(GR_TMU0,startAddress[0],GR_MIPMAPLEVELMASK_EVEN, &tri) ;
grTexSource(GR_TMU0,startAddress[0],GR_MIPMAPLEVELMASK_EVEN, &tri);
grTexCombine( GR_TMU0,
GR_COMBINE_FUNCTION_SCALE_MINUS_LOCAL_ADD_LOCAL,
GR_COMBINE_FACTOR_LOD_FRACTION,
GR_COMBINE_FUNCTION_SCALE_MINUS_LOCAL_ADD_LOCAL,
GR_COMBINE_FACTOR_LOD_FRACTION,
FXFALSE, FXFALSE);

grTexDownloadMipMap(GR_TMU1,startAddress[1],GR_MIPMAPLEVELMASK_ODD, &tri);


grTexSource(GR_TMU1,startAddress[1],GR_MIPMAPLEVELMASK_ODD, &tri);
grTexCombine( GR_TMU1, GR_COMBINE_FUNCTION_LOCAL, GR_COMBINE_FACTOR_NONE,
GR_COMBINE_FUNCTION_LOCAL, GR_COMBINE_FACTOR_NONE,
FXFALSE, FXFALSE );


This second code segment gives the proper grTexCombine() configuration when the situation is reversed: the odd LODs in the mipmap are on TMU0 while the even ones are upstream on TMU1. Note the difference in the texture combine unit configuration: the setting of the rgbInvert and alphaInvert parameters.

FxU32 textureSize[2], startAddress[2];


GrTexInfo tri;
FxU16 mipmap[256*256 + 128*128 + 64*64 + 32*32 + 256 + 64 + 16 + 4 + 1];

tri.smallLod = GR_LOD_1;


tri.largeLod = GR_LOD_256;
tri.aspectRatio = GR_ASPECT_1x1;
tri.format = GR_TEXFMT_1555;
tri.data = mipmap;

textureSize[0] = grTexTextureMemRequired(GR_MIPMAPLEVELMASK_ODD, &tri);


startAddress[0] = grTexMinAddress(GR_TMU0);
if ((startAddress[0] + textureSize[0])> grTexMaxAddress(GR_TMU0)) {
printf(“error: even LODs of texture too big for TMU0\n”);
exit();
}

textureSize[1] = grTexTextureMemRequired(GR_MIPMAPLEVELMASK_EVEN, &tri);


startAddress[1] = grTexMinAddress(GR_TMU1);
if ((startAddress[1] + textureSize[1])> grTexMaxAddress(GR_TMU1)) {
printf(“error: odd LODs of texture too big for TMU1\n”);
exit();
}
grTexDownloadMipMap(GR_TMU0,startAddress[0],GR_MIPMAPLEVELMASK_ODD, &tri);
grTexSource(GR_TMU0,startAddress[0],GR_MIPMAPLEVELMASK_ODD, &tri);
grTexCombine( GR_TMU0,
GR_COMBINE_FUNCTION_SCALE_MINUS_LOCAL_ADD_LOCAL,
GR_COMBINE_FACTOR_ONE_MINUS_LOD_FRACTION,
GR_COMBINE_FUNCTION_SCALE_MINUS_LOCAL_ADD_LOCAL,
GR_COMBINE_FACTOR_ONE_MINUS_LOD_FRACTION,
FXFALSE, FXFALSE);

grTexDownloadMipMap(GR_TMU1,startAddress[1],GR_MIPMAPLEVELMASK_EVEN, &tri);


grTexSource(GR_TMU1,startAddress[1],GR_MIPMAPLEVELMASK_EVEN, &tri);
grTexCombine( GR_TMU1, GR_COMBINE_FUNCTION_LOCAL, GR_COMBINE_FACTOR_NONE,
GR_COMBINE_FUNCTION_LOCAL, GR_COMBINE_FACTOR_NONE,
FXFALSE, FXFALSE );


Download 6.22 Mb.

Share with your friends:
1   ...   72   73   74   75   76   77   78   79   ...   106




The database is protected by copyright ©ininet.org 2024
send message

    Main page