TileAtlas
Maps a block type to the UV rectangle of its texture icon in object-m.png, either as the sheet is or as the terrain's padded copy.
| Header | src/GalaxyEggbert/Game/TileAtlas.hpp |
|---|---|
| Source | src/GalaxyEggbert/Game/TileAtlas.cpp |
| Namespace | GalaxyEggbert::Game |
| Former name | GETileAtlas |
Purpose
Every terrain block is textured with one icon of the original's tile sheet Content/icons/object-m.png:
1301 × 1431 pixels, 64-pixel tiles with a 1-pixel gap before each, 20 columns by 22 rows (icons 0-439).
TileAtlas is data only: it loads no pixels and draws nothing. GetTileUv() looks the block up in the
BlockDefinitionRegistry, takes its textureIcon (which may differ from the
block type) and returns that icon's rectangle.
Two layouts:
Layout::Sheet— the sheet as it is on disk. The rectangle comes fromBlockTypes::tileUV(), which accounts for the 65-pixel pitch and adds a half-texel inset so bilinear filtering never samples the gap or the next tile (the cause of thin seam lines seen in July 2026). Used for lift and crate cubes, the editor's markers and particles cut from tiles.Layout::Padded— the terrain's own copy built byBuildPaddedSheet(): each 64-pixel tile placed on a 96-pixel pitch with a 16-pixel border of its own edge texels (1920 × 2112 at 1x). It can be mipmapped without tiles bleeding into each other (distant floors used to shimmer into rings), and needs no inset. At texture scale 2 the tiles are 128 pixels, the border stays 16 and the sheet is 3200 × 3520, inside the 4096 limit.
Collaborators
- BlockDefinitionRegistry:
GetBlockDefinition(),textureSource,textureIcon. BlockTypes(include/GalaxyEggbert/BlockTypes.hpp):kSheetW,kSheetH,kTileSize,kSheetGap,kSheetCols,tileUV().- cna-engine's
CnaEngine::Graphics::UvRect, the type returned. - TerrainRenderer (padded atlas), the scene builder in
GalaxyEggbertGameScene.cppand the editor (sheet atlas). TextureScale.hpp: which scale a run loads (1x, or 2x whereContent/icons2x/exists).
Public API
| Member | What it does |
|---|---|
enum class Layout { Sheet, Padded } | Which texture the UVs are for. |
TileAtlas(), explicit TileAtlas(Layout layout, int scale = 1) | Default is Sheet at scale 1; a scale below 1 counts as 1. |
CnaEngine::Graphics::UvRect GetTileUv(int blockType) const | The rectangle, or all zeros for air, negative or out-of-sheet types, unsupported types and types not textured from object-m.png. |
int Scale() const | The texture scale given. |
PaddedLayout Padded() const, static constexpr PaddedLayout PaddedLayoutFor(int scale) | Tile, border, pitch, width and height of the padded sheet at a scale. |
kPaddedBorder = 16, kPaddedPitch = 96, kPaddedColumns = 20, kPaddedRows = 22, kPaddedWidth, kPaddedHeight | The 1x padded layout's constants. |
Free functions in the same header:
| Function | What it does |
|---|---|
std::vector<std::uint8_t> BuildPaddedSheet(const std::uint8_t* sheetRgba, int width, int height, int scale = 1) | The padded RGBA sheet from object-m.png's texels. |
std::vector<std::uint8_t> DownsampleHalf(const std::vector<std::uint8_t>& rgba, int width, int height) | The next mip level: each texel the mean of a 2 × 2 block. |
How it is used
The game keeps two atlases (src/GalaxyEggbertCNA/GalaxyEggbertGame.hpp):
// Maps block types to object-m.png UV rects (plan.md E3D-MIG-053).
GalaxyEggbert::Game::TileAtlas tileAtlas_;
// The terrain's own padded, mipmapped copy of object-m.png and its UVs (TileAtlas.hpp Layout::Padded).
GalaxyEggbert::Game::TileAtlas terrainTileAtlas_{GalaxyEggbert::Game::TileAtlas::Layout::Padded};
At load it builds the padded texture with BuildPaddedSheet() and its mip chain with DownsampleHalf(), and
hands terrainTileAtlas_ to every TerrainRenderer. A UV from one layout is only valid
on that layout's texture; mixing them shows the wrong part of the sheet.
VerifyTileUvBounds keeps this as an explicit, tracked exception.Tests
VerifyTileFaces(tools/VerifyTileFaces.cpp): padded rectangles (border, pitch, 64-texel width),BuildPaddedSheet()'s edge copies, the 1x and 2x padded layouts.VerifyTileUvBounds:BlockTypes::tileUV()keeps every icon 0-439 inside the sheet.VerifyTileCoverage: the sheet's 1301 × 1431 holds 440 icons, and the 2x layout.
Related pages
- Assets & Tools — the tile sheet's geometry and origin.
- Rendering, TerrainRenderer, BlockDefinitionRegistry.