class EE::Graphics::TextureFactory¶
Overview¶
Creates textures and weakly observes every live texture for diagnostics. More…
#include <texturefactory.hpp> class TextureFactory: protected EE::System::Mutex { public: // structs struct LiveTextureRecord; struct TextureDeleter; // construction ~TextureFactory(); // methods TexturePtr 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("") ); TexturePtr 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("") ); TexturePtr 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() ); TexturePtr 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() ); TexturePtr 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()); TexturePtr 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()); 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(); 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); TexturePtr getTexture(ResourceId textureId); unsigned int getTextureMemorySize(); TexturePtr 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 ); const Texture::CoordinateType& getLastCoordinateType() const; };
Inherited Members¶
public: // methods void lock(); void unlock(); bool tryLock();
Detailed Documentation¶
Creates textures and weakly observes every live texture for diagnostics.
Methods¶
TexturePtr 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
TexturePtr 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
TexturePtr 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
TexturePtr 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
TexturePtr 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
TexturePtr 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
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 currently live 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 is currently live.
TexturePtr getTexture(ResourceId textureId)
Returns:
The live texture matching textureId, or null if it has expired.
unsigned int getTextureMemorySize()
Returns:
The memory used by the textures (in bytes)
TexturePtr 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 ). |