Pyrogenesis  trunk
Public Member Functions | Public Attributes | List of all members
Tex Struct Reference

stores all data describing an image. More...

#include <tex.h>

Collaboration diagram for Tex:
Collaboration graph
[legend]

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 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 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...
 
u8get_data ()
 return a pointer to the image data (pixels), taking into account any header(s) that may come before it. More...
 
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

shared_ptr< u8m_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...
 

Detailed Description

stores all data describing an image.

we try to minimize size, since this is stored in OglTex resources (which are big and pushing the h_mgr limit).

Constructor & Destructor Documentation

Tex::~Tex ( )
inline

Member Function Documentation

Status Tex::decode ( const shared_ptr< u8 > &  data,
size_t  data_size 
)

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

Parameters
dataInput data.
data_sizeIts size [bytes].
Returns
Status.
Status Tex::encode ( const OsPath extension,
DynArray da 
)

encode a texture into a memory buffer in the desired file format.

Parameters
extension(including '.').
daOutput memory array. Allocated here; caller must free it when no longer needed. Invalid unless function succeeds.
Returns
Status
void Tex::free ( )

free all resources associated with the image and make further use of it impossible.

Returns
Status
u32 Tex::get_average_color ( ) const

return the ARGB value of the 1x1 mipmap level of the texture.

Returns
ARGB value (or 0 if texture does not have mipmaps)
u8 * Tex::get_data ( )

return a pointer to the image data (pixels), taking into account any header(s) that may come before it.

Returns
pointer to data returned by mem_get_ptr (holds reference)!
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).

Returns
size [bytes]
Status Tex::transform ( size_t  transforms)

Change the pixel format.

Parameters
transformsTexFlags that are to be flipped.
Returns
Status
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).

Parameters
new_flagsdesired new value of TexFlags.
Returns
Status
Status Tex::validate ( ) const

Is the texture object valid and self-consistent?

Returns
Status
Status Tex::wrap ( size_t  w,
size_t  h,
size_t  bpp,
size_t  flags,
const 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.

Parameters
w,hPixel dimensions.
bppBits per pixel.
flagsTexFlags.
dataImg texture data. note: size is calculated from other params.
ofs
Returns
Status

Member Data Documentation

size_t Tex::m_Bpp
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
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

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