Ember
A C++ 20 'game engine' built with SDL3 with wide platform support.
Public Member Functions | Protected Member Functions | List of all members
MetalRenderer Class Referencefinal

#include <ember_mtl.h>

Inheritance diagram for MetalRenderer:
Renderer

Public Member Functions

 MetalRenderer ()
 
 ~MetalRenderer () override
 
void initialize () override
 Initialize the renderer and its resources. More...
 
void clear (glm::vec4) override
 Clear the screen to the given color. More...
 
void present () override
 Swap buffers to present the rendered frame. More...
 
void resize_viewport (int, int) override
 Resize the rendering context. More...
 
void set_context (const void *) override
 Set the platform-specific rendering context. More...
 
void * get_context () override
 Get the platform-specific rendering context. More...
 
void destroy () override
 Destroy rendering resources. More...
 
bool load_font (const std::string &, const std::string &, int) override
 Load a font. More...
 
std::shared_ptr< Textureload_texture (const std::string &) override
 Load a texture from disk. More...
 
std::shared_ptr< Textureget_texture (const std::string &) override
 Get a previously loaded texture. More...
 
void unload_font (const Font &) override
 Unload a loaded font. More...
 
void unload_texture (Uint32) override
 Unload a texture by its ID. More...
 
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, bool flip_v, const UberShader &uber_shader) override
 Draw a textured quad. More...
 
void draw_rect (Rect2, float, const glm::vec4 &, bool, int) override
 Draw a rectangle (filled or outlined). More...
 
void draw_text (const std::string &, float, float, float, float, const glm::vec4 &, const std::string &, int, const UberShader &, int) override
 Draw text to screen. More...
 
void draw_line (float, float, float, float, float, float, const glm::vec4 &, int) override
 Draw a line. More...
 
void draw_triangle (float, float, float, float, float, float, float, const glm::vec4 &, bool, int) override
 Draw a triangle. More...
 
void draw_circle (float, float, float, float, const glm::vec4 &, bool, int, int) override
 Draw a circle. More...
 
void draw_polygon (const std::vector< glm::vec2 > &, float, const glm::vec4 &, bool, int) override
 Draw a polygon. More...
 
void flush () override
 Submit all batched draw calls. More...
 
- Public Member Functions inherited from Renderer
virtual ~Renderer ()=default
 
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 ()
 

Protected Member Functions

void set_default_font (const std::string &) override
 Set the current font to use for rendering. More...
 
void render_fbo () override
 Render the current frame buffer. More...
 
void set_effect_uniforms (const UberShader &, const glm::vec2 &) override
 
glm::vec2 get_texture_size (Uint32) const override
 
- Protected Member Functions inherited from Renderer
glm::vec2 rotate_point (const glm::vec2 &point, const glm::vec2 &center, 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...
 
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...
 

Additional Inherited Members

- Public Attributes inherited from Renderer
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 Attributes inherited from Renderer
HashMap< BatchKey, Batch_batches
 All batches by key. More...
 
FT_Library _ft = {}
 FreeType library instance. More...
 
HashMap< std::string, Fontfonts
 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...
 

Constructor & Destructor Documentation

◆ MetalRenderer()

MetalRenderer::MetalRenderer ( )
inlinedefault

◆ ~MetalRenderer()

MetalRenderer::~MetalRenderer ( )
inlineoverridedefault

Member Function Documentation

◆ clear()

void MetalRenderer::clear ( glm::vec4  color)
inlineoverridevirtual

Clear the screen to the given color.

Parameters
colorColor to clear the screen with (default is black).

Implements Renderer.

◆ destroy()

void MetalRenderer::destroy ( )
inlineoverridevirtual

Destroy rendering resources.

Implements Renderer.

◆ draw_circle()

void MetalRenderer::draw_circle ( float  center_x,
float  center_y,
float  rotation,
float  radius,
const glm::vec4 &  color,
bool  filled,
int  segments,
int  z_index 
)
inlineoverridevirtual

Draw a circle.

Implements Renderer.

◆ draw_line()

void MetalRenderer::draw_line ( float  x1,
float  y1,
float  x2,
float  y2,
float  thickness,
float  rotation,
const glm::vec4 &  color,
int  z_index 
)
inlineoverridevirtual

Draw a line.

Implements Renderer.

◆ draw_polygon()

void MetalRenderer::draw_polygon ( const std::vector< glm::vec2 > &  points,
float  rotation,
const glm::vec4 &  color,
bool  filled,
int  z_index 
)
inlineoverridevirtual

Draw a polygon.

Implements Renderer.

◆ draw_rect()

void MetalRenderer::draw_rect ( Rect2  rect,
float  rotation,
const glm::vec4 &  color,
bool  filled,
int  z_index 
)
inlineoverridevirtual

Draw a rectangle (filled or outlined).

Implements Renderer.

◆ draw_text()

void MetalRenderer::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,
const UberShader uber_shader,
int  ft_size 
)
inlineoverridevirtual

