Scene textures (.TEX)¶
Every scene archive (SCENES/**.ZIP) holds one .TEX texture buffer. The native build installs it through ZRenderDllSDL::CompactTextureBuffer, which turns every handle in a STextureRecordPS2 into a byte offset into the buffer, and then decodes each texture to RGBA8 with DecodeTexture (port/engine/drawing/old/_sdl/texturedecodesdl.cpp). tools/port/tex_dump.py is the Python reference for the same mapping.
What the disc holds¶
python3 tools/port/tex_dump.py survey decodes all 71 scene buffers, 24,869 textures:
lFormat |
GS format | Colours | Normal map | Textures |
|---|---|---|---|---|
ZPFP16 |
PSMT4 | 16 | no | 9,431 |
ZPFP256 |
PSMT8 | 256 | no | 9,311 |
ZPF8888 |
PSMCT32 | 0 | no | 5,642 |
ZPFP256 |
PSMT8 | 256 | yes | 451 |
ZPFP16 |
PSMT4 | 16 | yes | 34 |
All sizes are powers of two. 514 textures have 2 to 6 mip levels, and the rest have one. No data size, palette size or mip count disagrees with the PS2 upload code. Fourteen textures are animated (their frames are other texture records) and 105 scroll.
Texel layout¶
The PS2 code ignores lFormat. AddGifChainTexture (zolddrawps2.cpp) picks the GS format from the record alone: no palette is PSMCT32, a palette with fewer than 17 colours is PSMT4, and a larger one is PSMT8. Level 0 comes first in the data, then level 1 and so on, each a quarter of the previous level's qwords.
MakeLocations decides how each level is uploaded. A PSMT8 level whose width is a multiple of 16 and height a multiple of 4 is uploaded as a PSMCT32 rectangle of (w/2, h/2) with buffer width ceil(w/2 / 64). The equivalent PSMT4 condition gives a rectangle of (h/2, w/4), with the axes swapped. The GS then reads the level back as PSMT8 or PSMT4 with buffer width 2·ceil(w/128). The stored bytes are what makes that write-then-read land the right texels, so the decoder runs it in reverse: for each texel it takes the PSMT8/PSMT4 address, finds the PSMCT32 pixel of the upload rectangle holding that word, and reads the byte or nibble there. 20,150 levels take this path. The other 6,321 levels (all PSMCT32, plus PSMT4 levels 8×8, 16×8, 16×16, 32×8, 64×8 and 256×8, and PSMT8 8×8) are uploaded in their own format and are row-major. MakeLocations gives those levels a buffer width the read does not use (it tests up_mode - 2 < 2 where 0x13/0x14 were meant), but on this disc that never changes an address.
Palettes¶
The CLUT is PSMCT32 in CSM1, uploaded as an 8×2 (16 colours) or 16×16 (256 colours) raster. Sixteen-colour entries are in index order. A 256-colour entry i sits at raster position i with bits 3 and 4 swapped.
Normal maps upload five CLUTs side by side (40×2 or 48×32), and the dot3 pass in TextureSwitchInDot3Pass selects them by CBP (block offsets 0, 1, 4, 5, 16 for 16 colours and 0, 4, 8, 12, 16 for 256). For every entry of all 485 normal maps, CLUTs 0 to 2 are grey (128,128,128) with alpha nx, ny and nz. CLUT 3 holds max(0, n − 128) per axis, CLUT 4 holds max(0, 128 − n), and both share one alpha w (54 to 185). The decoder therefore writes normal-map texels as (nx, ny, nz, w), unmodified, which reproduces all five CLUTs.
Alpha¶
Stored alpha uses the full byte, and 255 is opaque. 75% of all 32-bit texels on the disc are 0xff, and the font pages ramp their palette alpha 0, 16, … 240. The engine compensates on the GS side. For textured sprites, zoldviewps2.cpp sends vertex alpha as lColor >> 26 (A/4), where untextured sprites get lColor >> 25 (A/2). With MODULATE, 255 × 63 >> 7 gives about 0x80. The loader sequence player halves palette alpha before its own upload (PALETTE_ALPHA_TO_GS). DecodeTexture copies alpha unchanged, so the port treats texture alpha as A/255. An alpha-test reference from a prim (lAlphaCutoff, compared on the GS after modulation) corresponds to about twice its value in texture alpha.
Sampler state¶
lFlags carries TEX1's MMAG (bit 28), MMIN (bits 29 to 31), L (bits 14 and 15) and K (bits 16 to 27, signed, 1/16 units). On the disc, 24,355 textures are bilinear with no mips (K = −9.0). The rest are LINEAR_MIPMAP_NEAREST (391) or LINEAR_MIPMAP_LINEAR (120), with K between −18.4 and 0. Three are point-sampled. The GS chooses the LOD from Q, as (log2(1/Q) << L) + K, so the renderer has to translate it. Clamping is not part of the texture. CalcGSRegs clamps U and V from the prim's lDrawMode bits 0x4000 and 0x8000, and repeats otherwise. The two axes are independent (CLAMP_1 WMS and WMT), and the draw list has a sampler for each combination (DrawSampler). M05's 32 kerb and lawn edge strips (GroundGrass_05, draw mode 0x8390) clamp V only: the ragged top edge stays put while the grass repeats along the kerb. When the port clamped both axes for either bit, those strips smeared their last texel column along the kerb.
Checks¶
python3 tools/port/tex_dump.py dump <file.TEX | SCENES/X.ZIP> [--mips] [--sheet] [--raw f.rgba] [--crc f.crc] writes PNGs, a contact sheet and textures.json/textures.csv. The Python decoder simulates GS memory forward: it writes each upload and reads the texture back. tools/port/tests/texture_decode_test.cpp compacts a buffer the way CompactTextureBuffer does, decodes it with the C++ functions and compares against --raw bytes or --crc lines:
clang++ -std=gnu++98 -fsigned-char -fno-strict-aliasing -fno-exceptions -fno-rtti -nostdinc++ -DNON_MATCHING \
-I src -I port tools/port/tests/texture_decode_test.cpp port/engine/drawing/old/_sdl/texturedecodesdl.cpp \
port/engine/system/_sdl/pcdata/pctexture.cpp -o build/tex/texture_decode_test
On 14 November 2026 all 26,471 levels of all 71 scenes matched; on 24 November, after the PC path was added, all 569 levels of M02 main still did.
PC data¶
When the port runs from a PC installation, the scene's PC .TEX is converted when it is read (PcConvertTextures, port/engine/system/_sdl/pcdata/pctexture.cpp) into a buffer of this layout whose records keep the PC ids and whose data blocks hold the PC levels unexpanded (DXT1, DXT3, RGBA, I8, U8V8, PALN). DecodeTexture decodes those to RGBA8 at first draw like the disc's, keeps their full mip chains (up to 11 levels; TEXTURE_MAX_MIPS is 12) and turns PC normal maps into the (nx, ny, nz) texels the dot3 pass reads. The format page has the layout, the mapping and the comparison with the PS2 textures.
Replacement textures¶
The launcher's Files tab sets a texture pack folder (game.texture_pack in obm.config.json). port/engine/drawing/old/_sdl/texturepacksdl.cpp replaces a scene texture when the pack has a PNG for it:
<pack>/<scene>/<id>.png, where<scene>is the scene file's base name in lower case (m00_main,hitmanbloodmoney), taken fromZEngineDataBase::GetSceneNamewhenInstallTextureBufferinstalls the scene's.TEX, and<id>is the record'slTextureIdin decimal;<pack>/hash/<crc>.png, where<crc>is the CRC-32 (eight lower-case hex digits) of the decoded texture's width and height as two little-endian 32-bit words followed by its level-0 RGBA. This needs no ID mapping, so a pack can be made from the port's own dumps.
OPENBLOOD_TEXTURE_DUMP=<dir> writes each decoded PS2 texture, as it is first drawn, to <dir>/<scene>/<id>.png and <dir>/hash/<crc>.png: a template whose files can be edited or upscaled and used as a pack.
Each scene's folder is listed once when the scene loads, so a texture with no replacement costs no file access; the log says how many replacements a scene has and, at the next scene, how many it used. A replacement is loaded with SDL_LoadPNG at the texture's first draw, converted to RGBA8, given a full box-filtered mip chain (at most 12 levels, at most 4096 pixels a side) and uploaded in place of the PS2 texels. Every draw path samples with normalised coordinates (mesh ST times fUVScale, sprite UVs from 0 to 1), so a replacement of any size fits the same geometry; it should keep the original's aspect ratio. The sampler, clamping and scrolling still come from the PS2 record.
- Alpha is A/255 as in
DecodeTexture. When the PS2 texture is fully opaque the replacement is made opaque too, so that a picture with other data in its alpha is not drawn as transparent. (The PC alpha that looked like specular masks is the x component of the PC's DXT3 normal maps, which share their diffuse texture's name; the PC colour textures themselves have alpha below 255 in only 5 of the 5,201 that are opaque on the PS2.) - Normal maps (
lFlagsbit 13) are never replaced: the dot3 pass reads them as (nx, ny, nz, w). - Animated textures are replaced frame by frame, since each frame is its own record.
- The loader-sequence pictures (
loadersequencesdl.cpp) do not go through this path.
A pack from the PC version¶
tools/port/pc_texture_pack.py build <pc install> <out> [--scene M00_main ...] reads the PC install's Scenes/**/*.ZIP in memory, decodes level 0 of every texture (DXT1, DXT3, RGBA, I8, PALN; the U8V8 bump maps are skipped) into <out>/<scene>/<id>.png, and keeps <out>/manifest.csv (scene, id, PC name, format, size) across runs. The PC .TEX layout is described at the top of the script. RGBA texels and PALN palettes are stored R, G, B, A; the image height comes before the width in the record. The front end's 487 textures take about 16 seconds and M00's 1,007 about 24 seconds.
The pack keys PC textures by the PC's IDs, on the assumption that both versions number a scene's textures the same way. They do not: of 22,101 named PS2 textures, 10,120 have a PC texture of the same name in the same scene, but only 446 at the same id (all 68 scene pairs, 24 November 2026), so a PC pack keyed by id replaces the wrong PS2 textures. tools/port/pc_texture_pack.py compare <pc install> SCENES/M00/M00_MAIN.ZIP [--iso ISO] lists one scene's PS2 and PC records by ID (PS2 szName, the end of the PC name, both sizes) and counts IDs present in both, with the same aspect ratio, and with agreeing names; run it on a few scenes before relying on a PC pack. If the IDs do not correspond, a PC pack can still be used by hash, matched by name with the dump's IDs.