Simulant  21.12-574
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
smlt::Texture Class Reference
Inheritance diagram for smlt::Texture:
smlt::Asset smlt::Loadable smlt::generic::Identifiable< TextureID > smlt::RefCounted< Texture > smlt::Updateable smlt::RenderTarget smlt::ChainNameable< Texture > smlt::Nameable smlt::TwoPhaseConstructed smlt::Nameable

Classes

struct  BuiltIns
 

Public Types

typedef std::shared_ptr< Textureptr
 
typedef std::vector< uint8_t > Data
 
typedef std::function< void(uint8_t *, uint16_t, uint16_t, TextureFormat)> MutationFunc
 
- Public Types inherited from smlt::generic::Identifiable< TextureID >
typedef TextureID id_type
 
- Public Types inherited from smlt::RefCounted< Texture >
typedef std::shared_ptr< Textureptr
 
typedef std::weak_ptr< Texturewptr
 

Public Member Functions

 Texture (TextureID id, AssetManager *asset_manager, uint16_t width, uint16_t height, TextureFormat format=TEXTURE_FORMAT_RGBA_4UB_8888)
 
TextureFormat format () const
 
void set_format (TextureFormat format)
 
bool is_paletted_format () const
 
uint32_t palette_size () const
 
bool update_palette (const uint8_t *palette)
 
bool blur (BlurType blur_type, std::size_t radius)
 
smlt::optional< Pixelpixel (std::size_t x, std::size_t y)
 
bool convert (TextureFormat new_format, const TextureChannelSet &channels=Texture::DEFAULT_SOURCE_CHANNELS)
 
void resize (uint16_t width, uint16_t height, uint32_t data_size)
 
void resize (uint16_t width, uint16_t height)
 
void flip_vertically ()
 
void set_source (const smlt::Path &source)
 
void set_texture_filter (TextureFilter filter)
 
void set_free_data_mode (TextureFreeData mode)
 
void set_texture_wrap (TextureWrap wrap_u, TextureWrap wrap_v, TextureWrap wrap_w)
 
void set_texture_wrap_u (TextureWrap wrap_u)
 
void set_texture_wrap_v (TextureWrap wrap_v)
 
void set_texture_wrap_w (TextureWrap wrap_w)
 
void set_auto_upload (bool v=true)
 
void set_mipmap_generation (MipmapGenerate type)
 
std::vector< uint8_t > data_copy () const
 
const uint8_t * data () const
 
uint32_t data_size () const
 
void set_data (const uint8_t *data, std::size_t size)
 
void set_data (const std::vector< uint8_t > &data)
 
void free ()
 
bool has_data () const
 
void flush ()
 
void mutate_data (MutationFunc func)
 
uint16_t width () const override
 
uint16_t height () const override
 
Vec2 dimensions () const
 
bool is_compressed () const
 
uint8_t channels () const
 
void save_to_file (const Path &filename)
 
Path source () const
 
TextureFilter texture_filter () const
 
TextureWrap wrap_u () const
 
TextureWrap wrap_v () const
 
TextureWrap wrap_w () const
 
MipmapGenerate mipmap_generation () const
 
TextureFreeData free_data_mode () const
 
bool init () override
 
void clean_up () override
 
void update (float dt) override
 
bool has_mipmaps () const
 
bool auto_upload () const
 
void _set_renderer_specific_id (const uint32_t id)
 
uint32_t _renderer_specific_id () const
 
void _set_params_clean ()
 
bool _data_dirty () const
 
void _set_data_clean ()
 
bool _params_dirty () const
 
void _set_has_mipmaps (bool v)
 
uint8_t * _stash_paletted_data ()
 
- Public Member Functions inherited from smlt::Asset
 Asset (AssetManager *manager)
 
AssetManagerasset_manager ()
 
const AssetManagerasset_manager () const
 
int age () const
 
void set_garbage_collection_method (GarbageCollectMethod method)
 
