QtCraft API C++ classes QML types Handbook

QcTextureAtlas Class

All content textures in one image with its mip levels (decision E-300). More...

Header: #include <clientcore/textures/QcTextureAtlas.h>

Public Types

struct TileSource
Options

Public Functions

QcTextureAnimation animation(const QString &textureName) const
int animationCycleTicks() const
const QImage &animationMap() const
qint64 bytes() const
bool contains(const QString &textureName) const
QRectF frameUv(const QString &textureName, int frame) const
const QImage &image() const
const QcAtlasLayout &layout() const
const QImage &levelForTile(int maxSide) const
const QList<QImage> &levels() const
QcTexturePackProblems notices() const
QStringList problems() const
int requestedTileSize() const
bool sameLayout(const QcTextureAtlas &other) const
const QHash<QString, int> &sources() const
QImage tile(const QString &textureName, int maxSide = 0) const
int tileSize() const
const QList<QcTextureAtlas::TileSource> &tileSources() const
QRectF uv(const QString &textureName) const
QRectF uvAt(const QString &textureName, double ticks) const

Static Public Members

QcTextureAtlas build(const QcContentRegistry &content, const QcTexturePackStack &packs = {}, const QcTextureAtlas::Options &options = {})
const int maxCycleTicks
const char *const missingTextureName

Detailed Description

Each texture comes from the active texture packs or the content (QcTextureSources); unknown or broken textures map to a magenta placeholder. The tile size is the highest resolution of the packs (16 without packs), halved until the atlas fits the GPU's texture size and the memory budget. The UV rectangles depend only on the list of textures, not on the tile size (QcAtlasLayout).

Member Type Documentation

[alias] QcTextureAtlas::Options

Limits and settings of build().

Member Function Documentation

QcTextureAnimation QcTextureAtlas::animation(const QString &textureName) const

For tests and tools (the renderer reads animationMap()): returns the animation of textureName (a still one for unknown names) and frameUv() its frames.

int QcTextureAtlas::animationCycleTicks() const

Returns the ticks after which every animation of the atlas starts over (the least common multiple of their loops): the time handed to the shader wraps there, so the float it gets keeps 1/8 tick at most. Capped at maxCycleTicks (2^20 ticks, about 14.5 h): a larger multiple (loops of many different prime lengths) wraps there anyway, and the animations whose loop does not divide it jump once at that wrap.

const QImage &QcTextureAtlas::animationMap() const

Returns the animated textures for the block shader (decision E-878): one RGBA8 texel per cell of the atlas grid (columns x rows), set at the cell of an animated texture's first frame: red the frame count plus 128 with interpolation, green the frame time in ticks, blue and alpha the low and high byte of the tile index of its second frame (the later frames follow it, row by row); 0 at every other cell. Each frame is a tile of its own with its gutter, so filtering and mip levels never mix frames.

[static] QcTextureAtlas QcTextureAtlas::build(const QcContentRegistry &content, const QcTexturePackStack &packs = {}, const QcTextureAtlas::Options &options = {})

Returns the atlas of all textures of content, taken from packs where they have them, within the limits of options.

qint64 QcTextureAtlas::bytes() const

Returns the bytes of all levels.

bool QcTextureAtlas::contains(const QString &textureName) const

Returns whether the atlas has a tile for textureName.

QRectF QcTextureAtlas::frameUv(const QString &textureName, int frame) const

For tests and tools: returns the UV rectangle of frame frame of textureName (frame 0 and still textures: uv()).

const QImage &QcTextureAtlas::image() const

Returns mip level 0.

const QcAtlasLayout &QcTextureAtlas::layout() const

Returns the layout of the tiles (also of the material maps) and where each tile came from.

const QImage &QcTextureAtlas::levelForTile(int maxSide) const

Returns the level whose tiles are at most maxSide pixels (at least the last level).

const QList<QImage> &QcTextureAtlas::levels() const

Returns all mip levels: level 0 first, each level half the size of the one before.

QcTexturePackProblems QcTextureAtlas::notices() const

Returns the notices for the player: the atlas uses a lower resolution than the packs asked for.

QStringList QcTextureAtlas::problems() const

Returns the content problems (English, for the log).

int QcTextureAtlas::requestedTileSize() const

Returns the resolution the packs asked for (tileSize() is smaller when a limit applied).

bool QcTextureAtlas::sameLayout(const QcTextureAtlas &other) const

Returns whether other has the same textures at the same UV rectangles, so meshes stay valid.

const QHash<QString, int> &QcTextureAtlas::sources() const

Returns how many tiles each source gave ("" = the content itself).

QImage QcTextureAtlas::tile(const QString &textureName, int maxSide = 0) const

Returns the single texture tile textureName from the level whose tiles are at most maxSide pixels (0: level 0), e.g. for item icons in the UI.

int QcTextureAtlas::tileSize() const

Returns the tile size of level 0 in pixels.

const QList<QcTextureAtlas::TileSource> &QcTextureAtlas::tileSources() const

Returns where each tile of layout() came from, by tile index.

QRectF QcTextureAtlas::uv(const QString &textureName) const

Returns the UV rectangle of textureName in [0, 1]; falls back to the placeholder for unknown names.

QRectF QcTextureAtlas::uvAt(const QString &textureName, double ticks) const

Returns the UV rectangle the texture textureName shows ticks into its animation: the frame the block shader picks at that time (QcTextureAnimation::frameAt), without blending into the next one; uv() for still textures. Entity meshes, built on the CPU every frame, pick their frames this way, so flames on a burning body flicker like fire blocks (decision E-919).

Member Variable Documentation

const int QcTextureAtlas::maxCycleTicks

Upper bound of animationCycleTicks(): 2^20 ticks, about 14.5 h.

const char *const QcTextureAtlas::missingTextureName

Name of the magenta placeholder texture for unknown or broken textures.