gui::gl::material Class Reference

A class that holds rendering data. More...

#include <gui_gl_material.hpp>

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

List of all members.

Classes

struct  color_data
struct  texture_data

Public Types

enum  wrap { REPEAT, CLAMP }
enum  filter { NONE, LINEAR }
enum  type { TYPE_TEXTURE, TYPE_COLOR }

Public Member Functions

 material (uint uiWidth, uint uiHeight, wrap mWrap=REPEAT, filter mFilter=NONE, bool bGPUOnly=false)
 Constructor for textures.
 material (const color &mColor)
 Constructor for plain colors.
 ~material ()
 Destructor.
type get_type () const
 Returns the type of this texture (texture or color).
float get_width () const
 Returns the width of the underlying texture (if any).
float get_height () const
 Returns the height of the underlying texture (if any).
float get_real_width () const
 Returns the physical width of the underlying texture (if any).
float get_real_height () const
 Returns the physical height of the underlying texture (if any).
bool set_dimensions (uint uiWidth, uint uiHeight)
 Resizes this texture.
color get_color () const
 Returns the plain color of this texture.
void premultiply_alpha ()
 Premultiplies the texture by alpha component.
void set_wrap (wrap mWrap)
 Sets the wrap mode of this texture.
void set_filter (filter mFilter)
 Sets the filter mode of this texture.
void bind () const
 Sets this material as the active one.
const std::vector< ub32color > & get_data () const
 Returns the cached texture data (read only).
std::vector< ub32color > & get_data ()
 Returns the cached texture data (read and write).
void set_pixel (uint x, uint y, const ub32color &mColor)
 Sets the color of one pixel.
const ub32colorget_pixel (uint x, uint y) const
 Returns the color of one pixel (read only).
ub32colorget_pixel (uint x, uint y)
 Returns the color of one pixel.
void update_texture ()
 Updates the texture that is in GPU memory.
void clear_cache_data_ ()
 Removes the cached texture data (in CPU memory).
uint get_handle_ ()
 Returns the OpenGL texture handle.

Static Public Member Functions

static void check_availability ()
 Checks if the machine is capable of using some features.

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 25 of file gui_gl_material.hpp.


Member Enumeration Documentation

Enumerator:
NONE 
LINEAR 

Definition at line 35 of file gui_gl_material.hpp.

Enumerator:
TYPE_TEXTURE 
TYPE_COLOR 

Definition at line 41 of file gui_gl_material.hpp.

Enumerator:
REPEAT 
CLAMP 

Definition at line 29 of file gui_gl_material.hpp.


Constructor & Destructor Documentation

gui::gl::material::material ( uint  uiWidth,
uint  uiHeight,
wrap  mWrap = REPEAT,
filter  mFilter = NONE,
bool  bGPUOnly = false 
)

Constructor for textures.

Parameters:
uiWidth The requested texture width
uiHeight The requested texture height
mWrap How to adjust texture coordinates that are outside the [0,1] range
mFilter Use texture filtering or not (see set_filter()) bGPUOnly If 'false', a copy of the texture is kept in CPU memory (RAM). Else the texture only resides in GPU memory (used by render_target).

Definition at line 15 of file gui_gl_material.cpp.

gui::gl::material::material ( const color mColor  ) 

Constructor for plain colors.

Parameters:
mColor The plain color to use

Definition at line 84 of file gui_gl_material.cpp.

gui::gl::material::~material (  )  [virtual]

Destructor.

Reimplemented from gui::material.

Definition at line 90 of file gui_gl_material.cpp.


Member Function Documentation

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

Sets this material as the active one.

Definition at line 155 of file gui_gl_material.cpp.

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

Definition at line 350 of file gui_gl_material.cpp.

void gui::gl::material::clear_cache_data_ (  ) 

Removes the cached texture data (in CPU memory).

Note:
For internal use.

Definition at line 340 of file gui_gl_material.cpp.

color gui::gl::material::get_color (  )  const

Returns the plain color of this texture.

Returns:
The plain color of this texture

Definition at line 106 of file gui_gl_material.cpp.

std::vector< ub32color > & gui::gl::material::get_data (  ) 

Returns the cached texture data (read and write).

Returns:
The cached texture data (read and write)
Note:
If you modify the texture data, you need to call update_texture() when you're done, so that the texture that is in the GPU memory gets updated.

Definition at line 165 of file gui_gl_material.cpp.

