2013-10-09 11:44:15 +00:00
|
|
|
/*
|
|
|
|
** tileatlas.h
|
|
|
|
**
|
|
|
|
** This file is part of mkxp.
|
|
|
|
**
|
|
|
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
|
|
**
|
|
|
|
** mkxp is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 2 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** mkxp is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
Implement a new tileset atlas layout to allow for bigger tilesets
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.
2013-09-23 20:21:58 +00:00
|
|
|
#ifndef TILEATLAS_H
|
|
|
|
#define TILEATLAS_H
|
|
|
|
|
|
|
|
#include "etc-internal.h"
|
|
|
|
|
2013-12-26 19:18:33 +00:00
|
|
|
#include <vector>
|
Implement a new tileset atlas layout to allow for bigger tilesets
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.
2013-09-23 20:21:58 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2013-12-26 19:18:33 +00:00
|
|
|
typedef std::vector<Blit> BlitList;
|
Implement a new tileset atlas layout to allow for bigger tilesets
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.
2013-09-23 20:21:58 +00:00
|
|
|
|
|
|
|
/* 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
|