lxgui
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
lxgui::gui::sfml::material Class Referencefinal

A class that holds rendering data This implementation can contain either a plain color or a real sf::Texture. It is also used by the gui::sfml::render_target class to store the output data. More...

#include <gui_sfml_material.hpp>

Inheritance diagram for lxgui::gui::sfml::material:
lxgui::gui::material

Public Types

enum class  wrap { repeat , clamp }
 
enum class  filter { none , linear }
 

Public Member Functions

 material (const vector2ui &dimensions, bool is_render_target, wrap wrp=wrap::repeat, filter filt=filter::none)
 Constructor for textures. More...
 
 material (const sf::Image &data, wrap wrp=wrap::repeat, filter filt=filter::none)
 Constructor for textures. More...
 
 material (const std::string &file_name, wrap wrp=wrap::repeat, filter filt=filter::none)
 Constructor for textures. More...
 
 material (const sf::Texture &texture, const bounds2f &location, filter filt=filter::none)
 Constructor for atlas textures. More...
 
 material (const material &tex)=delete
 
 material (material &&tex)=delete
 
materialoperator= (const material &tex)=delete
 
materialoperator= (material &&tex)=delete
 
bounds2f get_rect () const override
 Returns the pixel rect in pixels of the canvas containing this texture (if any). More...
 
vector2ui get_canvas_dimensions () const override
 Returns the physical dimensions (in pixels) of the canvas containing this texture (if any). More...
 
bool uses_same_texture (const gui::material &other) const override
 Checks if another material is based on the same texture as the current material. More...
 
bool set_dimensions (const vector2ui &dimensions)
 Resizes this texture. More...
 
void set_wrap (wrap wrp)
 Sets the wrap mode of this texture. More...
 
void set_filter (filter filt)
 Sets the filter mode of this texture. More...
 
filter get_filter () const
 Returns the filter mode of this texture. More...
 
void update_texture (const color32 *data)
 Updates the texture that is in GPU memory. More...
 
sf::RenderTexture * get_render_texture ()
 Returns the underlying SFML render texture object. return The underlying SFML render texture object. More...
 
const sf::Texture * get_texture () const
 Returns the underlying SFML texture object. return The underlying SFML texture object. More...
 
vector2f get_canvas_uv (const vector2f &texture_uv, bool from_normalized) const
 Returns normalized UV coordinates on the canvas, given local UV coordinates. More...
 
vector2f get_local_uv (const vector2f &canvas_uv, bool as_normalized) const
 Returns local UV coordinates on the texture, given canvas UV coordinates. More...
 
bool is_in_atlas () const
 Checks if the material is embedded in an atlas. More...
 

Static Public Member Functions

static void premultiply_alpha (sf::Image &data)
 Premultiplies an image by its alpha component. More...
 

Protected Attributes

bool is_atlas_ = false
 

Detailed Description

A class that holds rendering data This implementation can contain either a plain color or a real sf::Texture. It is also used by the gui::sfml::render_target class to store the output data.

Definition at line 23 of file gui_sfml_material.hpp.

Member Enumeration Documentation

◆ filter

enum lxgui::gui::material::filter
stronginherited
Enumerator
none 
linear 

Definition at line 20 of file gui_material.hpp.

◆ wrap

enum lxgui::gui::material::wrap
stronginherited
Enumerator
repeat 
clamp 

Definition at line 18 of file gui_material.hpp.

Constructor & Destructor Documentation

◆ material() [1/6]

lxgui::gui::sfml::material::material ( const vector2ui dimensions,
bool  is_render_target,
wrap  wrp = wrap::repeat,
filter  filt = filter::none 
)

Constructor for textures.

Parameters
dimensionsThe requested texture dimensions
is_render_targetCreate the material for a render target or only for display
wrpHow to adjust texture coordinates that are outside the [0,1] range
filtUse texture filtering or not (see set_filter())

◆ material() [2/6]

lxgui::gui::sfml::material::material ( const sf::Image &  data,
wrap  wrp = wrap::repeat,
filter  filt = filter::none 
)
explicit

Constructor for textures.

Parameters
dataThe image data to use as texture
wrpHow to adjust texture coordinates that are outside the [0,1] range
filtUse texture filtering or not (see set_filter())

◆ material() [3/6]

lxgui::gui::sfml::material::material ( const std::string &  file_name,
wrap  wrp = wrap::repeat,
filter  filt = filter::none 
)
explicit

Constructor for textures.

Parameters
file_nameThe file from which the texture data is loaded
wrpHow to adjust texture coordinates that are outside the [0,1] range
filtUse texture filtering or not (see set_filter())

◆ material() [4/6]

lxgui::gui::sfml::material::material ( const sf::Texture &  texture,
const bounds2f location,
filter  filt = filter::none 
)
explicit

Constructor for atlas textures.

Parameters
textureThe atlas texture holding this material's texture
locationThe location of the texture inside the atlas texture (in pixels)
filtUse texture filtering or not (see set_filter())

◆ material() [5/6]

