Expandable texture atlas for packing 2D images into a spritesheet to enable batch rendering.
More...
#include <GREM/graphics/SpriteAtlas.hpp>
|
| struct | Sprite |
| | Information about a specific image in the spritesheet. More...
|
Expandable texture atlas for packing 2D images into a spritesheet to enable batch rendering.
◆ SpriteAtlas()
Construct an empty sprite atlas.
- Parameters
-
| device | device to create the sprite atlas for. Must outlive the sprite atlas. |
| options | sprite atlas options, see SpriteAtlasOptions. |
◆ clear()
| void grem::graphics::SpriteAtlas::clear |
( |
| ) |
|
|
inlinenoexcept |
Clear all inserted sprites and images from the spritesheet.
◆ insertSprite()
Add a new image to the spritesheet, possibly expanding the texture atlas in order to make space for it.
- Parameters
-
| image | non-owning view over the image to copy into the spritesheet. |
| spriteOptions | sprite options, see SpriteOptions. |
- Returns
- an identifier for the inserted image.
- Exceptions
-
| graphics::Error | on failure to copy the image or expand the texture atlas. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
- Note
- The function will fail if the given image is not of a format that is compatible with the internal format of the texture atlas.
- See also
- createSubSprite()
◆ createSubSprite()
Add a new sprite that is defined as a sub-region of an existing sprite.
- Parameters
-
| 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. |
| region | region, in pixels, relative to the bottom left corner of the original sprite, where the new sprite will begin. Must fit within the original sprite image. |
| flip | flags that describe how the sprite should be flipped when rendered. |
- Returns
- an identifier for the new sub-sprite.
- Exceptions
-
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
- Note
- This function does not grow the texture atlas.
- See also
- insert()
◆ getSprite()
| const Sprite & grem::graphics::SpriteAtlas::getSprite |
( |
SpriteID | id | ) |
const |
|
inlinenodiscard |
Get information about a specific image in the spritesheet.
- Parameters
-
| 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. |
- Returns
- a read-only reference to the sprite information that is valid until the next call to insert(), or until the SpriteAtlas is destroyed, whichever happens first.
◆ getSpriteTextureOffsetAndScale()
| Pair< vec2 > grem::graphics::SpriteAtlas::getSpriteTextureOffsetAndScale |
( |
SpriteID | id | ) |
const |
|
inlinenodiscardnoexcept |
Get the offset and scale of a specific sprite in the texture atlas.
- Parameters
-
| 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. |
- Returns
- a pair of:
- the texture offset of the sprite, in normalized texture coordinates, and
- the texture scale of the sprite, in normalized texture coordinates.
◆ getAtlasTexture()
| const Texture & grem::graphics::SpriteAtlas::getAtlasTexture |
( |
| ) |
const |
|
inlinenodiscardnoexcept |
Get a reference to the internal texture atlas.
- Returns
- a read-only reference to the texture atlas containing the sprite image data that is valid until the next call to insert(), or until the SpriteAtlas is destroyed, whichever happens first.
◆ getOptions()
Get the configuration options of this spritesheet.
- Returns
- a read-only reference to the current options.
The documentation for this class was generated from the following file: