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:
    // 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(Uint32 TexId);
    bool remove(Texture* texture);
    void reloadAllTextures();
    void bind(const Uint32& TexId, 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);
    Uint32 getTextureId(const Uint32& TexId);
    int getCurrentTexture(const Uint32& TextureUnit = 0) const;
    void setCurrentTexture(const int& TexId, const Uint32& TextureUnit);
    Uint32 getTextureCount() const;
    std::vector<Texture*> getTextures();
    void setActiveTextureUnit(const Uint32& Unit);
    unsigned int getValidTextureSize(const unsigned int& Size);
    bool existsId(const Uint32& TexId);
    bool exists(const Texture* tex);
    Texture* getTexture(const Uint32& TexId);
    void grabTextures();
    void ungrabTextures();
    void allocate(const unsigned int& size);
    unsigned int getTextureMemorySize();

    Texture* pushTexture(
        const std::string& Filepath,
        const Uint32& TexId,
        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(Uint32 TexId)

Removes and Unload the Texture Id

Parameters:

TexId

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 reloadAllTextures()

Reload all loaded textures to recover the OpenGL context

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

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

Parameters:

TexId

The internal Texture Id

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 ).

Uint32 getTextureId(const Uint32& TexId)

Parameters:

TexId

The internal Texture Id

Returns:

The OpenGL Texture Id (texture handler)

int getCurrentTexture(const Uint32& TextureUnit = 0) const

Parameters:

TextureUnit

The Texture Unit binded

Returns:

The real current texture id (OpenGL Texture Id)

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

Set the current internal texture id. This will set the TexId as the current texture binded.

Parameters:

TexId

The real current texture id (OpenGL Texture Id)

TextureUnit

The Texture Unit binded

Uint32 getTextureCount() const

Returns the number of textures loaded

std::vector<Texture*> getTextures()

Returns:

All the active textures

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(const Uint32& TexId)

Determine if the TextureId passed exists

bool exists(const Texture* tex)

Determine if the TextureId passed exists

Texture* getTexture(const Uint32& TexId)

Returns:

A pointer to the Texture

void grabTextures()

Get a local copy for all the textures

void ungrabTextures()

Reload all the grabed textures

void allocate(const unsigned int& size)

Allocate space for Textures (only works if EE_ALLOC_TEXTURES_ON_VECTOR is defined)

unsigned int getTextureMemorySize()

Returns:

The memory used by the textures (in bytes)

Texture* pushTexture(
    const std::string& Filepath,
    const Uint32& TexId,
    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 )

TexId

The OpenGL Texture Id

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