lxgui::gui::sfml::material::material ( const material tex)
delete

◆ material() [6/6]

lxgui::gui::sfml::material::material ( material &&  tex)
delete

Member Function Documentation

◆ get_canvas_dimensions()

vector2ui lxgui::gui::sfml::material::get_canvas_dimensions ( ) const
overridevirtual

Returns the physical dimensions (in pixels) of the canvas containing this texture (if any).

Returns
The physical dimensions (in pixels) of the canvas containing this (if any)
Note
When a texture is loaded, most of the time it will fill the entire "canvas", namely, the 2D pixel array containing the texture data. However, some old hardware don't support textures that have non power-of-two dimensions. If the user creates a material for such a texture, the gui::renderer will create a bigger canvas that has power-of-two dimensions, and store the texture in it. Likewise, if a texture is placed in a wider texture atlas, the canvas will contain more than one texture.

Implements lxgui::gui::material.

◆ get_canvas_uv()

vector2f lxgui::gui::material::get_canvas_uv ( const vector2f texture_uv,
bool  from_normalized 
) const
inherited

Returns normalized UV coordinates on the canvas, given local UV coordinates.

Parameters
texture_uvThe original UV coordinates, local to this texture
from_normalizedSet to 'true' if input coordinates are normalized
Note
Normalized coordinates range from 0 to 1, with 1 corresponding to the width/height of the texture, while non-normalized coordinates are in pixels.

Definition at line 7 of file gui_material.cpp.

◆ get_filter()

filter lxgui::gui::sfml::material::get_filter ( ) const

Returns the filter mode of this texture.

Returns
The filter mode of this texture

◆ get_local_uv()

vector2f lxgui::gui::material::get_local_uv ( const vector2f canvas_uv,
bool  as_normalized 
) const
inherited

Returns local UV coordinates on the texture, given canvas UV coordinates.

Parameters
canvas_uvThe canvas UV coordinates
as_normalizedSet to 'true' if output coordinates should be normalized
Note
Normalized coordinates range from 0 to 1, with 1 corresponding to the width/height of the texture, while non-normalized coordinates are in pixels.

Definition at line 20 of file gui_material.cpp.

◆ get_rect()

bounds2f lxgui::gui::sfml::material::get_rect ( ) const
overridevirtual

Returns the pixel rect in pixels of the canvas containing this texture (if any).

Returns
The pixel rect in pixels of the canvas containing this texture (if any)

Implements lxgui::gui::material.

◆ get_render_texture()

sf::RenderTexture* lxgui::gui::sfml::material::get_render_texture ( )

Returns the underlying SFML render texture object. return The underlying SFML render texture object.

◆ get_texture()

const sf::Texture* lxgui::gui::sfml::material::get_texture ( ) const

Returns the underlying SFML texture object. return The underlying SFML texture object.

◆ is_in_atlas()

bool lxgui::gui::material::is_in_atlas ( ) const
inherited

Checks if the material is embedded in an atlas.

Returns
'true' if the material is inside an atlas, 'false' otherwise.

Definition at line 33 of file gui_material.cpp.

◆ operator=() [1/2]

material& lxgui::gui::sfml::material::operator= ( const material tex)
delete

◆ operator=() [2/2]

material& lxgui::gui::sfml::material::operator= ( material &&  tex)
delete

◆ premultiply_alpha()

static void lxgui::gui::sfml::material::premultiply_alpha ( sf::Image &  data)
static

Premultiplies an image by its alpha component.

Note
Premultiplied alpha is a rendering technique that allows perfect alpha blending when using render targets.

◆ set_dimensions()

bool lxgui::gui::sfml::material::set_dimensions ( const vector2ui dimensions)

Resizes this texture.

Parameters
dimensionsThe new texture dimensions
Returns
'true' if the function had to re-create a new texture object
Note
All the previous data that was stored in this texture will be lost.

◆ set_filter()

void lxgui::gui::sfml::material::set_filter ( filter  filt)

Sets the filter mode of this texture.

Parameters
filtUse texture filtering or not
Note
When texture filtering is disabled, enlarged textures get pixelated. Else, the GPU uses an averaging algorithm to blur the pixels.

◆ set_wrap()

void lxgui::gui::sfml::material::set_wrap ( wrap  wrp)

Sets the wrap mode of this texture.

Parameters
wrpHow to adjust texture coordinates that are outside the [0,1] range

◆ update_texture()

void lxgui::gui::sfml::material::update_texture ( const color32 data)

Updates the texture that is in GPU memory.

Parameters
dataThe new pixel data

◆ uses_same_texture()

bool lxgui::gui::sfml::material::uses_same_texture ( const gui::material other) const
overridevirtual

Checks if another material is based on the same texture as the current material.

Returns
'true' if both materials use the same texture, 'false' otherwise

Implements lxgui::gui::material.

Member Data Documentation

◆ is_atlas_

bool lxgui::gui::material::is_atlas_ = false
protectedinherited

Definition at line 93 of file gui_material.hpp.


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