const std::vector< ub32color > & gui::gl::material::get_data (  )  const

Returns the cached texture data (read only).

Returns:
The cached texture data (read only)

Definition at line 160 of file gui_gl_material.cpp.

uint gui::gl::material::get_handle_ (  ) 

Returns the OpenGL texture handle.

Note:
For internal use.

Definition at line 345 of file gui_gl_material.cpp.

float gui::gl::material::get_height (  )  const [virtual]

Returns the height of the underlying texture (if any).

Returns:
The height of the underlying texture (if any)

Implements gui::material.

Definition at line 211 of file gui_gl_material.cpp.

ub32color & gui::gl::material::get_pixel ( uint  x,
uint  y 
)

Returns the color of one pixel.

Parameters:
x The coordinate of the pixel in the texture
y The coordinate of the pixel in the texture
Returns:
The color of the pixel
Note:
If you modify the texture data, you need to call update_texture() when you're done, so that the texture that is in the GPU memory gets updated.

Definition at line 180 of file gui_gl_material.cpp.

const ub32color & gui::gl::material::get_pixel ( uint  x,
uint  y 
) const

Returns the color of one pixel (read only).

Parameters:
x The coordinate of the pixel in the texture
y The coordinate of the pixel in the texture
Returns:
The color of the pixel

Definition at line 175 of file gui_gl_material.cpp.

float gui::gl::material::get_real_height (  )  const [virtual]

Returns the physical height of the underlying texture (if any).

Returns:
The physical height of the underlying texture (if any)
Note:
Some old hardware don't support textures that have non power of two dimensions. If the user creates such a material and its hardware doesn't support it, this class creates a bigger texture that has power of two dimensions (the "physical" dimensions).

Implements gui::material.

Definition at line 237 of file gui_gl_material.cpp.

float gui::gl::material::get_real_width (  )  const [virtual]

Returns the physical width of the underlying texture (if any).

Returns:
The physical width of the underlying texture (if any)
Note:
Some old hardware don't support textures that have non power of two dimensions. If the user creates such a material and its hardware doesn't support it, this class creates a bigger texture that has power of two dimensions (the "physical" dimensions).

Implements gui::material.

Definition at line 224 of file gui_gl_material.cpp.

material::type gui::gl::material::get_type (  )  const

Returns the type of this texture (texture or color).

Returns:
The type of this texture (texture or color)

Definition at line 101 of file gui_gl_material.cpp.

float gui::gl::material::get_width (  )  const [virtual]

Returns the width of the underlying texture (if any).

Returns:
The width of the underlying texture (if any)

Implements gui::material.

Definition at line 198 of file gui_gl_material.cpp.

void gui::gl::material::premultiply_alpha (  ) 

Premultiplies the texture by alpha component.

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

Definition at line 185 of file gui_gl_material.cpp.

bool gui::gl::material::set_dimensions ( uint  uiWidth,
uint  uiHeight 
)

Resizes this texture.

Parameters:
uiWidth The new texture width
uiHeight The new texture height
Note:
All the previous data that was stored in this texture will be lost.

Definition at line 250 of file gui_gl_material.cpp.

void gui::gl::material::set_filter ( filter  mFilter  ) 

Sets the filter mode of this texture.

Parameters:
mFilter Use 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.

Definition at line 133 of file gui_gl_material.cpp.

void gui::gl::material::set_pixel ( uint  x,
uint  y,
const ub32color mColor 
)

Sets the color of one pixel.

Parameters:
x The coordinate of the pixel in the texture
y The coordinate of the pixel in the texture
mColor The new color of the pixel
Note:
If you modify the texture data, you need to call update_texture() when you're done, so that the texture that is in the GPU memory gets updated.

Definition at line 170 of file gui_gl_material.cpp.

void gui::gl::material::set_wrap ( wrap  mWrap  ) 

Sets the wrap mode of this texture.

Parameters:
mWrap How to adjust texture coordinates that are outside the [0,1] range

Definition at line 111 of file gui_gl_material.cpp.

void gui::gl::material::update_texture (  ) 

Updates the texture that is in GPU memory.

Note:
Whenever you modify pixels of the texture, remember to call this function when you're done, else your changes won't be applied to the GPU.

Definition at line 327 of file gui_gl_material.cpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on Tue Jan 1 21:58:13 2013 for gui by  doxygen 1.6.1