Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
headless_renderer.hpp
Go to the documentation of this file.
1
3#pragma once
4
7#include <aegis2d/render/export.hpp>
9
10#include <cstddef>
11#include <cstdint>
12#include <optional>
13#include <span>
14#include <vector>
15
16namespace aegis2d::render {
17
22class AEGIS2D_RENDER_EXPORT HeadlessRenderer final : public IRenderer {
23public:
25 TextureId create_texture(const Image& image) override;
27 void update_texture(TextureId texture, const Image& image) override;
29 [[nodiscard]] TextureSize texture_size(TextureId texture) const override;
31 void begin_frame(Color clear) override;
33 void draw(const Sprite& sprite) override;
35 void end_frame() override;
37 [[nodiscard]] bool in_frame() const noexcept override;
39 [[nodiscard]] FrameStats stats() const noexcept override;
41 void set_camera(const std::optional<Camera>& camera) override;
43 [[nodiscard]] const std::optional<Camera>& camera() const noexcept override;
44
48 [[nodiscard]] std::span<const Sprite> sprites() const noexcept;
49
52 [[nodiscard]] Color clear_color() const noexcept;
53
56 [[nodiscard]] std::size_t textures() const noexcept;
57
62 [[nodiscard]] std::size_t texture_updates(TextureId texture) const;
63
66 [[nodiscard]] std::uint64_t frames() const noexcept;
67
68private:
69 std::vector<TextureSize> textures_;
70 std::vector<std::size_t> updates_;
71 std::vector<Sprite> sprites_;
72 std::optional<Camera> camera_;
73 Color clear_color_;
74 FrameStats stats_;
75 std::uint64_t frames_ = 0;
76 bool in_frame_ = false;
77};
78
79} // namespace aegis2d::render
2D camera: the part of a world larger than the screen that is shown.
The part of the world shown on screen: where it looks, how close, within which bounds.
Definition camera.hpp:31
IRenderer without window nor graphics API, which keeps the sprites of each frame.
Definition headless_renderer.hpp:22
void end_frame() override
Finishes the current frame and shows it.
void begin_frame(Color clear) override
Starts a frame and fills the screen with one color.
bool in_frame() const noexcept override
Tells whether a frame is started.
TextureId create_texture(const Image &image) override
Makes a texture of an image, to draw sprites with.
void draw(const Sprite &sprite) override
Adds a sprite to the current frame.
void update_texture(TextureId texture, const Image &image) override
Replaces the image of a texture, which keeps its identifier.
TextureSize texture_size(TextureId texture) const override
Size of a texture.
What the game draws with, whatever the graphics API behind it.
Definition renderer.hpp:81
RGBA color used by the renderer.
OpenGL renderer: sprites, text and camera (client only).
Definition bitmap_font.hpp:16
std::uint32_t TextureId
Identifier of a texture loaded by the resource manager.
Definition renderer.hpp:32
Definition endpoint.hpp:85
Backend-independent renderer interface and the sprite it draws.
RGBA color with components in [0, 1].
Definition color.hpp:10
Counters of the last finished frame.
Definition renderer.hpp:64
RGBA image with 8 bits per channel, ready to become a texture.
Definition image.hpp:25
One textured quad to draw.
Definition renderer.hpp:46
Width and height of a texture, in pixels.
Definition renderer.hpp:38