class EE::Graphics::TextureAtlasLoader

Overview

The Texture Atlas Loader loads any previously created Texture Atlas. More…

#include <textureatlasloader.hpp>

class TextureAtlasLoader {
public:
    // typedefs

    typedef std::function<void(TextureAtlasLoader*)> GLLoadCallback;

    // structs

    struct sTempTexAtlas;

    // construction

    TextureAtlasLoader();
    TextureAtlasLoader(const std::string& TextureAtlasPath, const bool& threaded = false, GLLoadCallback LoadCallback = GLLoadCallback());
    TextureAtlasLoader(const Uint8* Data, const Uint32& DataSize, const std::string& TextureAtlasName, const bool& threaded = false, GLLoadCallback LoadCallback = GLLoadCallback());
    TextureAtlasLoader(Pack* Pack, const std::string& FilePackPath, const bool& threaded = false, GLLoadCallback LoadCallback = GLLoadCallback());
    TextureAtlasLoader(IOStream& IOS, const bool& threaded = false, GLLoadCallback LoadCallback = GLLoadCallback());
    ~TextureAtlasLoader();

    // methods

    static TextureAtlasLoader* New();
    static TextureAtlasLoader* New(const std::string& TextureAtlasPath, const bool& threaded = false, GLLoadCallback LoadCallback = GLLoadCallback());
    static TextureAtlasLoader* New(const Uint8* Data, const Uint32& DataSize, const std::string& TextureAtlasName, const bool& threaded = false, GLLoadCallback LoadCallback = GLLoadCallback());
    static TextureAtlasLoader* New(Pack* Pack, const std::string& FilePackPath, const bool& threaded = false, GLLoadCallback LoadCallback = GLLoadCallback());
    static TextureAtlasLoader* New(IOStream& IOS, const bool& threaded = false, GLLoadCallback LoadCallback = GLLoadCallback());
    void loadFromFile(const std::string& TextureAtlasPath = "");
    void loadFromStream(IOStream& IOS);
    void loadFromMemory(const Uint8* Data, const Uint32& DataSize, const std::string& TextureAtlasName);
    void loadFromPack(Pack* Pack, const std::string& FilePackPath);
    bool isThreaded() const;
    void setThreaded(const bool& threaded);
    const bool& isLoaded() const;
    const bool& isLoading() const;
    bool updateTextureAtlas(std::string TextureAtlasPath, std::string ImagesPath, Sizei maxImageSize = Sizei::Zero);
    bool updateTextureAtlas();
    Texture* getTexture(const Uint32& texnum = 0) const;
    Uint32 getTexturesLoadedCount();
    TextureAtlas* getTextureAtlas() const;
    void setLoadCallback(GLLoadCallback LoadCallback);
    sTextureAtlasHdr getTextureAtlasHeader();
    void setTextureFilter(const Texture::Filter& textureFilter);
};

Detailed Documentation

The Texture Atlas Loader loads any previously created Texture Atlas.

Construction

TextureAtlasLoader()

Creates an empty loader. The texture atlas can be loaded callin any Load* function.

TextureAtlasLoader(const std::string& TextureAtlasPath, const bool& threaded = false, GLLoadCallback LoadCallback = GLLoadCallback())

Loads a texture atlas from its path ( the texture atlas binary is expected, not the texture, the “.eta” file ). If the loader is not threaded, it will load the atlas immediately.

Parameters:

TextureAtlasPath

The texture atlas path.

threaded

Indicates if the loading is done in another thread.

LoadCallback

The load notification callback.

TextureAtlasLoader(const Uint8* Data, const Uint32& DataSize, const std::string& TextureAtlasName, const bool& threaded = false, GLLoadCallback LoadCallback = GLLoadCallback())

Loads a texture atlas from memory. If the loader is not threaded, it will load the atlas immediately.

Parameters:

Data

The texture atlas buffer pointer

DataSize

The texture atlas buffer pointer size

TextureAtlasName

Since the texture atlas is loaded from memory, the name can’t be obtained from the file name. So it needs to be indicated manually.

threaded

Indicates if the loading is done in another thread.

LoadCallback

The load notification callback.

TextureAtlasLoader(Pack* Pack, const std::string& FilePackPath, const bool& threaded = false, GLLoadCallback LoadCallback = GLLoadCallback())

Loads a texture atlas from a pack file. If the loader is not threaded, it will load the atlas immediately.

Parameters:

Pack

The pointer of the pack instance to be used to load the file.

FilePackPath

The path of the file inside the pack.

threaded

Indicates if the loading is done in another thread.

LoadCallback

The load notification callback.

TextureAtlasLoader(IOStream& IOS, const bool& threaded = false, GLLoadCallback LoadCallback = GLLoadCallback())

Loads a texture atlas from a io stream. If the loader is not threaded, it will load the atlas immediately.

Parameters:

IOS

The io stream to use for the loading.

threaded

Indicates if the loading is done in another thread.

LoadCallback

The load notification callback.

Methods

void loadFromFile(const std::string& TextureAtlasPath = "")

Loads a texture atlas from its path ( the texture atlas binary is expected, not the texture, the “.eta” file ). If the loader is not threaded, it will load the atlas immediately.

Parameters:

TextureAtlasPath

The texture atlas path.

void loadFromStream(IOStream& IOS)

Loads a texture atlas from a io stream. If the loader is not threaded, it will load the atlas immediately.

Parameters:

IOS

The io stream to use for the loading.

void loadFromMemory(const Uint8* Data, const Uint32& DataSize, const std::string& TextureAtlasName)

Loads a texture atlas from memory. If the loader is not threaded, it will load the atlas immediately.

Parameters:

Data

The texture atlas buffer pointer

DataSize

The texture atlas buffer pointer size

TextureAtlasName

Since the texture atlas is loaded from memory, the name can’t be obtained from the file name. So it needs to be indicated manually.

void loadFromPack(Pack* Pack, const std::string& FilePackPath)

Loads a texture atlas from a pack file. If the loader is not threaded, it will load the atlas immediately.

Parameters:

Pack

The pointer of the pack instance to be used to load the file.

FilePackPath

The path of the file inside the pack.

bool isThreaded() const

Returns:

If the loader is threaded ( asynchronous ).

void setThreaded(const bool& threaded)

If threaded is true sets the loader as asynchronous. This must be called before the loading is done.

const bool& isLoaded() const

Returns:

True if the texture atlas is loaded.

const bool& isLoading() const

Returns:

True if the texture atlas is loading.

bool updateTextureAtlas(std::string TextureAtlasPath, std::string ImagesPath, Sizei maxImageSize = Sizei::Zero)

The function will check if the texture atlas is updated. Checks if all the images inside the images path are inside the texture atlas, and if they have the same date and size, otherwise it will recreate or update the texture atlas.

Parameters:

TextureAtlasPath

The path to the texture atlas ( the “.eta” file )

ImagesPath

The directory where the source images are located.

maxImageSize

Maximum texture size allowed for the new texture atlas created. Default value will use the current image size.

bool updateTextureAtlas()

Rewrites the texture atlas file. Usefull if the TextureRegions where modified and need to be updated inside the texture atlas.

Texture* getTexture(const Uint32& texnum = 0) const

Parameters:

texnum

The texture index. A texture atlas can use more than one texture, so it can be 0 to GetTexturesLoadedCount(). Usually a texture atlas corresponds to only one texture, so the texture index is 0.

Returns:

The texture that corresponds to the texture atlas.

Uint32 getTexturesLoadedCount()

Returns:

The number of textures linked to the texture atlas.

TextureAtlas* getTextureAtlas() const

Returns:

The texture atlas instance pointer ( NULL if the atlas isn’t loaded yet ).

void setLoadCallback(GLLoadCallback LoadCallback)

Sets a load notification callback.