.CMD -- Terrain Mesh LOD Commands

1. Architectural Role & Engine Purpose

The CMD (Compiled Mesh Command Stream) format represents pre-compiled GPU draw packets and primitive assembly streams embedded within 3D mesh assets in Project I.G.I. 1.

CMD files compile high-level geometry into tightly-packed 8-byte command tokens (cmd_item_s) that map directly to Direct3D 7 DrawIndexedPrimitive execution buffers, eliminating CPU driver state parsing.

2. Binary File Layout & Memory Map Diagram

A CMD stream contains a packet count header followed by sequential 8-byte GPU execution commands:

CMD MESH COMMANDS — 8-BYTE GPU DRAW PACKET LAYOUT 0x00: Command Header (16 Bytes) 16 BYTES Magic "CMD " | Command Packet Count | Total Vertex Count | Total Index Count magic[4], command_count, vertex_count, index_count GPU Draw Command Packets: 8 Bytes per Packet (cmd_item_s) 8B PACKET Primitive Type (0=TriStrip, 1=TriList, 2=TriFan) | Material ID (uint16) | Vertex Offset (uint16) | Primitive Count Pre-sorted by material index • Maps directly to D3D7 DrawIndexedPrimitive Sequential Primitive Execution Stream TRISTRIP Optimized for high-throughput AGP vertex transfer with shared triangle strip vertices Reduces Direct3D texture swaps and GPU state flushes by over 80%

3. Direct3D Command Dispatch Pipeline Diagram

During mesh rendering, the engine executes the CMD token stream in a tight loop:

CMD COMMANDS — DIRECT3D 7 PRIMITIVE DISPATCH PIPELINE 1. MESH RENDER • Bind Model Vertex VBO • Inspect CMD Packets • Loop Command Count 2. STATE BINDING • SetTexture(pCmd->mat) • SetRenderState() • Zero Redundant Swaps 3. D3D7 DRAW CALL • DrawIndexedPrimitive() • TriStrip / TriList • Vertex Offset & Count 4. GPU RASTER • Direct AGP Execution • Hardware Rasterization • Next Command Packet

4. Architectural Mechanics & Engine Implementation Details

The 8-byte CMD design achieved maximum graphics throughput on early 3D graphics cards:

  • State Sorting: Commands are pre-sorted offline by material and texture index, minimizing Direct3D texture swaps and pipeline flushes during the render loop.
  • Triangle Strip Maximization: Over 80% of commands in IGI 1 utilize Triangle Strips (D3DPT_TRIANGLESTRIP), sharing two vertices between adjacent triangles to minimize AGP bus bandwidth.

5. C++ Struct Definitions

#pragma pack(push, 1)
struct CmdHeader {
    char     magic[4];       // "CMD "
    uint32_t command_count;  // Total draw command packets
    uint32_t vertex_count;   // Referenced vertices
    uint32_t index_count;    // Referenced triangle indices
};

// IGI 1 8-Byte Command Packet
struct cmd_item_s {
    uint16_t prim_type;      // 0=TriStrip, 1=TriList, 2=TriFan
    uint16_t material_id;    // Index to material / texture state
    uint16_t vertex_offset;  // Base vertex start index
    uint16_t prim_count;     // Number of primitives to render
};
static_assert(sizeof(cmd_item_s) == 8, "cmd_item_s must be 8 bytes");
#pragma pack(pop)