Ember
A C++ 20 'game engine' built with SDL3 with wide platform support.
|
Base class for all renderers. More...
#include <ember_core.h>
Public Member Functions | |
virtual | ~Renderer ()=default |
virtual void | initialize ()=0 |
Initialize the renderer and its resources. More... | |
virtual bool | load_font (const std::string &font_path, const std::string &font_alias, int font_size=48)=0 |
Load a font. More... | |
virtual std::shared_ptr< Texture > | load_texture (const std::string &path)=0 |
Load a texture from disk. More... | |
virtual std::shared_ptr< Texture > | get_texture (const std::string &path)=0 |
Get a previously loaded texture. More... | |
virtual void | draw_texture (const Texture *texture, const Rect2 &dest_rect, float rotation, const glm::vec4 &color, const Rect2 &src_rect, int z_index, bool flip_h=false, bool flip_v=false, const UberShader &uber_shader={})=0 |
Draw a textured quad. More... | |
virtual void | draw_rect (Rect2 rect, float rotation, const glm::vec4 &color, bool filled=true, int z_index=0)=0 |
Draw a rectangle (filled or outlined). More... | |
virtual void | draw_text (const std::string &text, float x, float y, float rotation, float scale, const glm::vec4 &color, const std::string &font_alias="", int z_index=0, const UberShader &uber_shader=UberShader::none(), int ft_size=0)=0 |
Draw text to screen. More... | |
virtual void | draw_line (float x1, float y1, float x2, float y2, float thickness, float rotation, const glm::vec4 &color, int z_index=0)=0 |
Draw a line. More... | |
virtual void | draw_triangle (float x1, float y1, float x2, float y2, float x3, float y3, float rotation, const glm::vec4 &color, bool filled=true, int z_index=0)=0 |
Draw a triangle. More... | |
virtual void | draw_circle (float center_x, float center_y, float rotation, float radius, const glm::vec4 &color, bool filled=true, int segments=32, int z_index=0)=0 |
Draw a circle. More... | |
virtual void | draw_polygon (const std::vector< glm::vec2 > &points, float rotation, const glm::vec4 &color, bool filled=true, int z_index=0)=0 |
Draw a polygon. More... | |
virtual void | flush ()=0 |
Submit all batched draw calls. More... | |
virtual void | present ()=0 |
Swap buffers to present the rendered frame. More... | |
virtual void | clear (glm::vec4 color=glm::vec4(0.0f, 0.0f, 0.0f, 0.0f))=0 |
Clear the screen to the given color. More... | |
virtual void | resize_viewport (int view_width, int view_height)=0 |
Resize the rendering context. More... | |
virtual void | set_context (const void *ctx)=0 |
Set the platform-specific rendering context. More... | |
virtual void * | get_context ()=0 |
Get the platform-specific rendering context. More... | |
virtual void | destroy ()=0 |
Destroy rendering resources. More... | |
virtual void | unload_font (const Font &font)=0 |
Unload a loaded font. More... | |
virtual void | unload_texture (Uint32 id)=0 |
Unload a texture by its ID. More... | |
void | set_view_matrix (const glm::mat4 &view_matrix=glm::mat4(1.f)) |
glm::mat4 | get_view_matrix () const |
virtual Uint32 | get_framebuffer_texture () const |
virtual HashMap< std::string, std::shared_ptr< Texture > > & | get_loaded_textures () |
virtual std::vector< std::string > & | get_loaded_fonts_name () |
Public Attributes | |
int | Viewport [2] = {800, 600} |
Viewport size. More... | |
SDL_Window * | Window = nullptr |
SDL Window. More... | |
Backend | Type = Backend::GL_COMPATIBILITY |
Default Type of renderer. More... | |
Protected Member Functions | |
virtual void | set_default_font (const std::string &font_name)=0 |
Set the current font to use for rendering. More... | |
glm::vec2 | rotate_point (const glm::vec2 &point, const glm::vec2 ¢er, float radians) |
Rotate a point around a center point. More... | |
Recti | calc_display () |
Calculate the display rectangle for rendering based on the viewport and window size. More... | |
virtual void | render_fbo ()=0 |
Render the current frame buffer. More... | |
void | submit (const BatchKey &key, float x, float y, float w, float h, float u0, float v0, float u1, float v1, const glm::vec4 &color, float rotation=0.0f, bool is_filled=true) |
Add a quad (textured or untextured) to the appropriate batch. More... | |
virtual void | set_effect_uniforms (const UberShader &uber_shader, const glm::vec2 &texture_size=glm::vec2(1, 1))=0 |
virtual glm::vec2 | get_texture_size (Uint32 texture_id) const =0 |
Protected Attributes | |
HashMap< BatchKey, Batch > | _batches |
All batches by key. More... | |
FT_Library | _ft = {} |
FreeType library instance. More... | |
HashMap< std::string, Font > | fonts |
Loaded fonts. More... | |
std::string | current_font_name |
Currently selected font alias. More... | |
glm::mat4 | _projection = glm::mat4(1.f) |
Projection matrix. More... | |
glm::mat4 | _view = glm::mat4(1.f) |
View matrix. More... | |
HashMap< std::string, std::shared_ptr< Texture > > | _textures |
Cached textures. More... | |
HashMap< Uint32, glm::vec2 > | _texture_sizes |
HACK_FIX: Cached texture sizes by ID. More... | |
Base class for all renderers.
|
virtualdefault |
|
protected |
Calculate the display rectangle for rendering based on the viewport and window size.
This function calculates the rectangle to draw the viewport in a way that maintains the aspect ratio (letterbox or pillarbox).
|
pure virtual |
Clear the screen to the given color.
color | Color to clear the screen with (default is black). |
Implemented in MetalRenderer, and OpenglRenderer.
|
pure virtual |
Destroy rendering resources.
Implemented in OpenglRenderer, and MetalRenderer.
|
pure virtual |
Draw a circle.
Implemented in MetalRenderer, and OpenglRenderer.
|
pure virtual |
Draw a line.
Implemented in MetalRenderer, and OpenglRenderer.
|
pure virtual |
Draw a polygon.
Implemented in OpenglRenderer, and MetalRenderer.
|
pure virtual |
Draw a rectangle (filled or outlined).
Implemented in MetalRenderer, and OpenglRenderer.
|
pure virtual |
Draw text to screen.
Implemented in OpenglRenderer, and MetalRenderer.
|
pure virtual |
Draw a textured quad.
Implemented in OpenglRenderer, and MetalRenderer.
|
pure virtual |
Draw a triangle.
Implemented in MetalRenderer, and OpenglRenderer.
|
pure virtual |
Submit all batched draw calls.
Implemented in OpenglRenderer, and MetalRenderer.
|
pure virtual |
Get the platform-specific rendering context.
Implemented in OpenglRenderer, and MetalRenderer.
|
inlinevirtual |
Reimplemented in OpenglRenderer.
|
inlinevirtual |
|
inlinevirtual |
|
pure virtual |
Get a previously loaded texture.
path | Path or alias of the texture. |
Implemented in OpenglRenderer, and MetalRenderer.
|
protectedpure virtual |
Implemented in MetalRenderer.
glm::mat4 Renderer::get_view_matrix | ( | ) | const |
|
pure virtual |
Initialize the renderer and its resources.
Implemented in OpenglRenderer, and MetalRenderer.
|
pure virtual |
Load a font.
font_path | Path to TTF file. |
font_alias | Alias name to refer to this font. |
font_size | Size of font in pixels. |
Implemented in OpenglRenderer, and MetalRenderer.
|
pure virtual |
Load a texture from disk.
path | Path to image file. |
Implemented in OpenglRenderer, and MetalRenderer.
|
pure virtual |
Swap buffers to present the rendered frame.
This function is called to display the rendered content on the screen.
Implemented in OpenglRenderer, and MetalRenderer.
|
protectedpure virtual |
Render the current frame buffer.
Implemented in MetalRenderer.
|
pure virtual |
Resize the rendering context.
view_width | Width of the view. |
view_height | Height of the view. |
Implemented in MetalRenderer, and OpenglRenderer.
|
protected |
Rotate a point around a center point.
|
pure virtual |
Set the platform-specific rendering context.
Implemented in OpenglRenderer, and MetalRenderer.
|
protectedpure virtual |
Set the current font to use for rendering.
font_name | Alias of the font to use. |
Implemented in OpenglRenderer, and MetalRenderer.
|
protectedpure virtual |
Implemented in MetalRenderer.
void Renderer::set_view_matrix | ( | const glm::mat4 & | view_matrix = glm::mat4(1.f) | ) |
|
protected |
Add a quad (textured or untextured) to the appropriate batch.
|
pure virtual |
Unload a loaded font.
Implemented in OpenglRenderer, and MetalRenderer.
|
pure virtual |
Unload a texture by its ID.
Implemented in MetalRenderer, and OpenglRenderer.
|
protected |
FreeType library instance.
|
protected |
Projection matrix.
|
protected |
HACK_FIX: Cached texture sizes by ID.
|
protected |
View matrix.
|
protected |
Currently selected font alias.
Backend Renderer::Type = Backend::GL_COMPATIBILITY |
Default Type of renderer.
int Renderer::Viewport[2] = {800, 600} |
Viewport size.
SDL_Window* Renderer::Window = nullptr |
SDL Window.