|
Aegis2D
Modular C++26 2D game engine for networked games
|
What the game draws with, whatever the graphics API behind it. More...
#include <aegis2d/render/renderer.hpp>
Public Member Functions | |
| IRenderer ()=default | |
| IRenderer (const IRenderer &)=delete | |
| IRenderer & | operator= (const IRenderer &)=delete |
| IRenderer (IRenderer &&)=delete | |
| IRenderer & | operator= (IRenderer &&)=delete |
| virtual | ~IRenderer () |
| Releases the backend resources. | |
| virtual TextureId | create_texture (const Image &image)=0 |
| Makes a texture of an image, to draw sprites with. | |
| virtual void | update_texture (TextureId texture, const Image &image)=0 |
| Replaces the image of a texture, which keeps its identifier. | |
| virtual TextureSize | texture_size (TextureId texture) const =0 |
| Size of a texture. | |
| virtual void | begin_frame (Color clear)=0 |
| Starts a frame and fills the screen with one color. | |
| virtual void | draw (const Sprite &sprite)=0 |
| Adds a sprite to the current frame. | |
| virtual void | end_frame ()=0 |
| Finishes the current frame and shows it. | |
| virtual bool | in_frame () const noexcept=0 |
| Tells whether a frame is started. | |
| virtual FrameStats | stats () const noexcept=0 |
| Counters of the last finished frame. | |
| virtual void | set_camera (const std::optional< Camera > &camera)=0 |
| Places the sprites drawn from now on with a camera, or on the screen as given. | |
| virtual const std::optional< Camera > & | camera () const noexcept=0 |
| The camera applied to the sprites drawn. | |
What the game draws with, whatever the graphics API behind it.
A frame is begin_frame(), any number of draw(), then end_frame(), which shows it. Sprites are drawn by layer, lowest first; within a layer, sprites of the same texture keep the order they were drawn in, and textures follow each other in the order they were created (see batch_sprites()), so overlapping sprites that must stack in a given order go on different layers. Calling them out of this order throws std::logic_error. With a camera (set_camera()), the sprites drawn are in world coordinates, placed on screen by the camera; without one, the default, they are in screen coordinates. Game code takes an IRenderer&, so it runs unchanged with the OpenGL backend (opengl::Renderer) or without any window (HeadlessRenderer, for tests and tools).
|
default |
|
delete |
|
delete |
|
virtual |
Releases the backend resources.
|
pure virtual |
Starts a frame and fills the screen with one color.
| clear | Background color of the frame. |
| std::logic_error | if a frame is already started. |
Implemented in aegis2d::render::HeadlessRenderer, and aegis2d::render::opengl::Renderer.
|
pure virtualnoexcept |
The camera applied to the sprites drawn.
Implemented in aegis2d::render::HeadlessRenderer, and aegis2d::render::opengl::Renderer.
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.
| image | RGBA image, not empty. |
| std::invalid_argument | if image is empty. |
Implemented in aegis2d::render::HeadlessRenderer, and aegis2d::render::opengl::Renderer.
|
pure virtual |
Adds a sprite to the current frame.
| sprite | Sprite to draw; it is copied, the caller may reuse it. |
| std::logic_error | outside a frame. |
Implemented in aegis2d::render::HeadlessRenderer, and aegis2d::render::opengl::Renderer.
|
pure virtual |
Finishes the current frame and shows it.
| std::logic_error | outside a frame. |
Implemented in aegis2d::render::HeadlessRenderer, and aegis2d::render::opengl::Renderer.
|
pure virtualnoexcept |
Tells whether a frame is started.
true between begin_frame() and end_frame(). Implemented in aegis2d::render::HeadlessRenderer, and aegis2d::render::opengl::Renderer.
|
pure virtual |
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.
| camera | The camera to apply; nothing to draw in screen coordinates. |
Implemented in aegis2d::render::HeadlessRenderer, and aegis2d::render::opengl::Renderer.
|
pure virtualnoexcept |
Counters of the last finished frame.
Implemented in aegis2d::render::HeadlessRenderer, and aegis2d::render::opengl::Renderer.
|
pure virtual |
Size of a texture.
| texture | Identifier returned by create_texture(). |
| std::out_of_range | if texture was not created by this renderer. |
Implemented in aegis2d::render::HeadlessRenderer, and aegis2d::render::opengl::Renderer.
|
pure virtual |
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.
| texture | Identifier returned by create_texture(). |
| image | RGBA image, not empty; it may have another size. |
| std::out_of_range | if texture was not created by this renderer. |
| std::invalid_argument | if image is empty. |
Implemented in aegis2d::render::HeadlessRenderer, and aegis2d::render::opengl::Renderer.