libdonut
2.3.2
Application framework for cross-platform game development in C++20
|
Expandable texture atlas for packing 2D images into a spritesheet to enable batch rendering. More...
#include <donut/graphics/SpriteAtlas.hpp>
Classes | |
struct | Sprite |
Information about a specific image in the spritesheet. More... | |
struct | SpriteId |
Identifier for a specific image in the spritesheet. More... | |
Public Types | |
enum | FlipAxis : Flip { NO_FLIP = 0 , FLIP_HORIZONTALLY = 1 << 0 , FLIP_VERTICALLY = 1 << 1 } |
Flag values for Flip that describe how a sprite is flipped when rendered. More... | |
using | Flip = std::uint8_t |
Flags that describe how a sprite is flipped when rendered. More... | |
Public Member Functions | |
SpriteAtlas ()=default | |
Construct an empty sprite atlas. More... | |
SpriteAtlas (const SpriteAtlasOptions &options) | |
Construct an empty sprite atlas. More... | |
SpriteId | insert (Renderer &renderer, const ImageView &image, Flip flip=NO_FLIP) |
Add a new image to the spritesheet, possibly expanding the texture atlas in order to make space for it. More... | |
SpriteId | createSubSprite (SpriteId baseSpriteId, std::size_t offsetX, std::size_t offsetY, std::size_t width, std::size_t height, Flip flip=NO_FLIP) |
Add a new sprite that is defined as a sub-region of an existing sprite. More... | |
const Sprite & | getSprite (SpriteId id) const |
Get information about a specific image in the spritesheet. More... | |
const Texture & | getAtlasTexture () const noexcept |
Get a reference to the internal texture atlas. More... | |
Expandable texture atlas for packing 2D images into a spritesheet to enable batch rendering.
using donut::graphics::SpriteAtlas::Flip = std::uint8_t |
Flags that describe how a sprite is flipped when rendered.
|
default |
Construct an empty sprite atlas.
|
inlineexplicit |
Construct an empty sprite atlas.
options | sprite atlas options, see SpriteAtlasOptions. |
|
inline |
Add a new image to the spritesheet, possibly expanding the texture atlas in order to make space for it.
renderer | renderer to use for expanding the texture atlas, if needed. |
image | non-owning view over the image to copy into the spritesheet. |
flip | flags that describe how the sprite should be flipped when rendered. |
graphics::Error | on failure to copy the image or expand the texture atlas. |
std::bad_alloc | on allocation failure. |
|
inline |
Add a new sprite that is defined as a sub-region of an existing sprite.
baseSpriteId | identifier for the existing sprite to create a sub-region of. Must have been obtained from a previous call to insert() or createSubSprite() on the same SpriteAtlas object as the one that this function is called on. |
offsetX | horizontal offset, in pixels, from the left edge of the original sprite, where the new sprite will begin. Must be less than or equal to the width of the original sprite image. |
offsetY | vertical offset, in pixels, from the bottom edge of the original sprite, where the new sprite will begin. Must be less than or equal to the height of the original sprite image. |
width | width, in pixels, of the new sprite region. Must be less than or equal to the width of the original sprite image minus offsetX. |
height | height, in pixels, of the new sprite region. Must be less than or equal to the height of the original sprite image minus offsetY. |
flip | flags that describe how the sprite should be flipped when rendered. |
std::bad_alloc | on allocation failure. |
Get information about a specific image in the spritesheet.
id | identifier for the image to get the information of. Must have been obtained from a previous call to insert() or createSubSprite() on the same SpriteAtlas object as the one that this function is called on. |
|
inlinenoexcept |
Get a reference to the internal texture atlas.