The atlas packing algorithm has been reworked to pack autotiles and tileset very efficiently into a texture, splitting the tileset in multiple ways and eliminating the previous duplication of image data in the atlas across "frames". Animation, which these frames were designed for, is now done via duplicated buffer frames, ie. each animation frame has its own VBO and IBO data. This was not done to save on VRAM (hardly less memory is used), but to make place for the new atlas layout. Thanks to this new layout, even with a max texture size of 2048, one can use tilesets with up to 15000 height. Of course, such a tileset couldn't be stored in a regular Bitmap to begin with, which is why I also introduced a hack called "mega surfaces": software surfaces stored in RAM and wrapped inside a Bitmap, whose sole purpose is to be passed to a Tilemap as tilesets. Various other minor changes and fixes are included.
45 lines
953 B
C++
45 lines
953 B
C++
#ifndef TILEATLAS_H
|
|
#define TILEATLAS_H
|
|
|
|
#include "etc-internal.h"
|
|
|
|
#include <QList>
|
|
|
|
namespace TileAtlas
|
|
{
|
|
|
|
/* Abstract definition of a blit
|
|
* operation with undefined rect width */
|
|
struct Blit
|
|
{
|
|
Vec2i src;
|
|
Vec2i dst;
|
|
int h;
|
|
|
|
Blit(int sx, int sy,
|
|
int dx, int dy,
|
|
int h)
|
|
: src(sx, sy),
|
|
dst(dx, dy),
|
|
h(h)
|
|
{}
|
|
};
|
|
|
|
typedef QList<Blit> BlitList;
|
|
|
|
/* Calculates the minimum atlas size required to hold
|
|
* a tileset of height 'tilesetH'. If the required dimensions
|
|
* exceed 'maxAtlasSize', Vec2i(-1, -1) is returned. */
|
|
Vec2i minSize(int tilesetH, int maxAtlasSize);
|
|
|
|
/* Calculates a series of blits necessary to fill dstRows
|
|
* with srcRows without wasting any space */
|
|
BlitList calcBlits(int tilesetH, const Vec2i &atlasSize);
|
|
|
|
/* Translates a tile coordinate (not pixel!) to a physical
|
|
* pixel coordinate in the atlas */
|
|
Vec2i tileToAtlasCoor(int tileX, int tileY, int tilesetH, int atlasH);
|
|
|
|
}
|
|
|
|
#endif // TILEATLAS_H
|