Table of Contents Glide Programming Guide



Download 6.22 Mb.
Page80/106
Date03.02.2023
Size6.22 Mb.
#60547
1   ...   76   77   78   79   80   81   82   83   ...   106
GLIDEPGM

2Color Palettes


A color palette is an array of 256 ARGB colors, 8 bits for each component, 32 bits per entry (refer back to Figure Managing Texture Memory.1). The alpha component, in the high order 8 bits, is ignored. It is defined using the Glide structure GuTexPalette, shown below.
typedef struct {
FxU32 data[256];
} GuTexPalette;
Example Managing Texture Memory.8 Loading a color palette.
The following code segment will create a random color palette and download it into TMU0. To use the palette, download a palletized texture (texture formats GR_TEXFMT_P_8 or GR_TEXFMT_AP_88) and configure the texture and color combine units appropriately.
extern unsigned long lrand( void);
GuTexPalette palette;
int i, j;

// create a random 256-entry color palette


for (i=0; i<256; i++)
palette.data[i] = 0x00FFFFFF & lrand();

grTexDownloadTable(GR_TMU0, GU_TEX_PALETTE, &palette);



12Loading Mipmaps From Disk


TexUS (3Dfx Interactive’s Texture Utility Software) programs create files in a 3DF file format. These files may contain mipmaps, decompression tables, or both. A pair of data types and a pair of functions provide access to .3DF files from Glide.
The data structures are shown below. Gu3dfInfo is the top level structure. It has a pointer to the mipmap data, and stores the decompression table or palette if there is one. There is also a Gu3dfHeader structure that contains all the mipmap characteristics (LOD range, aspect ratio, format, dimensions) and the amount of memory the mipmap will require.
typedef struct {
FxU32 width, height;
int small_lod, large_lod;
GrAspectRatio_t aspect_ratio;
GrTextureFormat_t format;
} Gu3dfHeader;

typedef union {


GuNccTable nccTable;
GuTexPalette palette;
} GuTexTable;

typedef struct {


Gu3dfHeader header;
GuTexTable table;
void *data;
FxU32 mem_required;
} Gu3dfInfo;
The procedure for reading a .3DF file from Glide is shown in Example Managing Texture Memory.9. The application first calls gu3dfGetInfo() to fill in the Gu3dfInfo structure pointed to by info.
FxBool gu3dfGetInfo( const char *filename, Gu3dfInfo *info )

After an application has determined the characteristics of a .3DF mipmap, memory must be allocated for the mipmap and the address stored in the info®data pointer. Then gu3dfLoad() is invoked to load the mipmap from the file into memory. Note that the mipmap must be downloaded into a TMU before it can be used as a texel source.


FxBool gu3dfLoad( const char *filename, Gu3dfInfo *info )

Both gu3dfGetInfo() and gu3dfLoad() return FXTRUE if the file specified by filename exists and can be read; otherwise they return FXFALSE.


Example Managing Texture Memory.9 Reading a .3DF file.
The following code segment assumes that “mipmap.3df” contains a properly formatted 3DF file. The code calls gu3dfGetInfo() to determine memory requirements, allocates storage for the mipmap using the system subroutine malloc(), then reads the mipmap into the newly allocated memory by calling gu3dfLoad().
Gu3dfInfo fileInfo;

gu3dfGetInfo(“mipmap.3df”, &fileInfo);


fileInfo.data = malloc(fileInfo.mem_required);
gu3dfLoad(“mipmap.3df”, &fileInfo);

Download 6.22 Mb.

Share with your friends:
1   ...   76   77   78   79   80   81   82   83   ...   106




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

    Main page