.TEX -- Texture Bitmaps (LOOP v2/7/9/11)

1. Architectural Role & Engine Purpose

The TEX (Texture File) format stores all 2D bitmap textures, character skins, weapon surfaces, foliage alpha maps, and particle textures in Project I.G.I. 1.

In the IGI 1 engine, textures are stored in Version 2 or Version 7 container formats. The format supports 16-bit high-color surfaces (RGB 5:6:5, ARGB 1:5:5:5 for 1-bit alpha test cutouts, ARGB 4:4:4:4 for soft glass/smoke), as well as 8-bit paletted textures with dedicated 256-entry color tables.

2. Binary File Layout & Memory Map Diagram

A TEX file begins with a 16-byte or 32-byte header, followed by an optional color palette, and a complete mipmap cascade:

TEX TEXTURE — DIRECT3D 7 SURFACE CONTAINER LAYOUT 0x00: Header (16/32 Bytes) HEADER Version (2 or 7) | Width, Height | Mip Levels | Surface Format Flag (565, 1555, 4444, Paletted) uint16 ver, fmt, width, height, mips, flags; uint32 reserved Optional 256-Entry Color Palette (1024 Bytes) PALETTE 8-BIT Present if Format == 0x04 (8-bit Paletted). Array of 256 * 4 Bytes RGBA color entries Direct upload to DirectDraw Palette or expanded during stage binding Precomputed Mipmap Cascade Pyramid MIPMAP CHAIN Sequential downsampled texture levels stored contiguously from full resolution to 1x1 [Mip 0: Full WxH] → [Mip 1: W/2 x H/2] → [Mip 2: W/4 x H/4] → ... → [Mip N: 1x1]

3. Engine Texture Ingestion & Direct3D 7 Stage Pipeline Diagram

The texture loading pipeline converts disk formats into native DirectDraw surfaces and binds them to Direct3D texture stages:

TEX TEXTURE — DIRECTDRAW & D3D7 STAGE BINDING PIPELINE 1. TEXLOADER • Read Version 7 Header • Inspect Surface Format • Check Mipmap Count 2. SURFACE CREATE • IDirectDrawSurface7 • RGB 5:6:5 / ARGB 1:5:5:5 • Allocate Mip Chain 3. VRAM MEMCPY • Direct Video RAM Copy • Zero Software Scaling • Palette Table Upload 4. GPU BINDING • SetTexture(0, pSurf) • Trilinear Filter • Alpha Test Setup

4. Architectural Mechanics & Engine Implementation Details

Innerloop designed the TEX texture pipeline around Direct3D 7 fixed-function hardware acceleration:

  • Precomputed Mip Pyramids: All mipmap levels are pre-calculated offline during packaging, ensuring that level loading requires zero CPU overhead for image downsampling or filtering.
  • Color-Key & 1-Bit Alpha: Foliage, fences, and character eyelashes utilize ARGB 1:5:5:5 textures. The high bit controls the alpha test comparison against D3DRENDERSTATE_ALPHAREF, enabling fast cutouts without full depth sorting.
  • Texture Clamping & Wrapping: Texture addressing modes (Wrap vs Clamp) are driven by the material definition in the corresponding .mtp file.

5. C++ Struct Definitions

#pragma pack(push, 1)
struct TexHeader {
    uint16_t version;       // 2 or 7
    uint16_t format;        // 1=565, 2=1555, 3=4444, 4=8-bit paletted
    uint16_t width;         // Width in pixels
    uint16_t height;        // Height in pixels
    uint16_t mip_levels;    // Total mip levels in file
    uint16_t flags;         // Surface flags
    uint32_t reserved;
};
static_assert(sizeof(TexHeader) == 16, "TexHeader must be 16 bytes");
#pragma pack(pop)