1 #ifndef LXGUI_GUI_GL_RENDERER_HPP
2 #define LXGUI_GUI_GL_RENDERER_HPP
4 #include "lxgui/impl/gui_gl_render_target.hpp"
5 #if defined(LXGUI_OPENGL3)
6 # include "lxgui/impl/gui_gl_vertex_cache.hpp"
9 #include "lxgui/gui_matrix4.hpp"
10 #include "lxgui/gui_renderer.hpp"
11 #include "lxgui/utils.hpp"
83 std::shared_ptr<gui::material>
113 #if !defined(LXGUI_OPENGL3)
129 std::shared_ptr<gui::material>
150 const std::string& font_file,
153 const std::vector<code_point_range>& code_points,
154 char32_t default_code_point)
override;
160 void begin_(std::shared_ptr<gui::render_target> target)
override;
193 const gui::material* mat,
const std::vector<std::array<vertex, 4>>& quad_list)
override;
215 const matrix4f& model_transform)
override;
218 void update_view_matrix_()
const;
219 #if defined(LXGUI_OPENGL3)
220 void compile_programs_();
221 void setup_buffers_();
224 std::shared_ptr<gui::material>
225 create_material_png_(
const std::string& file_name,
material::filter filt)
const;
229 std::shared_ptr<gui::gl::render_target> current_target_;
232 #if defined(LXGUI_OPENGL3)
233 struct shader_cache {
234 shader_cache() =
default;
235 shader_cache(
const shader_cache&) =
delete;
236 shader_cache(shader_cache&&) =
delete;
239 std::uint32_t program = 0;
240 int sampler_location = 0;
241 int proj_location = 0;
242 int model_location = 0;
243 int type_location = 0;
246 static thread_local std::weak_ptr<shader_cache> static_shader_cache;
247 std::shared_ptr<shader_cache> shader_cache_;
249 static constexpr std::size_t cache_cycle_size = 1024u;
250 std::array<std::shared_ptr<gl::vertex_cache>, cache_cycle_size> quad_cache_;
251 std::array<std::shared_ptr<gl::vertex_cache>, cache_cycle_size> array_cache_;
252 std::uint32_t quad_cycle_cache_ = 0u;
253 std::uint32_t array_cycle_cache_ = 0u;
255 std::uint32_t previous_texture_ = std::numeric_limits<std::uint32_t>::max();
Open implementation of rendering.
void begin_(std::shared_ptr< gui::render_target > target) override
Begins rendering on a particular render target.
bool is_texture_vertex_color_supported() const override
Checks if the renderer supports setting colors for each vertex of a textured quad.
std::size_t get_texture_max_size() const override
Returns the maximum texture width/height (in pixels).
bool is_texture_atlas_supported() const override
Checks if the renderer supports texture atlases natively.
std::shared_ptr< gui::material > create_material(const vector2ui &dimensions, const color32 *pixel_data, material::filter filt=material::filter::none) override
Creates a new material from arbitrary pixel data.
matrix4f get_view() const override
Returns the current view matrix to use when rendering (viewport).
std::shared_ptr< gui::material > create_material_(const std::string &file_name, material::filter filt) override
Creates a new material from a texture file.
void set_view_(const matrix4f &view_matrix) override
Sets the view matrix to use when rendering (viewport).
void render_quads_(const gui::material *mat, const std::vector< std::array< vertex, 4 >> &quad_list) override
Renders a set of quads.
renderer(const vector2ui &window_dimensions, bool init_glew=true)
Constructor.
std::shared_ptr< gui::atlas > create_atlas_(material::filter filt) override
Creates a new atlas with a given texture filter mode.
std::shared_ptr< gui::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) override
Creates a new font.
std::string get_name() const override
Returns a human-readable name for this renderer.
void end_() override
Ends rendering.
bool is_vertex_cache_supported() const override
Checks if the renderer supports vertex caches.
static bool is_gl_extension_supported(const std::string &extension)
Checks if a given OpenGL extension is supported by the machine.
void render_cache_(const gui::material *mat, const gui::vertex_cache &cache, const matrix4f &model_transform) override
Renders a vertex cache.
void notify_window_resized(const vector2ui &new_dimensions) override
Notifies the renderer that the render window has been resized.
std::shared_ptr< gui::render_target > create_render_target(const vector2ui &dimensions, material::filter filt=material::filter::none) override
Creates a new render target.
std::shared_ptr< gui::material > create_material(std::shared_ptr< gui::render_target > target, const bounds2f &location) override
Creates a new material from a portion of a render target.
std::shared_ptr< gui::vertex_cache > create_vertex_cache(gui::vertex_cache::type type) override
Creates a new empty vertex cache.
A class that holds rendering data.
Abstract type for implementation specific management.
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