- Public Member Functions inherited from smlt::Nameable
void set_name (const std::string &name)
 
const std::string & name () const
 
bool has_name () const
 
- Public Member Functions inherited from smlt::generic::Identifiable< TextureID >
 Identifiable (TextureID id)
 
TextureID id () const
 
virtual bool operator== (const Identifiable< TextureID > &rhs) const
 
virtual bool operator< (const Identifiable< TextureID > &rhs) const
 
void _bind_id_pointer (ResourceTypePtr ptr)
 
void _overwrite_id (TextureID new_id)
 
- Public Member Functions inherited from smlt::Updateable
virtual void _update_thunk (float dt)
 
virtual void _late_update_thunk (float dt)
 
virtual void _fixed_update_thunk (float step)
 
- Public Member Functions inherited from smlt::RenderTarget
virtual void set_clear_every_frame (uint32_t clear_flags=BUFFER_CLEAR_ALL, const smlt::Colour &colour=smlt::Colour::BLACK)
 
virtual uint32_t clear_every_frame_flags () const
 
virtual smlt::Colour clear_every_frame_colour () const
 
- Public Member Functions inherited from smlt::ChainNameable< Texture >
Textureset_name_and_get (const std::string &name)
 

Static Public Member Functions

static std::size_t required_data_size (TextureFormat fmt, uint16_t width, uint16_t height)
 
- Static Public Member Functions inherited from smlt::RefCounted< Texture >
static RefCounted< Texture >::ptr create (Args &&... args)
 
static RefCounted< Texture >::ptr create ()
 

Static Public Attributes

static const TextureChannelSet DEFAULT_SOURCE_CHANNELS
 

Additional Inherited Members

- Public Attributes inherited from smlt::Asset
Property< generic::DataCarrier Asset::* > data = {this, &Asset::data_}
 
- Protected Member Functions inherited from smlt::Asset
 Asset (const Asset &rhs)
 
Assetoperator= (const Asset &rhs)
 
- Protected Member Functions inherited from smlt::RefCounted< Texture >
 RefCounted (Args &&...)
 

Member Function Documentation

◆ _data_dirty()

bool smlt::Texture::_data_dirty ( ) const

INTERNAL: returns true if the data needs re-uploading

◆ _params_dirty()

bool smlt::Texture::_params_dirty ( ) const

INTERNAL: returns true if the filters are dirty

◆ _set_data_clean()

void smlt::Texture::_set_data_clean ( )

INTERNAL: clears the dirty data flag

◆ _set_params_clean()

void smlt::Texture::_set_params_clean ( )

INTERNAL: Clears the params dirty flag

◆ _set_renderer_specific_id()

void smlt::Texture::_set_renderer_specific_id ( const uint32_t  id)

This is for storing the GL (or whatever) texture ID

◆ _stash_paletted_data()

uint8_t * smlt::Texture::_stash_paletted_data ( )

INTERNAL: copy the current data to the paletted data array

◆ channels()

uint8_t smlt::Texture::channels ( ) const

Returns the number of channels that this texture has

◆ convert()

bool smlt::Texture::convert ( TextureFormat  new_format,
const TextureChannelSet &  channels = Texture::DEFAULT_SOURCE_CHANNELS 
)

Convert a texture to a new format and allow manipulating/filling the channels during the conversion

◆ data()

const uint8_t * smlt::Texture::data ( ) const

Returns the current in-ram data. For paletted texture the data will be prefixed with the palette.

◆ data_copy()

std::vector< uint8_t > smlt::Texture::data_copy ( ) const

Return a copy of the internal data array

◆ data_size()

uint32_t smlt::Texture::data_size ( ) const

Returns the size of the currently allocated data buffer, this will be zero if the data only exists in vram. For paletted texture this will be the size of the data plus the size of the palette.

◆ flip_vertically()

void smlt::Texture::flip_vertically ( )

