class EE::Graphics::TextureFactory

Overview

The Texture Manager Class. Here we do all the textures stuff. (Singleton Class) More…

#include <texturefactory.hpp>

class TextureFactory: protected EE::System::Mutex {
public:
    // structs

    struct LiveTextureRecord;
    struct TextureDeleter;

    // construction

    ~TextureFactory();

    // methods

    Texture* createEmptyTexture(
        const unsigned int& Width,
        const unsigned int& Height,
        const unsigned int& Channels = 4,
        const Color& DefaultColor = Color(0, 0, 0, 255),
        const bool& Mipmap = false,
        const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge,
        const bool& CompressTexture = false,
        const bool& KeepLocalCopy = false,
        const std::string& Filename = std::string("")
    );

    Texture* loadFromPixels(
        const unsigned char* Pixels,
        const unsigned int& Width,
        const unsigned int& Height,
        const unsigned int& Channels,
        const bool& Mipmap = false,
        const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge,
        const bool& CompressTexture = false,
        const bool& KeepLocalCopy = false,
        const std::string& FileName = std::string("")
    );

    Texture* loadFromPack(
        Pack* Pack,
        const std::string& FilePackPath,
        const bool& Mipmap = false,
        const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge,
        const bool& CompressTexture = false,
        const bool& KeepLocalCopy = false,
        const Image::FormatConfiguration& imageformatConfiguration = Image::FormatConfiguration()
    );

    Texture* loadFromMemory(
        const unsigned char* ImagePtr,
        const unsigned int& Size,
        const bool& Mipmap = false,
        const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge,
        const bool& CompressTexture = false,
        const bool& KeepLocalCopy = false,
        const Image::FormatConfiguration& imageformatConfiguration = Image::FormatConfiguration()
    );

    Texture* loadFromStream(IOStream& Stream, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge, const bool& CompressTexture = false, const bool& KeepLocalCopy = false, const Image::FormatConfiguration& imageformatConfiguration = Image::FormatConfiguration());
    Texture* loadFromFile(const std::string& Filepath, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge, const bool& CompressTexture = false, const bool& KeepLocalCopy = false, const Image::FormatConfiguration& imageformatConfiguration = Image::FormatConfiguration());
    bool remove(ResourceId textureId);
    bool remove(Texture* texture);
    void bind(ResourceId textureId, Texture::CoordinateType coordinateType = Texture::CoordinateType::Normalized, const Uint32& textureUnit = 0, const bool& forceRebind = false);
    void bind(const Texture* Tex, Texture::CoordinateType coordinateType = Texture::CoordinateType::Normalized, const Uint32& TextureUnit = 0, const bool& forceRebind = false);
    int getCurrentTexture(const Uint32& TextureUnit = 0) const;
    void setCurrentTexture(const int& textureHandle, const Uint32& TextureUnit);
    Uint32 getTextureCount();
    std::vector<Texture*> getTextures();
    TextureRegistrySnapshot snapshotTextures();
    void purgeExpiredTextures();
    Uint64 getLiveTextureGeneration() const;
    void collectReleasedTextures();
    std::size_t getPendingReleaseCount();
    void setActiveTextureUnit(const Uint32& Unit);
    unsigned int getValidTextureSize(const unsigned int& Size);
    bool existsId(ResourceId textureId);
    bool exists(const Texture* tex);
    Texture* getTexture(ResourceId textureId);
    unsigned int getTextureMemorySize();

    Texture* pushTexture(
        const std::string& Filepath,
        const Uint32& textureHandle,
        const unsigned int& Width,
        const unsigned int& Height,
        const unsigned int& ImgWidth,
        const unsigned int& ImgHeight,
        const bool& Mipmap,
        const unsigned int& Channels,
        const Texture::ClampMode& ClampMode,
        const bool& CompressTexture,
        const bool& LocalCopy = false,
        const Uint32& MemSize = 0
    );

    Texture* getByName(const std::string& Name);
    Texture* getByHash(const String::HashType& hash);
    const Texture::CoordinateType& getLastCoordinateType() const;
};

Inherited Members

public:
    // methods

    void lock();
    void unlock();
    bool tryLock();

Detailed Documentation

The Texture Manager Class. Here we do all the textures stuff. (Singleton Class)

Methods

Texture* createEmptyTexture(
    const unsigned int& Width,
    const unsigned int& Height,
    const unsigned int& Channels = 4,
    const Color& DefaultColor = Color(0, 0, 0, 255),
    const bool& Mipmap = false,
    const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge,
    const bool& CompressTexture = false,
    const bool& KeepLocalCopy = false,
    const std::string& Filename = std::string("")
)

Creates an empty texture

Parameters:

Width

Texture Width

Height

Texture Height

Channels

Texture Number of Channels (in bytes)

DefaultColor

The background color for the texture

Mipmap

Create Mipmap?

ClampMode

Defines the CLAMP MODE

CompressTexture

If use the DXT compression on the texture loading ( if the card can display them, will convert RGB to DXT1, RGBA to DXT5 )

KeepLocalCopy

Keep the array data copy. ( useful if want to reload the texture )

Filename

A filename to recognize the texture.

Returns:

The created texture

Texture* loadFromPixels(
    const unsigned char* Pixels,
    const unsigned int& Width,
    const unsigned int& Height,
    const unsigned int& Channels,
    const bool& Mipmap = false,
    const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge,
    const bool& CompressTexture = false,
    const bool& KeepLocalCopy = false,
    const std::string& FileName = std::string("")
)

Loads a RAW Texture from Memory

Parameters:

Pixels

The Texture array

Width

Texture Width

Height

Texture Height

Channels

Texture Number of Channels (in bytes)

Mipmap

Create Mipmap?

ClampMode

Defines the CLAMP MODE

CompressTexture

If use the DXT compression on the texture loading ( if the card can display them, will convert RGB to DXT1, RGBA to DXT5 )

KeepLocalCopy

Keep the array data copy. ( useful if want to reload the texture )

FileName

A filename to recognize the texture ( the path in case that was loaded from outside the texture factory ).

Returns:

The texture loaded or null if error

Texture* loadFromPack(
    Pack* Pack,
    const std::string& FilePackPath,
    const bool& Mipmap = false,
    const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge,
    const bool& CompressTexture = false,
    const bool& KeepLocalCopy = false,
    const Image::FormatConfiguration& imageformatConfiguration = Image::FormatConfiguration()
)

Load a texture from Pack file

Parameters:

Pack

Pointer to the pack instance

FilePackPath

The path of the file inside the pack

Mipmap

Create Mipmap?

ClampMode

Defines the CLAMP MODE

CompressTexture

If use the DXT compression on the texture loading ( if the card can display them, will convert RGB to DXT1, RGBA to DXT5 )

KeepLocalCopy

Keep the array data copy. ( useful if want to reload the texture )

imageformatConfiguration

The specific image format configuration to use when decoding the image.

Returns:

The texture loaded or null if error

Texture* loadFromMemory(
    const unsigned char* ImagePtr,
    const unsigned int& Size,
    const bool& Mipmap = false,
    const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge,
    const bool& CompressTexture = false,
    const bool& KeepLocalCopy = false,
    const Image::FormatConfiguration& imageformatConfiguration = Image::FormatConfiguration()
)

Load a texture from memory

Parameters:

ImagePtr

The image data in RAM just as if it were still in a file

Size

The size of the texture ( Width * Height * BytesPerPixel )

Mipmap

Use mipmaps?

ClampMode

Defines the CLAMP MODE

CompressTexture

If use the DXT compression on the texture loading ( if the card can display them, will convert RGB to DXT1, RGBA to DXT5 )

KeepLocalCopy

Keep the array data copy. ( useful if want to reload the texture )

imageformatConfiguration

The specific image format configuration to use when decoding the image.

Returns:

The texture loaded or null if error

Texture* loadFromStream(IOStream& Stream, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge, const bool& CompressTexture = false, const bool& KeepLocalCopy = false, const Image::FormatConfiguration& imageformatConfiguration = Image::FormatConfiguration())

Load a Texture from stream

Parameters:

Stream

The IOStream instance

Mipmap

Use mipmaps?

ClampMode

Defines the CLAMP MODE

CompressTexture

If use the DXT compression on the texture loading ( if the card can display them, will convert RGB to DXT1, RGBA to DXT5 )

KeepLocalCopy

Keep the array data copy. ( useful if want to reload the texture )

imageformatConfiguration

The specific image format configuration to use when decoding the image.

Returns:

The texture loaded or null if error

Texture* loadFromFile(const std::string& Filepath, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge, const bool& CompressTexture = false, const bool& KeepLocalCopy = false, const Image::FormatConfiguration& imageformatConfiguration = Image::FormatConfiguration())

Load a Texture from a file path

Parameters:

Filepath

The path for the texture

Mipmap

Use mipmaps?

ClampMode

Defines the CLAMP MODE

CompressTexture

If use the DXT compression on the texture loading ( if the card can display them, will convert RGB to DXT1, RGBA to DXT5 )

KeepLocalCopy

