Simple++
Powerfull and lightning fast C++ Library
Public Types | Public Member Functions | Protected Member Functions | List of all members
Graphic::TextureLoadable< T > Class Template Reference

#include <TextureLoadable.h>

Inheritance diagram for Graphic::TextureLoadable< T >:
BasicLoadableIO Graphic::Texture< T > BasicSimpleLoadableIO BasicIO BasicSimpleIO BasicLoadable BasicSimpleIO

Public Types

enum  LoadingType { EMPTY, FILE }
 

Public Member Functions

 TextureLoadable (typename Format format=Format::RGB)
 Empty constructor, create an image unallocated of size (0:0) More...
 
 TextureLoadable (const Math::Vec2< Size > &size, typename Format format=Format::RGB)
 Constructor to create an not initialized image of specified size. More...
 
 TextureLoadable (const WString &filePath)
 create a new image using a path to a file (only support official file format) More...
 
 TextureLoadable (const TextureLoadable< T > &image)
 copy constructor More...
 
 TextureLoadable (TextureLoadable< T > &&image)
 move constructor More...
 
 ~TextureLoadable ()
 
void setDatas (const T *dataBuffer, const Math::Vec2< Size > &size, typename LoadingFormat loadingFormat=LoadingFormat::RGB, bool invertY=false)
 load this image from a buffer and a specified size. More...
 
void clear (const Math::Vec2< Size > &size)
 clear this texture with a new size More...
 
void clear (const Math::Vec2< Size > &size, typename Format format)
 reset this image with a new size and a new format More...
 
void generateMipmaps ()
 generate the mipmaps from the actual lod 0 More...
 
const T * getDatas (typename Vector< _Image< T >>::Size i=0) const
 get the data buffer of this image More...
 
T * getDatas (typename Vector< _Image< T >>::Size i=0)
 get the data buffer of this image More...
 
const T * getPixel (typename Vector< _Image< T >>::Size i, unsigned int x, unsigned int y) const
 get a pixel from this image More...
 
void setPixel (typename Vector< _Image< T >>::Size i, unsigned int x, unsigned int y, const T *p)
 set a pixel inside this image More...
 
Texture< T > & operator= (const Texture< T > &image)
 copy operator More...
 
Texture< T > & operator= (Texture< T > &&image)
 move operator More...
 
Format getFormat () const
 get the format of this image More...
 
- Public Member Functions inherited from BasicLoadableIO
 BasicLoadableIO ()
 
 ~BasicLoadableIO ()
 
bool writeToFile (const WString &path)
 write this object to a file. More...
 
bool readFromFile (const WString &path)
 load this object from a file. More...
 
- Public Member Functions inherited from BasicSimpleLoadableIO
 BasicSimpleLoadableIO ()
 
 ~BasicSimpleLoadableIO ()
 
bool read (std::fstream *fileStream)
 load this object from a file stream More...
 
bool write (std::fstream *fileStream)
 write this object as binary into a file stream More...
 
- Public Member Functions inherited from BasicSimpleIO
bool read (std::fstream *fileStream)
 read from a file stream More...
 
bool write (std::fstream *fileStream) const
 write this object as binary into a file stream More...
 
- Public Member Functions inherited from BasicLoadable
 BasicLoadable ()
 Empty constructor initialized at NOT loaded and NOT loading. More...
 
 BasicLoadable (const BasicLoadable &loadable)
 copy constructor More...
 
 ~BasicLoadable ()
 
void load ()
 load the object (this function may not be overloaded) More...
 
void unload ()
 unload this object (this function may not be overloaded) More...
 
bool isLoaded () const
 get if the current object is loaded or not More...
 
void reload ()
 if the current object is loaded, unload it and then call load again, if not, this do nothing. More...
 
bool isLoading () const
 get if the current object is currently loading More...
 
void lock ()
 lock the current object to ensure no parallelization of the loading state. More...
 
void unlock ()
 unlock the current object to permit parallelization of the loading state. More...
 
BasicLoadableoperator= (const BasicLoadable &loadable)
 copy operator More...
 