Flip the data buffer vertically. This will have no effect if the data buffer has been wiped after upload

◆ flush()

void smlt::Texture::flush ( )

Flushes texture data / properties to the renderer immediately. This will free ram if the free data mode is set to TEXTURE_FREE_DATA_AFTER_UPLOAD

◆ free()

void smlt::Texture::free ( )

Clear the data buffer

◆ has_data()

bool smlt::Texture::has_data ( ) const

Returns true if the data array isn't empty

◆ has_mipmaps()

bool smlt::Texture::has_mipmaps ( ) const

Returns true if the format contains mipmap data, or mipmaps have been generated during texture upload

◆ init()

bool smlt::Texture::init ( )
overridevirtual

These are overridden to notify the renderer of texture changes

Reimplemented from smlt::TwoPhaseConstructed.

◆ is_compressed()

bool smlt::Texture::is_compressed ( ) const

Returns true if this Texture uses a compressed format

◆ is_paletted_format()

bool smlt::Texture::is_paletted_format ( ) const

Returns true if this is a paletted texture format

◆ mutate_data()

void smlt::Texture::mutate_data ( Texture::MutationFunc  func)

Apply a mutation function to the current texture data

◆ palette_size()

uint32_t smlt::Texture::palette_size ( ) const

Returns the size in bytes of the palette for paletted textures. Returns 0 if the format is not paletted

◆ required_data_size()

std::size_t smlt::Texture::required_data_size ( TextureFormat  fmt,
uint16_t  width,
uint16_t  height 
)
static

The required size that data() should be to hold a texture in this format with these dimensions. For non-compressed formats this is usually the width * height * stride. For compressed formats this can vary, and will include any space for things like codebooks. For paletted textures this will return the size of the index data + plus the size of the palette

◆ resize() [1/2]

void smlt::Texture::resize ( uint16_t  width,
uint16_t  height 
)

Change the width and height, automatically resizing the data buffer depending on the bytes_per_pixel of the texel_type

◆ resize() [2/2]

void smlt::Texture::resize ( uint16_t  width,
uint16_t  height,
uint32_t  data_size 
)

Change the width and height, but manually set the data buffer size, mainly used for compressed textures

◆ save_to_file()

void smlt::Texture::save_to_file ( const Path filename)

Save a texture to the specified file. Will only work for uncompressed Textures

◆ set_auto_upload()

void smlt::Texture::set_auto_upload ( bool  v = true)

If enabled (default) the texture will be uploaded to the GPU by the renderer. You can disable this if you need just a way to load images from disk for other purposes (e.g. heightmaps)

◆ set_free_data_mode()

void smlt::Texture::set_free_data_mode ( TextureFreeData  mode)

If set to TEXTURE_FREE_DATA_AFTER_UPLOAD then the data attribute will be wiped after the renderer has uploaded to the GPU.

◆ set_texture_filter()

void smlt::Texture::set_texture_filter ( TextureFilter  filter)

Texture filtering and wrapping

◆ set_texture_wrap()

void smlt::Texture::set_texture_wrap ( TextureWrap  wrap_u,
TextureWrap  wrap_v,
TextureWrap  wrap_w 
)

Set the texture wrap modes, either together or per-dimension

◆ update_palette()

bool smlt::Texture::update_palette ( const uint8_t *  palette)

Changes the current palette. The palette must be sizes correctly based on the format. This will return false if a previous palette and data has not been supplied through set_data() etc.

NOT YET IMPLEMENTED! PATCHES WELCOME!

Member Data Documentation

◆ DEFAULT_SOURCE_CHANNELS

const TextureChannelSet smlt::Texture::DEFAULT_SOURCE_CHANNELS
static
Initial value:
= {{
TEXTURE_CHANNEL_RED,
TEXTURE_CHANNEL_GREEN,
TEXTURE_CHANNEL_BLUE,
TEXTURE_CHANNEL_ALPHA
}}

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