Draw text to screen.

Implements Renderer.

◆ draw_texture()

void MetalRenderer::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,
bool  flip_v,
const UberShader uber_shader 
)
inlineoverridevirtual

Draw a textured quad.

Implements Renderer.

◆ draw_triangle()

void MetalRenderer::draw_triangle ( float  x1,
float  y1,
float  x2,
float  y2,
float  x3,
float  y3,
float  rotation,
const glm::vec4 &  color,
bool  filled,
int  z_index 
)
inlineoverridevirtual

Draw a triangle.

Implements Renderer.

◆ flush()

void MetalRenderer::flush ( )
inlineoverridevirtual

Submit all batched draw calls.

Implements Renderer.

◆ get_context()

void * MetalRenderer::get_context ( )
inlineoverridevirtual

Get the platform-specific rendering context.

Implements Renderer.

◆ get_texture()

std::shared_ptr< Texture > MetalRenderer::get_texture ( const std::string &  path)
inlineoverridevirtual

Get a previously loaded texture.

Parameters
pathPath or alias of the texture.
Returns
Reference to the Texture.

Implements Renderer.

◆ get_texture_size()

glm::vec2 MetalRenderer::get_texture_size ( Uint32  ) const
inlineoverrideprotectedvirtual

Implements Renderer.

◆ initialize()

void MetalRenderer::initialize ( )
inlineoverridevirtual

Initialize the renderer and its resources.

Implements Renderer.

◆ load_font()

bool MetalRenderer::load_font ( const std::string &  font_path,
const std::string &  font_alias,
int  font_size 
)
inlineoverridevirtual

Load a font.

Parameters
font_pathPath to TTF file.
font_aliasAlias name to refer to this font.
font_sizeSize of font in pixels.
Returns
true if loaded successfully.

Implements Renderer.

◆ load_texture()

std::shared_ptr< Texture > MetalRenderer::load_texture ( const std::string &  path)
inlineoverridevirtual

Load a texture from disk.

Parameters
pathPath to image file.
Returns
Reference to the loaded Texture.

Implements Renderer.

◆ present()

void MetalRenderer::present ( )
inlineoverridevirtual

Swap buffers to present the rendered frame.

This function is called to display the rendered content on the screen.

Implements Renderer.

◆ render_fbo()

void MetalRenderer::render_fbo ( )
inlineoverrideprotectedvirtual

Render the current frame buffer.

Implements Renderer.

◆ resize_viewport()

void MetalRenderer::resize_viewport ( int  view_width,
int  view_height 
)
inlineoverridevirtual

Resize the rendering context.

Parameters
view_widthWidth of the view.
view_heightHeight of the view.

Implements Renderer.

◆ set_context()

void MetalRenderer::set_context ( const void *  ctx)
inlineoverridevirtual

Set the platform-specific rendering context.

Implements Renderer.

◆ set_default_font()

void MetalRenderer::set_default_font ( const std::string &  font_name)
inlineoverrideprotectedvirtual

Set the current font to use for rendering.

Parameters
font_nameAlias of the font to use.

Implements Renderer.

◆ set_effect_uniforms()

void MetalRenderer::set_effect_uniforms ( const UberShader ,
const glm::vec2 &   
)
inlineoverrideprotectedvirtual

Implements Renderer.

◆ unload_font()

void MetalRenderer::unload_font ( const Font font)
inlineoverridevirtual

Unload a loaded font.

Implements Renderer.

◆ unload_texture()

void MetalRenderer::unload_texture ( Uint32  id)
inlineoverridevirtual

Unload a texture by its ID.

Implements Renderer.


The documentation for this class was generated from the following files: