Feersum/Sandbox – User

From Bohemia Interactive Community
Jump to navigation Jump to search


PAA texture file structure

Introduction

PAA is basic texture file format used in OFP and OFP:R. While engine also supports JPG textures, using PAA textures can result in much better performance.

Main Format

PAA texture file consists of type information, one or more "tags" and actual texture and mipmap data.

Every PAA file starts with type information

UWORD	type;	// type of texture, known values are 
		// 0xFF01 DXT1 compressed texture (may have 1 bit alpha map, check MSDN documentation for details)
		// 0x1555 Uncompressed RGBA 5:5:5:1 texture
		// 0x4444 Uncompressed RGBA 4:4:4:4 texture
		// 0x8080 Uncompressed Luminosity/Alpha map. Actual color of texture is derived from AVGCTAGG tag?

followed by one or more header tags

struct PAA_Tag {
	UCHAR	name[8];	// name of tag is actually reversed when written in file, 
				// so OFFSTAGG would be written as GGATSFFO. See  below for known tags.
	ULONG	tag_size;	// size of this tag
	UCHAR	data; 		// size * bytes of actual data
}

Known header tags

There are several knowns header tags, of these at least OFFSTAGG is mandatory.

OFFSTAGG This tag has always 16 ULONG entries which contain pointers to actual mipmap data inside file. Note that while 16 offsets are always stored, actual number of mipmaps might be smaller. In this case, offset is marked as 0x00000000. This tag is mandatory.

AVGCTAGG This tag contains average color of texture, probably used in rendering 8:8 luminosity/alpha textures.

FLAGTAGG Marks if texture contains transparency. Value 1 means basic transparency, 2 means alpha channel is not interpolated. This flag should be always present in LOD textures with 1-bit alpha with value of 2 or there will be "ghost outlines" on LOD textures when viewed from distance. Note that this flag must be present in texture file when binarizing model, because Binarize stores information about how to render textures in actual P3D file.

End of header tag data is marked by UWORD 0x0000.

Mipmap data

After end-of-header marker, actual mipmap data follows. Tag OFFSTAG points to start of each mipmap structure relative to start of the file.

struct Mipmap_Data {
	UWORD	width;		// width of this mipmap
	UWORD	height;		// height of this mipmap
	UCHAR	size[3];	// size of compressed texture data. this is 24-bit unsigned integer. 
	UCHAR	data;		// actual texture data 
};

Note that texture types 0x4444 and 0x8080 are always stored in compressed format. See Pbo_File_Format#Data Compression for details. DXT1 textures are stored "as is" (width*height/2 bytes).

After last mipmap, there are six (6) bytes set to 0x00 to mark end of texture data.

Alpha channel interpolation

These two images visualize difference between alpha channel interpolation (FLAGTAGG header tag value).

FLAGTAGG = 1

FLAGTAGG = 2