- Public Member Functions inherited from Graphic::Texture< T >
 Texture (typename Format format=Format::RGB)
 Empty constructor, create an image unallocated of size (0:0) More...
 
 Texture (const Math::Vec2< Size > &size, typename Format format=Format::RGB)
 Constructor to create an not initialized image of specified size. More...
 
 Texture (const WString &filePath)
 create a new image using a path to a file (only support official file format) More...
 
 Texture (std::fstream *fileStream)
 create a new Texture using a file stream to read. More...
 
 Texture (const Texture< T > &image)
 copy constructor More...
 
 Texture (const T *dataBuffer, const Math::Vec2< Size > &size, typename LoadingFormat loadingFormat=LoadingFormat::RGB, bool invertY=false)
 create a Texture from a image data More...
 
 Texture (Texture< T > &&image)
 move constructor More...
 
 ~Texture ()
 
const Math::Vec2< Size > & getSize (typename Vector< _Image< T >>::Size i=0) const
 get the actual size (width:height) of the image More...
 
unsigned int getWidth (typename Vector< _Image< T >>::Size i=0) const
 get the actual width of the image More...
 
unsigned int getHeight (typename Vector< _Image< T >>::Size i=0) const
 get the actual height of the image More...
 
void setDatas (const T *data, const Math::Vec2< Size > &size, typename LoadingFormat loadingFormat=LoadingFormat::RGB, bool invertY=false)
 set the data from an another data buffer. More...
 
void clear (const Math::Vec2< Size > &size)
 reset this image with a new size. More...
 
void clear (const Math::Vec2< Size > &size, typename Format format)
 reset this image with a new size and a new format More...
 
_Image< T > * getMipmap (typename Vector< _Image< T >>::Size i=0)
 get a mipmap from this texture More...
 
_Image< T > * operator[] (typename Vector< _Image< T >>::Size i)
 get a mipmap from this texture More...
 
void generateMipmaps ()
 generate the mipmap from the actual lod 0 More...
 
const T * getDatas (typename Vector< _Image< T >>::Size i=0) const
 get the data buffer of this image More...
 
T * getDatas (typename Vector< _Image< T >>::Size i=0)
 get the data buffer of this image More...
 
const T * getPixel (typename Vector< _Image< T >>::Size i, unsigned int x, unsigned int y) const
 get a pixel from this texture More...
 
void setPixel (typename Vector< _Image< T >>::Size i, unsigned int x, unsigned int y, const T *p)
 set a pixel inside this image More...
 
Texture< T > & operator= (const Texture< T > &image)
 copy operator More...
 
Texture< T > & operator= (Texture< T > &&image)
 move operator More...
 
bool read (std::fstream *fileStream)
 read from a file stream More...
 
bool write (std::fstream *fileStream) const
 write this object as binary into a file stream More...
 
Format getFormat () const
 get the format of this image More...
 
Vector< _Image< T > * >::Size getNumMipmaps () const
 get the number of mipmap of this texture More...
 

Protected Member Functions

virtual bool onRead (std::fstream *fileStream) override
 function to be overloaded to set the action when reading from a stream. More...
 
virtual bool onWrite (std::fstream *fileStream) const override
 function to be overloaded to set the action when writing from a stream. More...
 
virtual void onLoad () override
 function to be overloaded to add action during the loading process. More...
 
virtual void onUnload () override
 function to be overloaded to add action during the unloading process. More...
 
- Protected Member Functions inherited from BasicLoadable
void setLoaded (bool loaded)
 set if the current object is loaded or not. (use with caution) More...
 
void setLoading (bool isLoading)
 set if the current object is currently loading (use with caution) More...
 
- Protected Member Functions inherited from Graphic::Texture< T >
 Texture (ctor)
 
bool _read (std::fstream *fileStream)
 
void _unload ()
 

Additional Inherited Members

- Protected Types inherited from Graphic::Texture< T >
enum  ctor { null }
 
- Protected Attributes inherited from Graphic::Texture< T >
Vector< _Image< T > * > datas
 

Member Enumeration Documentation

template<typename T = unsigned char>
enum Graphic::TextureLoadable::LoadingType
Enumerator
EMPTY 
FILE 

When loaded the buffer is NOT initialized.

When loaded the file is opened and read.

Constructor & Destructor Documentation

template<typename T >
Graphic::TextureLoadable< T >::TextureLoadable ( typename Format  format = Format::RGB)

Empty constructor, create an image unallocated of size (0:0)

Parameters
formatof the image
template<typename T >
Graphic::TextureLoadable< T >::TextureLoadable ( const Math::Vec2< Size > &  size,
typename Format  format = Format::RGB 
)

Constructor to create an not initialized image of specified size.

Parameters
sizesize of the image to create.
formatof the image
template<typename T >
Graphic::TextureLoadable< T >::TextureLoadable ( const WString filePath)

create a new image using a path to a file (only support official file format)

template<typename T >
Graphic::TextureLoadable< T >::TextureLoadable ( const TextureLoadable< T > &  image)

copy constructor

template<typename T >
Graphic::TextureLoadable< T >::TextureLoadable ( TextureLoadable< T > &&  image)

move constructor

template<typename T >
Graphic::TextureLoadable< T >::~TextureLoadable ( )

Member Function Documentation

template<typename T >
void Graphic::TextureLoadable< T >::clear ( const Math::Vec2< Size > &  size)

clear this texture with a new size

Parameters
sizeNew size from the mipmap 0
template<typename T >
void Graphic::TextureLoadable< T >::clear ( const Math::Vec2< Size > &  size,
typename Format  format 
)

reset this image with a new size and a new format

Parameters
sizenew size
formatnew format of the image
template<typename T >
void Graphic::TextureLoadable< T >::generateMipmaps ( )

generate the mipmaps from the actual lod 0

template<typename T >
const T * Graphic::TextureLoadable< T >::getDatas ( typename Vector< _Image< T >>::Size  i = 0) const

get the data buffer of this image

Parameters
inumber of mipmap (0 = original image)
Returns
data buffer
template<typename T >
T * Graphic::TextureLoadable< T >::getDatas ( typename Vector< _Image< T >>::Size  i = 0)

get the data buffer of this image

Parameters
inumber of mipmap (0 = original image)
Returns
data buffer
template<typename T >
Format Graphic::TextureLoadable< T >::getFormat ( ) const

get the format of this image

Returns
format of this image (its castable in unsigned char to retrieve the number of components)
template<typename T >
const T * Graphic::TextureLoadable< T >::getPixel ( typename Vector< _Image< T >>::Size  i,
unsigned int  x,
unsigned int  y 
) const

get a pixel from this image

Parameters
imipmap level
xx coordinate of the pixel
yy coordinate of the pixel
Returns
the pixel from the picture at the specified 2D coordinate.
template<typename T >
void Graphic::TextureLoadable< T >::onLoad ( )
overrideprotectedvirtual

function to be overloaded to add action during the loading process.

Reimplemented from BasicLoadable.

template<typename T >
bool Graphic::TextureLoadable< T >::onRead ( std::fstream *  fileStream)
overrideprotectedvirtual

function to be overloaded to set the action when reading from a stream.

Parameters
fileStreamstream used to read load this object
Returns
boolean to know if the operation is a success of not.

Reimplemented from BasicSimpleLoadableIO.

template<typename T >
void Graphic::TextureLoadable< T >::onUnload ( )
overrideprotectedvirtual

function to be overloaded to add action during the unloading process.

Reimplemented from BasicLoadable.

template<typename T >
bool Graphic::TextureLoadable< T >::onWrite ( std::fstream *  fileStream) const
overrideprotectedvirtual

function to be overloaded to set the action when writing from a stream.

Parameters
fileStreamstream used to write this object
Returns
boolean to know if the operation is a success of not.

Reimplemented from BasicSimpleLoadableIO.

template<typename T >
Texture< T > & Graphic::TextureLoadable< T >::operator= ( const Texture< T > &  image)

copy operator

Parameters
imageImage to copy
template<typename T >
Texture< T > & Graphic::TextureLoadable< T >::operator= ( Texture< T > &&  image)

move operator

Parameters
imageImage to move from
template<typename T >
void Graphic::TextureLoadable< T >::setDatas ( const T *  dataBuffer,
const Math::Vec2< Size > &  size,
typename LoadingFormat  loadingFormat = LoadingFormat::RGB,
bool  invertY = false 
)

load this image from a buffer and a specified size.

Parameters
dataBufferbuffer to copy inside the new image (the buffer has to have a size of at least size.x * size.y)
sizesize of the new image
formatof the image
invertYif the image has to be flipped vertically or not.
template<typename T >
void Graphic::TextureLoadable< T >::setPixel ( typename Vector< _Image< T >>::Size  i,
unsigned int  x,
unsigned int  y,
const T *  p 
)

set a pixel inside this image

Parameters
imipmap level
xx coordinate of the pixel
yy coordinate of the pixel
pThe pixel to set.

The documentation for this class was generated from the following files: