lxgui
gui_gl_material.hpp
1 #ifndef LXGUI_GUI_GL_MATERIAL_HPP
2 #define LXGUI_GUI_GL_MATERIAL_HPP
3 
4 #include "lxgui/gui_bounds2.hpp"
5 #include "lxgui/gui_color.hpp"
6 #include "lxgui/gui_material.hpp"
7 #include "lxgui/utils.hpp"
8 
9 #include <memory>
10 #include <vector>
11 
12 namespace lxgui::gui::gl {
13 
20 class material final : public gui::material {
21 public:
28  material(const vector2ui& dimensions, wrap wrp = wrap::repeat, filter filt = filter::none);
29 
38  std::uint32_t texture_handle,
39  const vector2ui& canvas_dimensions,
40  const bounds2f rect,
41  filter filt = filter::none);
42 
43  material(const material& tex) = delete;
44  material(material&& tex) = delete;
45  material& operator=(const material& tex) = delete;
46  material& operator=(material&& tex) = delete;
47 
49  ~material() override;
50 
55  bounds2f get_rect() const override;
56 
68  vector2ui get_canvas_dimensions() const override;
69 
74  bool uses_same_texture(const gui::material& other) const override;
75 
82  bool set_dimensions(const vector2ui& dimensions);
83 
90  static void premultiply_alpha(std::vector<color32>& data);
91 
96  void set_wrap(wrap wrp);
97 
104  void set_filter(filter filt);
105 
111 
113  void bind() const;
114 
119  void update_texture(const color32* data);
120 
125  std::uint32_t get_handle() const;
126 
133  static void check_availability();
134 
139  static std::size_t get_max_size();
140 
141 private:
142  vector2ui canvas_dimensions_;
143  wrap wrap_ = wrap::repeat;
144  filter filter_ = filter::none;
145  std::uint32_t texture_handle_ = 0u;
146  bounds2f rect_;
147  bool is_owner_ = false;
148 
149  static bool only_power_of_two;
150  static std::size_t maximum_size;
151 };
152 
153 } // namespace lxgui::gui::gl
154 
155 #endif
A class that holds rendering data This implementation can contain either a plain color or a real Open...
material(const vector2ui &dimensions, wrap wrp=wrap::repeat, filter filt=filter::none)
Constructor for textures.
material & operator=(const material &tex)=delete
void update_texture(const color32 *data)
Updates the texture that is in GPU memory.
static void check_availability()
Checks if the machine is capable of using some features.
bounds2f get_rect() const override
Returns the pixel rect in pixels of the canvas containing this texture (if any).
~material() override
Destructor.
static std::size_t get_max_size()
Returns the maximum size available for a texture, in pixels.
material(const material &tex)=delete
bool set_dimensions(const vector2ui &dimensions)
Resizes this texture.
std::uint32_t get_handle() const
Returns the OpenGL texture handle.
bool uses_same_texture(const gui::material &other) const override
Checks if another material is based on the same texture as the current material.
vector2ui get_canvas_dimensions() const override
Returns the physical dimensions (in pixels) of the canvas containing this texture (if any).
void set_filter(filter filt)
Sets the filter mode of this texture.
material(std::uint32_t texture_handle, const vector2ui &canvas_dimensions, const bounds2f rect, filter filt=filter::none)
Constructor for atlas textures.
filter get_filter() const
Returns the filter mode of this texture.
void bind() const
Sets this material as the active one.
material & operator=(material &&tex)=delete
void set_wrap(wrap wrp)
Sets the wrap mode of this texture.
static void premultiply_alpha(std::vector< color32 > &data)
Premultiplies the texture by alpha component.
material(material &&tex)=delete
A class that holds rendering data.
Holds a single color (byte RGBA, 32 bits)
Definition: gui_color.hpp:75