1 #ifndef LXGUI_GUI_RENDERER_HPP
2 #define LXGUI_GUI_RENDERER_HPP
4 #include "lxgui/gui_code_point_range.hpp"
5 #include "lxgui/gui_material.hpp"
6 #include "lxgui/gui_matrix4.hpp"
7 #include "lxgui/gui_vertex_cache.hpp"
8 #include "lxgui/lxgui.hpp"
13 #include <unordered_map>
180 void begin(std::shared_ptr<render_target> target =
nullptr);
277 std::shared_ptr<material>
303 const std::string& atlas_category,
304 const std::string& file_name,
313 virtual std::shared_ptr<material>
321 std::shared_ptr<material>
create_material(std::shared_ptr<render_target> target);
358 const std::string& font_file,
361 const std::vector<code_point_range>& code_points,
362 char32_t default_code_point);
378 const std::string& atlas_category,
379 const std::string& font_file,
382 const std::vector<code_point_range>& code_points,
383 char32_t default_code_point);
403 virtual void begin_(std::shared_ptr<render_target> target) = 0;
466 virtual std::shared_ptr<material>
488 const std::string& font_file,
491 const std::vector<code_point_range>& code_points,
492 char32_t default_code_point) = 0;
496 std::unordered_map<std::string, std::weak_ptr<gui::material>>
texture_list_;
497 std::unordered_map<std::string, std::shared_ptr<gui::atlas>>
atlas_list_;
498 std::unordered_map<std::string, std::weak_ptr<gui::font>>
font_list_;
503 bool texture_atlas_enabled_ =
true;
504 bool vertex_cache_enabled_ =
true;
505 bool quad_batching_enabled_ =
true;
506 std::size_t texture_atlas_page_size_ = 0u;
508 struct quad_batcher {
509 std::vector<std::array<vertex, 4>> data;
510 std::shared_ptr<vertex_cache> cache;
513 static constexpr std::size_t batching_cache_cycle_size = 16u;
514 std::array<quad_batcher, batching_cache_cycle_size> quad_cache_;
517 std::size_t current_quad_cache_ = 0u;
518 std::size_t batch_count_ = 0u;
519 std::size_t vertex_count_ = 0u;
520 std::size_t last_frame_batch_count_ = 0u;
521 std::size_t last_frame_vertex_count_ = 0u;
A class that holds multiple materials for efficient rendering.
A class that holds rendering data.
Abstract type for implementation specific management.
renderer(renderer &&)=delete
Non-movable.
bool is_quad_batching_enabled() const
Checks if the renderer has quad render batching enabled.
std::shared_ptr< material > create_atlas_material(const std::string &atlas_category, const std::string &file_name, material::filter filt=material::filter::none)
Creates a new material from a texture file.
virtual std::shared_ptr< material > create_material(const vector2ui &dimensions, const color32 *pixel_data, material::filter filt=material::filter::none)=0
Creates a new material from arbitrary pixel data.
std::size_t get_batch_count() const
Returns the number of batches of vertices sent to the GPU since the last call to reset_counters.
renderer & operator=(const renderer &)=delete
Non-copiable.
std::shared_ptr< font > create_atlas_font(const std::string &atlas_category, const std::string &font_file, std::size_t size, std::size_t outline, const std::vector< code_point_range > &code_points, char32_t default_code_point)
Creates a new font.
renderer & operator=(renderer &&)=delete
Non-movable.
std::size_t get_texture_atlas_page_size() const
Returns the width/height of a texture atlas page (in pixels).
virtual std::shared_ptr< vertex_cache > create_vertex_cache(gui::vertex_cache::type type)=0
Creates a new empty vertex cache.
bool is_texture_atlas_enabled() const
Checks if the renderer has texture atlases enabled.
void render_quad(const quad &q)
Renders a quad.
virtual std::string get_name() const =0
Returns a human-readable name for this renderer.
renderer()=default
Constructor.
void set_view(const matrix4f &view_matrix)
Sets the view matrix to use when rendering (viewport).
virtual std::shared_ptr< font > create_font_(const std::string &font_file, std::size_t size, std::size_t outline, const std::vector< code_point_range > &code_points, char32_t default_code_point)=0
Creates a new font.
void end()
Ends rendering.
virtual bool is_texture_atlas_supported() const =0
Checks if the renderer supports texture atlases natively.
void render_cache(const material *mat, const vertex_cache &cache, const matrix4f &model_transform=matrix4f::identity)
Renders a vertex cache.
virtual void notify_window_resized(const vector2ui &dimensions)
Notifies the renderer that the render window has been resized.
std::size_t get_vertex_count() const
Returns the number of vertices sent to the GPU since the last call to reset_counters.
virtual ~renderer()=default
Destructor.
std::unordered_map< std::string, std::weak_ptr< gui::font > > font_list_
void auto_detect_settings()
Automatically determines the best rendering settings for the current platform.
renderer(const renderer &)=delete
Non-copiable.
std::size_t get_texture_atlas_page_count() const
Count the total number of texture atlas pages currently in use.
void set_texture_atlas_enabled(bool enabled)
Enables/disables texture atlases.
atlas & get_atlas_(const std::string &atlas_category, material::filter filt)
virtual bool is_vertex_cache_supported() const =0
Checks if the renderer supports vertex caches.
virtual std::shared_ptr< render_target > create_render_target(const vector2ui &dimensions, material::filter filt=material::filter::none)=0
Creates a new render target.
virtual std::size_t get_texture_max_size() const =0
Returns the maximum texture width/height (in pixels).
virtual void set_view_(const matrix4f &view_matrix)=0
Sets the view matrix to use when rendering (viewport).
virtual std::shared_ptr< atlas > create_atlas_(material::filter filt)=0
Creates a new atlas with a given texture filter mode.
void set_quad_batching_enabled(bool enabled)
Enables/disables quad batching.
virtual std::shared_ptr< material > create_material(std::shared_ptr< render_target > target, const bounds2f &location)=0
Creates a new material from a portion of a render target.
void begin(std::shared_ptr< render_target > target=nullptr)
Begins rendering on a particular render target.
void set_texture_atlas_page_size(std::size_t page_size)
Set the width/height of a texture atlas page (in pixels).
void render_quads(const material *mat, const std::vector< std::array< vertex, 4 >> &quad_list)
Renders a set of quads.
virtual void end_()=0
Ends rendering.
virtual void render_quads_(const material *mat, const std::vector< std::array< vertex, 4 >> &quad_list)=0
Renders a set of quads.
std::unordered_map< std::string, std::weak_ptr< gui::material > > texture_list_
std::unordered_map< std::string, std::shared_ptr< gui::atlas > > atlas_list_
void reset_counters()
Resets the number of batches to zero (for analytics only).
void flush_quad_batch()
Flushes any pending quad batch render operation.
virtual bool is_texture_vertex_color_supported() const =0
Checks if the renderer supports setting colors for each vertex of a textured quad.
virtual std::shared_ptr< material > create_material_(const std::string &file_name, material::filter filt)=0
Creates a new material from a texture file.
std::shared_ptr< font > create_font(const std::string &font_file, std::size_t size, std::size_t outline, const std::vector< code_point_range > &code_points, char32_t default_code_point)
Creates a new font.
bool is_vertex_cache_enabled() const
Checks if the renderer has enabled support for vertex caches.
void set_vertex_cache_enabled(bool enabled)
Enables/disables vertex caches.
virtual void render_cache_(const material *mat, const vertex_cache &cache, const matrix4f &model_transform)=0
Renders a vertex cache.
virtual void begin_(std::shared_ptr< render_target > target)=0
Begins rendering on a particular render target.
std::shared_ptr< material > create_material(const std::string &file_name, material::filter filt=material::filter::none)
Creates a new material from a texture file.
virtual matrix4f get_view() const =0
Returns the current view matrix to use when rendering (viewport).
An object representing cached vertex data on the GPU.
type
The type of vertex data contained in a vertex_cache.
Holds a single color (byte RGBA, 32 bits)
A 4x4 matrix, used for coordinate transformations.
static const matrix4f identity
Simple structure holding four vertices and a material.