FPLBase
An open source project by
FPL.
|
Abstraction for a texture object loaded on the GPU. More...
#include <texture.h>
Abstraction for a texture object loaded on the GPU.
Contains functions for loading, marshalling, and disposal of textures.
Public Member Functions | |
Texture (const char *filename=nullptr, TextureFormat format=kFormatAuto, TextureFlags flags=kTextureFlagsUseMipMaps) | |
Constructor for a Texture. | |
virtual | ~Texture () |
Destructor for a Texture. More... | |
virtual void | Load () |
Loads and unpacks the Texture from filename_ into data_ . It also sets the original size, if it has not yet been set. | |
virtual void | LoadFromMemory (const uint8_t *data, const mathfu::vec2i &size, TextureFormat texture_format) |
Create a texture from data in memory. More... | |
virtual bool | Finalize () |
Creates a Texture from data_ and stores the handle in id_ . | |
bool | IsValid () |
Whether this object loaded and finalized correctly. Call after Finalize has been called (by AssetManager::TryFinalize). | |
void | Set (size_t unit, Renderer *renderer) |
Set the active Texture and binds id_ to GL_TEXTURE_2D . More... | |
void | Set (size_t unit) |
void | Set (size_t unit, Renderer *renderer) const |
Set the active Texture and binds id_ to GL_TEXTURE_2D . More... | |
void | Set (size_t unit) const |
void | Delete () |
Delete the Texture stored in id_ , and reset id_ to 0 . | |
void | UpdateTexture (size_t unit, TextureFormat format, int xoffset, int yoffset, int width, int height, const void *data) |
Update (part of) the current texture with new pixel data. For now, must always update at least entire row. More... | |
void | SetTextureId (TextureTarget target, TextureHandle id) |
Set texture target and id directly for textures that have been created outside of this class. The creator is responsible for deleting the texture id. More... | |
const TextureHandle & | id () const |
Get the Texture handle ID. More... | |
const mathfu::vec2i & | size () const |
Get the Texture size. More... | |
const mathfu::vec2 & | scale () const |
Get the Texture scale. More... | |
void | set_scale (const mathfu::vec2 &scale) |
Set the Texture scale. More... | |
TextureFlags | flags () const |
returns the texture flags. | |
const mathfu::vec2i & | original_size () const |
Get the original size of the Texture. More... | |
void | set_original_size (const mathfu::vec2i &size) |
Set the original size of the Texture. More... | |
TextureFormat | format () const |
Get the Texture format. More... | |
void | SetOriginalSizeIfNotYetSet (const mathfu::vec2i &size) |
If the original size has not yet been set, then set it. More... | |
TextureImpl * | impl () |
Public Member Functions inherited from fplbase::AsyncAsset | |
AsyncAsset () | |
Default constructor for an empty AsyncAsset. | |
AsyncAsset (const char *filename) | |
Construct an AsyncAsset with a given file name. More... | |
virtual | ~AsyncAsset () |
AsyncAsset destructor. | |
bool | LoadNow () |
Performs a synchronous load by calling Load & Finalize. More... | |
void | set_filename (const std::string &filename) |
Sets the filename that should be loaded. More... | |
const std::string & | filename () const |
The name of the file associated with the resource. More... | |
void | AddFinalizeCallback (AssetFinalizedCallback callback) |
Adds a callback to be called when the asset is finalized. More... | |
Public Member Functions inherited from fplbase::Asset | |
void | IncreaseRefCount () |
indicate there is an additional owner of this asset. By default, when you call any of the UnLoad*() functions in the AssetManager, that will directly delete the asset since they all start out with a single reference count. Call this function to indicate multiple owners will call Unload*() independently, and only have the asset deleted by the last one. | |
Static Public Member Functions | |
static uint8_t * | UnpackTGA (const void *tga_buf, TextureFlags flags, mathfu::vec2i *dimensions, TextureFormat *texture_format) |
Unpacks a memory buffer containing a TGA format file. More... | |
static uint8_t * | UnpackWebP (const void *webp_buf, size_t size, const mathfu::vec2 &scale, TextureFlags flags, mathfu::vec2i *dimensions, TextureFormat *texture_format) |
Unpacks a memory buffer containing a Webp format file. More... | |
static uint8_t * | UnpackASTC (const void *astc_buf, size_t size, TextureFlags flags, mathfu::vec2i *dimensions, TextureFormat *texture_format) |
Reads a memory buffer containing an ASTC format (.astc) file. More... | |
static uint8_t * | UnpackPKM (const void *file_buf, size_t size, TextureFlags flags, mathfu::vec2i *dimensions, TextureFormat *texture_format) |
Reads a memory buffer containing an ETC2 format (.pkm) file. More... | |
static uint8_t * | UnpackKTX (const void *file_buf, size_t size, TextureFlags flags, mathfu::vec2i *dimensions, TextureFormat *texture_format) |
Reads a memory buffer containing an KTX format (.ktx) file. More... | |
static uint8_t * | UnpackPng (const void *png_buf, size_t size, const mathfu::vec2 &scale, TextureFlags flags, mathfu::vec2i *dimensions, TextureFormat *texture_format) |
Unpacks a memory buffer containing a Png format file. More... | |
static uint8_t * | UnpackJpg (const void *jpg_buf, size_t size, const mathfu::vec2 &scale, TextureFlags flags, mathfu::vec2i *dimensions, TextureFormat *texture_format) |
Unpacks a memory buffer containing a Jpeg format file. More... | |
static uint8_t * | LoadAndUnpackTexture (const char *filename, const mathfu::vec2 &scale, TextureFlags flags, mathfu::vec2i *dimensions, TextureFormat *texture_format) |
Loads the file in filename, and then unpacks the file format (supports TGA, WebP, KTX, PKM, ASTC). More... | |
static uint16_t * | Convert8888To5551 (const uint8_t *buffer, const mathfu::vec2i &size) |
Utility function to convert 32bit RGBA (8-bits each) to 16bit RGB in hex 5551 format. More... | |
static uint16_t * | Convert888To565 (const uint8_t *buffer, const mathfu::vec2i &size) |
Utility function to convert 24bit RGB (8-bits each) to 16bit RGB in hex 565 format. More... | |
Additional Inherited Members | |
Public Types inherited from fplbase::AsyncAsset | |
typedef std::function< void()> | AssetFinalizedCallback |
A function pointer to an asset loaded callback function. | |
Protected Member Functions inherited from fplbase::AsyncAsset | |
void | CallFinalizeCallback () |
Calls app callbacks when an asset is ready to be used. More... | |
Protected Attributes inherited from fplbase::AsyncAsset | |
std::string | filename_ |
The resource file name. | |
const uint8_t * | data_ |
The resource data. | |
std::vector < AssetFinalizedCallback > | finalize_callbacks_ |
|
static |
Utility function to convert 32bit RGBA (8-bits each) to 16bit RGB in hex 5551 format.
delete[]
the return value afterwards.
|
static |
Utility function to convert 24bit RGB (8-bits each) to 16bit RGB in hex 565 format.
delete[]
the return value afterwards.
|
inline |
Get the Texture format.
|
inline |
Get the Texture handle ID.
|
static |
Loads the file in filename, and then unpacks the file format (supports TGA, WebP, KTX, PKM, ASTC).
last_error()
contains more information if nullptr
is returned. You must free()
the returned pointer when done. [in] | filename | A C-string corresponding to the name of the file containing the Texture. |
[in] | scale | A scale value must be a power of two to have correct Texture sizes. |
[in] | flags | Texture flag, allowing premultiply (only webp now) |
[out] | dimensions | A mathfu::vec2i pointer the captures the Texture width and height. |
[out] | texture_format | The format of the returned buffer, always either 888 or 8888. |
nullptr
, if the format is not understood. free()
on the returned pointer when done.
|
virtual |
|
inline |
|
inline |
void fplbase::Texture::Set | ( | size_t | unit, |
Renderer * | renderer | ||
) |
void fplbase::Texture::Set | ( | size_t | unit | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void fplbase::Texture::Set | ( | size_t | unit, |
Renderer * | renderer | ||
) | const |
void fplbase::Texture::Set | ( | size_t | unit | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
|
inline |
|
inline |
If the original size has not yet been set, then set it.
[in] | size | A mathfu::vec2i containing the original Texture x and y sizes. |
void fplbase::Texture::SetTextureId | ( | TextureTarget | target, |
TextureHandle | id | ||
) |
|
inline |
|
static |
Reads a memory buffer containing an ASTC format (.astc) file.
[in] | astc_buf | The ASTC image data. |
[in] | size | The size of the memory block pointed to by astc_buf . |
[in] | flags | Texture flag, allowing premultiply (only webp now) |
[out] | dimensions | A mathfu::vec2i pointer the captures the image width and height. |
[out] | texture_format | The format of the returned buffer, always kFormatASTC. |
nullptr
, if the format is not understood. free()
on the returned pointer when done.
|
inlinestatic |
Unpacks a memory buffer containing a Jpeg format file.
[in] | jpg_buf | The Jpeg image data. |
[in] | size | The size of the memory block pointed to by data . |
[in] | scale | A scale value must be a power of two to have correct Texture sizes. |
[in] | flags | Texture flag, allowing premultiply (only webp now) |
[out] | dimensions | A mathfu::vec2i pointer the captures the image width and height. |
[out] | texture_format | Pixel format of unpacked image. |
nullptr
, if the format is not understood. free()
on the returned pointer when done.
|
static |
Reads a memory buffer containing an KTX format (.ktx) file.
[in] | file_buf | the loaded file. |
[in] | size | The size of the memory block pointed to by file_buf . |
[in] | flags | Texture flag, allowing premultiply (only webp now) |
[out] | dimensions | A mathfu::vec2i pointer the captures the image width and height. |
[out] | texture_format | The format of the returned buffer, always kFormatETC2. |
nullptr
, if the format is not understood. free()
on the returned pointer when done.
|
static |
Reads a memory buffer containing an ETC2 format (.pkm) file.
[in] | file_buf | the loaded file. |
[in] | size | The size of the memory block pointed to by file_buf . |
[in] | flags | Texture flag, allowing premultiply (only webp now) |
[out] | dimensions | A mathfu::vec2i pointer the captures the image width and height. |
[out] | texture_format | The format of the returned buffer, always kFormatETC2. |
nullptr
, if the format is not understood. free()
on the returned pointer when done.
|
inlinestatic |
Unpacks a memory buffer containing a Png format file.
[in] | png_buf | The Png image data. |
[in] | size | The size of the memory block pointed to by data . |
[in] | scale | A scale value must be a power of two to have correct Texture sizes. |
[in] | flags | Texture flag, allowing premultiply (only webp now) |
[out] | dimensions | A mathfu::vec2i pointer the captures the image width and height. |
[out] | texture_format | Pixel format of unpacked image. |
nullptr
, if the format is not understood. free()
on the returned pointer when done.
|
static |
Unpacks a memory buffer containing a TGA format file.
[in] | tga_buf | The TGA image data. |
[in] | flags | Texture flag, allowing premultiply (only webp now) |
[out] | dimensions | A mathfu::vec2i pointer the captures the TGA width and height. |
[out] | texture_format | The format of the returned buffer, always either 888 or 8888. |
nullptr
if the format is not understood. free()
the returned pointer when done.
|
static |
Unpacks a memory buffer containing a Webp format file.
[in] | webp_buf | The WebP image data. |
[in] | size | The size of the memory block pointed to by webp_buf . |
[in] | scale | A scale value must be a power of two to have correct Texture sizes. |
[in] | flags | Texture flag, allowing premultiply |
[out] | dimensions | A mathfu::vec2i pointer the captures the image width and height. |
[out] | texture_format | The format of the returned buffer, always either 888 or 8888. |
nullptr
, if the format is not understood. free()
on the returned pointer when done. void fplbase::Texture::UpdateTexture | ( | size_t | unit, |
TextureFormat | format, | ||
int | xoffset, | ||
int | yoffset, | ||
int | width, | ||
int | height, | ||
const void * | data | ||
) |
Update (part of) the current texture with new pixel data. For now, must always update at least entire row.
[in] | unit | Specifies which texture unit to do the update with. |
[in] | texture_format | The format of data . |
[in] | xoffset | Lowest x-pixel coordinate to update. |
[in] | yoffset | Lowest y-pixel coordinate to update. |
[in] | width | Number of pixels along x-axis to update. |
[in] | hegiht | Number of pixels along y-axis to update. |
[in] | data | The Texture data in memory to load from. |