IRenderer without window nor graphics API, which keeps the sprites of each frame.
More...
#include <aegis2d/render/headless_renderer.hpp>
IRenderer without window nor graphics API, which keeps the sprites of each frame.
Lets rendering code run in unit tests, on CI runners without a display and in tools: a test draws a scene, then checks sprites() and clear_color(). Textures keep only their size; stats() counts the draw calls a GPU backend would make (batch_sprites()).
◆ begin_frame()
| void aegis2d::render::HeadlessRenderer::begin_frame |
( |
Color |
clear | ) |
|
|
overridevirtual |
Starts a frame and fills the screen with one color.
- Parameters
-
| clear | Background color of the frame. |
- Exceptions
-
| std::logic_error | if a frame is already started. |
Implements aegis2d::render::IRenderer.
◆ camera()
| const std::optional< Camera > & aegis2d::render::HeadlessRenderer::camera |
( |
| ) |
const |
|
overridevirtualnoexcept |
◆ clear_color()
| Color aegis2d::render::HeadlessRenderer::clear_color |
( |
| ) |
const |
|
noexcept |
Background color of the current or last frame.
- Returns
- The color given to the last begin_frame().
◆ create_texture()
| TextureId aegis2d::render::HeadlessRenderer::create_texture |
( |
const Image & |
image | ) |
|
|
overridevirtual |
Makes a texture of an image, to draw sprites with.
Allowed inside and outside frames. Textures live as long as the renderer; a TextureManager makes sure each file is loaded once.
- Parameters
-
| image | RGBA image, not empty. |
- Returns
- Its identifier: 1 for the first texture, then 2, 3... never no_texture.
- Exceptions
-
| std::invalid_argument | if image is empty. |
Implements aegis2d::render::IRenderer.
◆ draw()
| void aegis2d::render::HeadlessRenderer::draw |
( |
const Sprite & |
sprite | ) |
|
|
overridevirtual |
Adds a sprite to the current frame.
- Parameters
-
| sprite | Sprite to draw; it is copied, the caller may reuse it. |
- Exceptions
-
| std::logic_error | outside a frame. |
Implements aegis2d::render::IRenderer.
◆ end_frame()
| void aegis2d::render::HeadlessRenderer::end_frame |
( |
| ) |
|
|
overridevirtual |
◆ frames()
| std::uint64_t aegis2d::render::HeadlessRenderer::frames |
( |
| ) |
const |
|
noexcept |
Number of frames finished since creation.
- Returns
- The end_frame() count.
◆ in_frame()
| bool aegis2d::render::HeadlessRenderer::in_frame |
( |
| ) |
const |
|
overridevirtualnoexcept |
◆ set_camera()
| void aegis2d::render::HeadlessRenderer::set_camera |
( |
const std::optional< Camera > & |
camera | ) |
|
|
overridevirtual |
Places the sprites drawn from now on with a camera, or on the screen as given.
Takes effect at the next draw(), so a frame can draw its world with the camera, then its HUD without it. The camera is copied: set it again after moving it.
- Parameters
-
| camera | The camera to apply; nothing to draw in screen coordinates. |
Implements aegis2d::render::IRenderer.
◆ sprites()
| std::span< const Sprite > aegis2d::render::HeadlessRenderer::sprites |
( |
| ) |
const |
|
noexcept |
Sprites of the current frame, or of the last finished one between frames.
- Returns
- The sprites in submission order, as placed on screen by the camera; valid until the next begin_frame().
◆ stats()
| FrameStats aegis2d::render::HeadlessRenderer::stats |
( |
| ) |
const |
|
overridevirtualnoexcept |
◆ texture_size()
Size of a texture.
- Parameters
-
- Returns
- Its width and height in pixels.
- Exceptions
-
| std::out_of_range | if texture was not created by this renderer. |
Implements aegis2d::render::IRenderer.
◆ texture_updates()
| std::size_t aegis2d::render::HeadlessRenderer::texture_updates |
( |
TextureId |
texture | ) |
const |
Number of update_texture() calls a texture went through.
- Parameters
-
- Returns
- 0 for a texture never updated.
- Exceptions
-
| std::out_of_range | if texture was not created by this renderer. |
◆ textures()
| std::size_t aegis2d::render::HeadlessRenderer::textures |
( |
| ) |
const |
|
noexcept |
◆ update_texture()
| void aegis2d::render::HeadlessRenderer::update_texture |
( |
TextureId |
texture, |
|
|
const Image & |
image |
|
) |
| |
|
overridevirtual |
Replaces the image of a texture, which keeps its identifier.
Every sprite drawn with the texture shows the new image from then on, as for a texture reloaded while the game runs. Allowed inside and outside frames.
- Parameters
-
| texture | Identifier returned by create_texture(). |
| image | RGBA image, not empty; it may have another size. |
- Exceptions
-
| std::out_of_range | if texture was not created by this renderer. |
| std::invalid_argument | if image is empty. |
Implements aegis2d::render::IRenderer.
The documentation for this class was generated from the following file: