An object that can render 2D graphics on a surface.
More...
#include <Renderer2D.h>
|
using | backend_type = Backend |
|
using | device_type = typename backend_type::device_type |
|
using | buffer_type = typename device_type::buffer_type |
|
using | command_buffer_type = typename device_type::command_buffer_type |
|
using | descriptor_set_type = typename command_buffer_type::descriptor_set_type |
|
using | adapter_type = typename device_type::adapter_type |
|
using | surface_type = typename backend_type::surface_type |
|
using | render_pass_type = typename backend_type::render_pass_type |
|
using | render_pipeline_type = typename backend_type::render_pipeline_type |
|
using | pipeline_layout_type = typename backend_type::pipeline_layout_type |
|
using | shader_program_type = typename backend_type::shader_program_type |
|
using | shader_module_type = typename shader_program_type::shader_module_type |
|
using | input_assembler_type = typename backend_type::input_assembler_type |
|
using | rasterizer_type = typename backend_type::rasterizer_type |
|
using | factory_type = typename device_type::factory_type |
|
using | vertex_buffer_layout_type = typename factory_type::vertex_buffer_layout_type |
|
using | vertex_buffer_type = typename factory_type::vertex_buffer_type |
|
using | index_buffer_layout_type = typename factory_type::index_buffer_layout_type |
|
using | index_buffer_type = typename factory_type::index_buffer_type |
|
|
| Renderer2D (const math::Vector2< unsigned > &render_area, std::function< typename surface_type::handle_type(const typename backend_type::handle_type &)> surface_factory, std::span< std::string > required_extensions) |
| Creates a new 2D renderer.
|
|
| Renderer2D (const Renderer2D &other)=delete |
|
| Renderer2D (Renderer2D &&other) noexcept=delete |
|
Renderer2D & | operator= (const Renderer2D &other)=delete |
|
Renderer2D & | operator= (Renderer2D &&other) noexcept=delete |
|
void | recreateSwapChain (const math::Vector2< unsigned > &new_size) |
| Recreates the swap chain with frame buffers of the new size .
|
|
void | render () |
| Draws the current frame.
|
|
void | drawQuad (const glm::mat4 &transform_matrix, const spark::math::Vector4< float > &color={1.f, 1.f, 1.f, 1.f}) |
| Draws a 1x1 quad with the given transformation_matrix .
|
|
void | drawCircle (const glm::mat4 &transform_matrix, float radius, const spark::math::Vector4< float > &color={1.f, 1.f, 1.f, 1.f}) |
| Draws a circle with the given transformation_matrix and radius .
|
|
template<typename Backend>
class spark::core::Renderer2D< Backend >
An object that can render 2D graphics on a surface.
- Template Parameters
-
◆ Renderer2D()
template<typename Backend >
spark::core::Renderer2D< Backend >::Renderer2D |
( |
const math::Vector2< unsigned > & | render_area, |
|
|
std::function< typename surface_type::handle_type(const typename backend_type::handle_type &)> | surface_factory, |
|
|
std::span< std::string > | required_extensions ) |
|
explicit |
Creates a new 2D renderer.
- Parameters
-
render_area | The size of the area to render to. |
surface_factory | A factory function that creates a raw surface handle from a raw device handle. |
required_extensions | The list of extensions that the renderer backend requires. |
◆ drawCircle()
template<typename Backend >
Draws a circle with the given transformation_matrix
and radius
.
- Parameters
-
transform_matrix | The 4x4 matrix describing the transformation of the circle into the final world space. |
radius | The desired radius of the circle. |
color | The color of the circle. Defaults to white. |
Internally, the circle is drawn as a 1x1 quad with the given transformation matrix (in the same batch as the quads). Then, the radius is passed to the fragment shader, which uses it to calculate the distance of each fragment to the center of the circle. It discards the fragment if the distance is greater than the radius, effectively clipping the quad into a circle.
◆ drawQuad()
template<typename Backend >
Draws a 1x1 quad with the given transformation_matrix
.
- Parameters
-
transform_matrix | The 4x4 matrix describing the transformation of the 1x1 quad into the final world space. |
color | The color of the quad. Defaults to white. |
◆ recreateSwapChain()
template<typename Backend >
Recreates the swap chain with frame buffers of the new size
.
- Parameters
-
new_size | The new size of the render area. |