|
ObjectivelyMVC
Object oriented MVC framework for SDL3 and GNU C
|
Packs many Images into one sheet, backed by one Texture. More...
#include <ImageAtlas.h>
Public Member Functions | |
| Class * | _ImageAtlas (void) |
| AtlasImage * | addImage (ImageAtlas *self, Image *image) |
| Adds the given Image to this atlas. | |
| AtlasImage * | addImageWithName (ImageAtlas *self, const char *name, Image *image) |
Adds the given Image to this atlas, registered under name for ImageAtlas::imageWithName. | |
| AtlasImage * | addImageWithResourceName (ImageAtlas *self, const char *name, float pixelDensity) |
| Loads the Image Resource by the given name and adds it to this atlas. | |
| bool | compile (ImageAtlas *self) |
| Packs every added Image into a new sheet. | |
| AtlasImage * | imageWithName (const ImageAtlas *self, const char *name) |
| ImageAtlas * | init (ImageAtlas *self) |
| Initializes this ImageAtlas. | |
| void | renderDeviceWillReset (ImageAtlas *self) |
| Releases this atlas' Texture ahead of a RenderDevice reset. | |
| Texture * | texture (ImageAtlas *self, RenderDevice *device) |
| Resolves the sheet's Texture, creating it on the given device if necessary. | |
Data Fields | |
| unsigned | generation |
| Incremented by every ImageAtlas::addImageWithName and ImageAtlas::compile, so that anything derived from this atlas' contents or layout can tell when it is stale. | |
| Image * | image |
The compiled sheet, or NULL until ImageAtlas::compile. | |
| Array * | images |
| The AtlasImages, in the order added. | |
| int | maxSize |
| The largest sheet dimension ImageAtlas::compile will attempt. | |
| Object | object |
| The superclass. | |
Protected Attributes | |
| ImageAtlasInterface * | interface [0] |
| The interface type. | |
Packs many Images into one sheet, backed by one Texture.
The Renderer merges consecutive draws that share a Texture into one draw call, so a UI whose images all come from one atlas draws in a handful of calls rather than one per View. Add Images, then compile: every AtlasImage learns where its pixels landed, and the sheet's Texture is created on first request and shared by every View that draws from it.
Packing is by shelves: images are sorted by height, then laid out left to right in rows, onto the smallest power-of-two square that holds them, up to maxSize. There is no padding: the Renderer samples without mipmaps, so there are no mip levels to bleed across.
Definition at line 49 of file ImageAtlas.h.
| Class * _ImageAtlas | ( | void | ) |
Definition at line 324 of file ImageAtlas.c.
| AtlasImage * addImage | ( | ImageAtlas * | self, |
| Image * | image | ||
| ) |
Adds the given Image to this atlas.
| self | The ImageAtlas. |
| image | The Image. Its surface is shared with the returned AtlasImage. |
rect is not valid until the next ImageAtlas::compile. Definition at line 59 of file ImageAtlas.c.
| AtlasImage * addImageWithName | ( | ImageAtlas * | self, |
| const char * | name, | ||
| Image * | image | ||
| ) |
Adds the given Image to this atlas, registered under name for ImageAtlas::imageWithName.
Names are unique: registering a name again replaces the mapping, while the previously registered AtlasImage remains in the atlas.
| self | The ImageAtlas. |
| name | The name. |
| image | The Image. Its surface is shared with the returned AtlasImage. |
rect is not valid until the next ImageAtlas::compile. Definition at line 96 of file ImageAtlas.c.
| AtlasImage * addImageWithResourceName | ( | ImageAtlas * | self, |
| const char * | name, | ||
| float | pixelDensity | ||
| ) |
Loads the Image Resource by the given name and adds it to this atlas.
| self | The ImageAtlas. |
| name | The Resource name. |
NULL if the Resource was not found. Definition at line 77 of file ImageAtlas.c.
| bool compile | ( | ImageAtlas * | self | ) |
Packs every added Image into a new sheet.
Every AtlasImage's rect is reassigned, and the previous sheet and Texture are released, so a View drawing from this atlas MUST read rect and ImageAtlas::texture at draw time rather than caching either. Compiling repacks everything from scratch, so add all Images first and compile once.
| self | The ImageAtlas. |
true if every Image fit within maxSize, false otherwise. Definition at line 170 of file ImageAtlas.c.
| AtlasImage * imageWithName | ( | const ImageAtlas * | self, |
| const char * | name | ||
| ) |
| self | The ImageAtlas. |
| name | The name. |
name via ImageAtlas::addImageWithName, or NULL. Definition at line 112 of file ImageAtlas.c.
| ImageAtlas * init | ( | ImageAtlas * | self | ) |
Initializes this ImageAtlas.
| self | The ImageAtlas. |
NULL on error. Definition at line 260 of file ImageAtlas.c.
| void renderDeviceWillReset | ( | ImageAtlas * | self | ) |
Releases this atlas' Texture ahead of a RenderDevice reset.
An ImageAtlas is not a View, so nothing calls this on its behalf: every View that draws from an atlas MUST forward its own View::renderDeviceWillReset here. The call is idempotent, so shared atlases are fine.
| self | The ImageAtlas. |
Definition at line 281 of file ImageAtlas.c.
| Texture * texture | ( | ImageAtlas * | self, |
| RenderDevice * | device | ||
| ) |
Resolves the sheet's Texture, creating it on the given device if necessary.
| self | The ImageAtlas. |
| device | The RenderDevice. |
NULL if the atlas has not been compiled. Definition at line 289 of file ImageAtlas.c.
| unsigned ImageAtlas::generation |
Incremented by every ImageAtlas::addImageWithName and ImageAtlas::compile, so that anything derived from this atlas' contents or layout can tell when it is stale.
Definition at line 66 of file ImageAtlas.h.
| Image* ImageAtlas::image |
The compiled sheet, or NULL until ImageAtlas::compile.
Definition at line 71 of file ImageAtlas.h.
| Array* ImageAtlas::images |
The AtlasImages, in the order added.
Definition at line 76 of file ImageAtlas.h.
|
protected |
The interface type.
Definition at line 60 of file ImageAtlas.h.
| int ImageAtlas::maxSize |
The largest sheet dimension ImageAtlas::compile will attempt.
Sheets are power-of-two squares, so this SHOULD be a power of two; a value that is not rounds down to one. Defaults to IMAGE_ATLAS_MAX_SIZE, which every SDL_GPU backend supports.
Definition at line 90 of file ImageAtlas.h.
| Object ImageAtlas::object |
The superclass.
Definition at line 54 of file ImageAtlas.h.