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

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

#include <gui_sdl_material.hpp>

Inheritance diagram for lxgui::gui::sdl::material:
lxgui::gui::material

Public Types

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

Public Member Functions

 material (SDL_Renderer *rdr, const vector2ui &dimensions, bool is_render_target=false, wrap wrp=wrap::repeat, filter filt=filter::none)
 Constructor for textures. More...
 
 material (SDL_Renderer *rdr, const std::string &file_name, bool is_pre_multiplied_alpha_supported, wrap wrp=wrap::repeat, filter filt=filter::none)
 Constructor for textures. More...
 
 material (SDL_Renderer *rdr, SDL_Texture *tex, const bounds2f &rect, 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
 
 ~material () noexcept override
 Destructor. More...
 
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...
 
wrap get_wrap () const
 Return the wrap mode of this texture. More...
 
SDL_Texture * get_texture () const
 Returns the underlying SDL texture object. return The underlying SDL texture object. More...
 
SDL_Texture * get_render_texture ()
 Returns the underlying SDL texture object (for render target). return The underlying SDL texture object (for render target) More...
 
SDL_Renderer * get_renderer ()
 Returns the SDL renderer object that this material was created on. return The SDL renderer object that this material was created on. More...
 
color32lock_pointer (std::size_t *pitch=nullptr)
 Returns a pointer to the texture data, which can be modified. More...
 
const color32lock_pointer (std::size_t *pitch=nullptr) const
 Returns a pointer to the texture data, which can be modified. More...
 
void unlock_pointer () const
 Stops modifying the texture data and update the texture in GPU memory. 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 (SDL_Surface *data)
 Premultiplies an image by its alpha component. More...
 
static int get_premultiplied_alpha_blend_mode ()
 Returns the SDL blend mode corresponding to pre-multiplied alpha. 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 SDL_Texture. It is also used by the gui::sdl::render_target class to store the output data.

Definition at line 24 of file gui_sdl_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/5]

lxgui::gui::sdl::material::material ( SDL_Renderer *  rdr,
const vector2ui dimensions,
bool  is_render_target = false,
wrap  wrp = wrap::repeat,
filter  filt = filter::none 
)

Constructor for textures.

Parameters
rdrThe SDL render to create the material for
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/5]

lxgui::gui::sdl::material::material ( SDL_Renderer *  rdr,
const std::string &  file_name,
bool  is_pre_multiplied_alpha_supported,
wrap  wrp = wrap::repeat,
filter  filt = filter::none 
)

Constructor for textures.

Parameters
rdrThe SDL render to create the material for
file_nameThe file from which the texture data is loaded
is_pre_multiplied_alpha_supported'true' if the renderer supports pre-multipled alpha
wrpHow to adjust texture coordinates that are outside the [0,1] range
filtUse texture filtering or not (see set_filter())

◆ material() [3/5]

lxgui::gui::sdl::material::material ( SDL_Renderer *  rdr,
SDL_Texture *  tex,
const bounds2f rect,
filter  filt = filter::none 
)

Constructor for atlas textures.

Parameters
rdrThe SDL render to create the material for
texThe texture object of the atlas
rectThe position of this texture inside the atlas
filtUse texture filtering or not (see set_filter())

◆ material() [4/5]

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

◆ material() [5/5]

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

◆ ~material()

lxgui::gui::sdl::material::~material ( )
overridevirtualnoexcept

Destructor.

Reimplemented from lxgui::gui::material.

Member Function Documentation

◆ get_canvas_dimensions()

vector2ui lxgui::gui::sdl::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::sdl::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_premultiplied_alpha_blend_mode()

static int lxgui::gui::sdl::material::get_premultiplied_alpha_blend_mode ( )
static

Returns the SDL blend mode corresponding to pre-multiplied alpha.

Returns
the SDL blend mode corresponding to pre-multiplied alpha

◆ get_rect()

bounds2f lxgui::gui::sdl::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()

SDL_Texture* lxgui::gui::sdl::material::get_render_texture ( )

Returns the underlying SDL texture object (for render target). return The underlying SDL texture object (for render target)

◆ get_renderer()

SDL_Renderer* lxgui::gui::sdl::material::get_renderer ( )

Returns the SDL renderer object that this material was created on. return The SDL renderer object that this material was created on.

◆ get_texture()

SDL_Texture* lxgui::gui::sdl::material::get_texture ( ) const

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

◆ get_wrap()

wrap lxgui::gui::sdl::material::get_wrap ( ) const

Return the wrap mode of this texture.

Returns
The wrap mode of this texture

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

◆ lock_pointer() [1/2]

color32* lxgui::gui::sdl::material::lock_pointer ( std::size_t *  pitch = nullptr)

Returns a pointer to the texture data, which can be modified.

Parameters
pitchAn output pointer to the size (in bytes) of a row (ignored if nullptr)
Returns
A pointer to the texture data, which can be modified
Note
The pointer is owned by this class, you must not delete it. Make sure you call unlock_pointer() when you are done.

◆ lock_pointer() [2/2]

const color32* lxgui::gui::sdl::material::lock_pointer ( std::size_t *  pitch = nullptr) const

Returns a pointer to the texture data, which can be modified.

Parameters
pitchAn output pointer to the size (in bytes) of a row (ignored if nullptr)
Returns
A pointer to the texture data, which can be modified
Note
The pointer is owned by this class, you must not delete it. Make sure you call unlock_pointer() when you are done.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ premultiply_alpha()

static void lxgui::gui::sdl::material::premultiply_alpha ( SDL_Surface *  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::sdl::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::sdl::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::sdl::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

◆ unlock_pointer()

void lxgui::gui::sdl::material::unlock_pointer ( ) const

Stops modifying the texture data and update the texture in GPU memory.

◆ uses_same_texture()

bool lxgui::gui::sdl::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: