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

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

#include <gui_gl_material.hpp>

Inheritance diagram for lxgui::gui::gl::material:
lxgui::gui::material

Public Types

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

Public Member Functions

 material (const vector2ui &dimensions, wrap wrp=wrap::repeat, filter filt=filter::none)
 Constructor for textures. More...
 
 material (std::uint32_t texture_handle, const vector2ui &canvas_dimensions, 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 () 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...
 
void bind () const
 Sets this material as the active one. More...
 
void update_texture (const color32 *data)
 Updates the texture that is in GPU memory. More...
 
std::uint32_t get_handle () const
 Returns the OpenGL texture handle. 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 (std::vector< color32 > &data)
 Premultiplies the texture by alpha component. More...
 
static void check_availability ()
 Checks if the machine is capable of using some features. More...
 
static std::size_t get_max_size ()
 Returns the maximum size available for a texture, in pixels. 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 OpenGL texture. It is also used by the gui::gl::render_target class to store the output data.

Definition at line 20 of file gui_gl_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/4]

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

Constructor for textures.

Parameters
dimensionsThe requested texture dimensions
wrpHow to adjust texture coordinates that are outside the [0,1] range
filtUse texture filtering or not (see set_filter())

◆ material() [2/4]

lxgui::gui::gl::material::material ( std::uint32_t  texture_handle,
const vector2ui canvas_dimensions,
const bounds2f  rect,
filter  filt = filter::none 
)

Constructor for atlas textures.

Parameters
texture_handleThe handle to the texture object of the atlas
canvas_dimensionsThe dimensions of the texture atlas
rectThe position of this texture inside the atlas
filtUse texture filtering or not (see set_filter())

◆ material() [3/4]

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

◆ material() [4/4]

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

◆ ~material()

lxgui::gui::gl::material::~material ( )
overridevirtual

Destructor.

Reimplemented from lxgui::gui::material.

Member Function Documentation

◆ bind()

void lxgui::gui::gl::material::bind ( ) const

Sets this material as the active one.

◆ check_availability()

static void lxgui::gui::gl::material::check_availability ( )
static

Checks if the machine is capable of using some features.

Note
The function checks for non power of two capability. If the graphics card doesn't support it, the material class will automatically create power of two textures.

◆ get_canvas_dimensions()

vector2ui lxgui::gui::gl::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::gl::material::get_filter ( ) const

Returns the filter mode of this texture.

Returns
The filter mode of this texture

◆ get_handle()

std::uint32_t lxgui::gui::gl::material::get_handle ( ) const

Returns the OpenGL texture handle.

Note
For internal use.

◆ 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_max_size()

static std::size_t lxgui::gui::gl::material::get_max_size ( )
static

Returns the maximum size available for a texture, in pixels.

Returns
The maximum size available for a texture, in pixels

◆ get_rect()

bounds2f lxgui::gui::gl::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.

◆ 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::gl::material::operator= ( const material tex)
delete

◆ operator=() [2/2]

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

◆ premultiply_alpha()

static void lxgui::gui::gl::material::premultiply_alpha ( std::vector< color32 > &  data)
static

Premultiplies the texture by alpha component.

Parameters
dataThe pixel data to pre-multiply
Note
Premultiplied alpha is a rendering technique that allows perfect alpha blending when using render targets.

◆ set_dimensions()

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