Keep the array data copy. ( useful if want to reload the texture )

imageformatConfiguration

The specific image format configuration to use when decoding the image.

Returns:

The texture loaded or null if error

bool remove(ResourceId textureId)

Removes and unloads the texture identified by textureId.

Parameters:

textureId

The process-wide texture identity.

Returns:

True if was removed

bool remove(Texture* texture)

Removes and Unload the Texture

Parameters:

texture

The texture pointer

Returns:

True if was removed

void bind(ResourceId textureId, Texture::CoordinateType coordinateType = Texture::CoordinateType::Normalized, const Uint32& textureUnit = 0, const bool& forceRebind = false)

Binds the texture identity indicated. This is useful if you are rendering a texture outside this class.

Parameters:

textureId

The process-wide texture identity.

coordinateType

Use normalized or pixel coordinates

textureUnit

The Texture Unit binded

forceRebind

Force the texture bind (even if is already binded ).

void bind(const Texture* Tex, Texture::CoordinateType coordinateType = Texture::CoordinateType::Normalized, const Uint32& TextureUnit = 0, const bool& forceRebind = false)

Bind the the Texture indicated. This is useful if you are rendering a texture outside this class.

Parameters:

Tex

The Texture Pointer

coordinateType

Selects the coordinate type to use with the binded texture.

TextureUnit

The Texture Unit binded

forceRebind

Force the texture bind (even if is already binded ).

int getCurrentTexture(const Uint32& TextureUnit = 0) const

Parameters:

TextureUnit

The bound texture unit.

Returns:

The currently bound OpenGL texture handle.

void setCurrentTexture(const int& textureHandle, const Uint32& TextureUnit)

Sets the currently bound OpenGL texture handle.

Parameters:

textureHandle

The OpenGL texture handle.

TextureUnit

The Texture Unit binded

Uint32 getTextureCount()

Returns the number of textures loaded

std::vector<Texture*> getTextures()

Returns:

All the active textures

TextureRegistrySnapshot snapshotTextures()

Returns:

A non-owning diagnostic snapshot of every currently live texture.

void purgeExpiredTextures()

Removes expired records from the diagnostic live-texture registry.

Uint64 getLiveTextureGeneration() const

Returns:

The generation of the live-texture registry. It changes when a texture is created or its last owning handle is released.

void collectReleasedTextures()

Destroys textures whose final owning handle was released. Must run on the graphics thread after pending batches have been flushed and while a context is current.

std::size_t getPendingReleaseCount()

Returns:

The number of textures waiting for graphics-thread destruction.

void setActiveTextureUnit(const Uint32& Unit)

Active a texture unit

unsigned int getValidTextureSize(const unsigned int& Size)

Parameters:

Size

Returns:

A valid texture size for the video card (checks if support non power of two textures)

bool existsId(ResourceId textureId)

Determines whether the texture identity exists in the factory.

bool exists(const Texture* tex)

Determines whether the texture is retained by the factory.

Texture* getTexture(ResourceId textureId)

Returns:

The texture matching textureId, or null if it is not factory-retained.

unsigned int getTextureMemorySize()

Returns:

The memory used by the textures (in bytes)

Texture* pushTexture(
    const std::string& Filepath,
    const Uint32& textureHandle,
    const unsigned int& Width,
    const unsigned int& Height,
    const unsigned int& ImgWidth,
    const unsigned int& ImgHeight,
    const bool& Mipmap,
    const unsigned int& Channels,
    const Texture::ClampMode& ClampMode,
    const bool& CompressTexture,
    const bool& LocalCopy = false,
    const Uint32& MemSize = 0
)

It’s possible to create textures outside the texture factory loader, but the library will need to know of this texture, so it’s necessary to push the texture to the factory.

Parameters:

Filepath

The Texture path ( if exists )

textureHandle

The OpenGL texture handle.

Width

Texture Width

Height

Texture Height

ImgWidth

Image Width.

ImgHeight

Image Height

Mipmap

Tell if the texture has mipmaps

Channels

Texture number of Channels ( bytes per pixel )

ClampMode

The Texture Clamp Mode

CompressTexture

The texture is compressed?

LocalCopy

If keep a local copy in memory of the texture

MemSize

The size of the texture in memory ( just if you need to specify the real size in memory, just useful to calculate the total texture memory ).

Texture* getByName(const std::string& Name)

Return a texture by it file path name

Parameters:

Name

File path name

Returns:

The texture, NULL if not exists.

Texture* getByHash(const String::HashType& hash)

Return a texture by it hash path name

Parameters:

Hash

The file path hash

Returns:

The texture, NULL if not exists