Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
|
Stores all data describing an image. More...
#include <tex.h>
Classes | |
struct | MIPLevel |
Public Member Functions | |
~Tex () | |
Status | validate () const |
Is the texture object valid and self-consistent? More... | |
void | free () |
free all resources associated with the image and make further use of it impossible. More... | |
Status | decode (const std::shared_ptr< u8 > &data, size_t data_size) |
decode an in-memory texture file into texture object. More... | |
Status | encode (const OsPath &extension, DynArray *da) |
encode a texture into a memory buffer in the desired file format. More... | |
Status | wrap (size_t w, size_t h, size_t bpp, size_t flags, const std::shared_ptr< u8 > &data, size_t ofs) |
store the given image data into a Tex object; this will be as if it had been loaded via tex_load. More... | |
Status | transform (size_t transforms) |
Change the pixel format. More... | |
Status | transform_to (size_t new_flags) |
Change the pixel format (2nd version) (note: this is equivalent to Tex::transform(t, t->flags^new_flags). More... | |
u8 * | get_data () |
return a pointer to the image data (pixels), taking into account any header(s) that may come before it. More... | |
const std::vector< MIPLevel > & | GetMIPLevels () const |
u32 | get_average_color () const |
return the ARGB value of the 1x1 mipmap level of the texture. More... | |
size_t | img_size () const |
return total byte size of the image pixels. More... | |
Public Attributes | |
std::shared_ptr< u8 > | m_Data |
file buffer or image data. More... | |
size_t | m_DataSize |
size_t | m_Ofs |
offset to image data in file. More... | |
size_t | m_Width |
size_t | m_Height |
size_t | m_Bpp |
size_t | m_Flags |
see TexFlags and "Format Conversion" in docs. More... | |
Private Member Functions | |
void | UpdateMIPLevels () |
Private Attributes | |
std::vector< MIPLevel > | m_MIPLevels |
Stores all data describing an image.
TODO: rename to TextureData.
|
inline |
decode an in-memory texture file into texture object.
FYI, currently BMP, TGA, JPG, JP2, PNG, DDS are supported - but don't rely on this (not all codecs may be included).
data | Input data. |
data_size | Its size [bytes]. |
encode a texture into a memory buffer in the desired file format.
extension | (including '.'). |
da | Output memory array. Allocated here; caller must free it when no longer needed. Invalid unless function succeeds. |
void Tex::free | ( | ) |
free all resources associated with the image and make further use of it impossible.
u32 Tex::get_average_color | ( | ) | const |
return the ARGB value of the 1x1 mipmap level of the texture.
u8 * Tex::get_data | ( | ) |
return a pointer to the image data (pixels), taking into account any header(s) that may come before it.
|
inline |
size_t Tex::img_size | ( | ) | const |
return total byte size of the image pixels.
(including mipmaps!) rationale: this is preferable to calculating manually because it's less error-prone (e.g. confusing bits_per_pixel with bytes).
Status Tex::transform | ( | size_t | transforms | ) |
Change the pixel format.
transforms | TexFlags that are to be flipped. |
Status Tex::transform_to | ( | size_t | new_flags | ) |
Change the pixel format (2nd version) (note: this is equivalent to Tex::transform(t, t->flags^new_flags).
new_flags | desired new value of TexFlags. |
|
private |
Status Tex::validate | ( | ) | const |
Is the texture object valid and self-consistent?
Status Tex::wrap | ( | size_t | w, |
size_t | h, | ||
size_t | bpp, | ||
size_t | flags, | ||
const std::shared_ptr< u8 > & | data, | ||
size_t | ofs | ||
) |
store the given image data into a Tex object; this will be as if it had been loaded via tex_load.
rationale: support for in-memory images is necessary for emulation of glCompressedTexImage2D and useful overall. however, we don't want to provide an alternate interface for each API; these would have to be changed whenever fields are added to Tex. instead, provide one entry point for specifying images. note: since we do not know how <img> was allocated, the caller must free it themselves (after calling tex_free, which is required regardless of alloc type).
we need only add bookkeeping information and "wrap" it in our Tex struct, hence the name.
w,h | Pixel dimensions. |
bpp | Bits per pixel. |
flags | TexFlags. |
data | Img texture data. note: size is calculated from other params. |
ofs |
size_t Tex::m_Bpp |
std::shared_ptr<u8> Tex::m_Data |
file buffer or image data.
note: during the course of transforms (which may occur when being loaded), this may be replaced with a new buffer (e.g. if decompressing file contents).
size_t Tex::m_DataSize |
size_t Tex::m_Flags |
see TexFlags and "Format Conversion" in docs.
size_t Tex::m_Height |
|
private |
size_t Tex::m_Ofs |
offset to image data in file.
this is required since tex_get_data needs to return the pixels, but data returns the actual file buffer. zero-copy load and write-back to file is also made possible.
size_t Tex::m_Width |