yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::gfx::MetalRenderer Class Referencefinal

#include <metal_renderer.h>

Inheritance diagram for yaze::gfx::MetalRenderer:
Collaboration diagram for yaze::gfx::MetalRenderer:

Public Member Functions

 MetalRenderer ()=default
 
 ~MetalRenderer () override
 
bool Initialize (SDL_Window *window) override
 Initializes the renderer with a given window.
 
void Shutdown () override
 Shuts down the renderer and releases all associated resources.
 
TextureHandle CreateTexture (int width, int height) override
 Creates a new, empty texture.
 
TextureHandle CreateTextureWithFormat (int width, int height, uint32_t format, int access) override
 Creates a new texture with a specific pixel format.
 
void UpdateTexture (TextureHandle texture, const Bitmap &bitmap) override
 Updates a texture with the pixel data from a Bitmap.
 
void DestroyTexture (TextureHandle texture) override
 Destroys a texture and frees its associated resources.
 
bool LockTexture (TextureHandle texture, SDL_Rect *rect, void **pixels, int *pitch) override
 
void UnlockTexture (TextureHandle texture) override
 
void Clear () override
 Clears the entire render target with the current draw color.
 
void Present () override
 Presents the back buffer to the screen, making the rendered content visible.
 
void RenderCopy (TextureHandle texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect) override
 Copies a portion of a texture to the current render target.
 
void SetRenderTarget (TextureHandle texture) override
 Sets the render target for subsequent drawing operations.
 
void SetDrawColor (SDL_Color color) override
 Sets the color used for drawing operations (e.g., Clear).
 
void * GetBackendRenderer () override
 Provides an escape hatch to get the underlying, concrete renderer object.
 
void SetMetalView (void *view)
 
- Public Member Functions inherited from yaze::gfx::IRenderer
virtual ~IRenderer ()=default
 

Private Attributes

void * metal_view_ = nullptr
 
void * command_queue_ = nullptr
 
TextureHandle render_target_ = nullptr
 

Detailed Description

Definition at line 8 of file metal_renderer.h.

Constructor & Destructor Documentation

◆ MetalRenderer()

yaze::gfx::MetalRenderer::MetalRenderer ( )
default

◆ ~MetalRenderer()

yaze::gfx::MetalRenderer::~MetalRenderer ( )
override

Definition at line 22 of file metal_renderer.mm.

References Shutdown().

Here is the call graph for this function:

Member Function Documentation

◆ Initialize()

bool yaze::gfx::MetalRenderer::Initialize ( SDL_Window * window)
overridevirtual

Initializes the renderer with a given window.

Parameters
windowA pointer to the SDL_Window to render into.
Returns
True if initialization was successful, false otherwise.

Implements yaze::gfx::IRenderer.

Definition at line 26 of file metal_renderer.mm.

References command_queue_, LOG_WARN, and metal_view_.

◆ Shutdown()

void yaze::gfx::MetalRenderer::Shutdown ( )
overridevirtual

Shuts down the renderer and releases all associated resources.

Implements yaze::gfx::IRenderer.

Definition at line 53 of file metal_renderer.mm.

References command_queue_, and render_target_.

Referenced by ~MetalRenderer().

◆ CreateTexture()

TextureHandle yaze::gfx::MetalRenderer::CreateTexture ( int width,
int height )
overridevirtual

Creates a new, empty texture.

Parameters
widthThe width of the texture in pixels.
heightThe height of the texture in pixels.
Returns
An abstract TextureHandle to the newly created texture, or nullptr on failure.

Implements yaze::gfx::IRenderer.

Definition at line 61 of file metal_renderer.mm.

References metal_view_.

Referenced by CreateTextureWithFormat().

◆ CreateTextureWithFormat()

TextureHandle yaze::gfx::MetalRenderer::CreateTextureWithFormat ( int width,
int height,
uint32_t format,
int access )
overridevirtual

Creates a new texture with a specific pixel format.

Parameters
widthThe width of the texture in pixels.
heightThe height of the texture in pixels.
formatThe SDL pixel format (e.g., SDL_PIXELFORMAT_ARGB8888).
accessThe texture access pattern (e.g., SDL_TEXTUREACCESS_STREAMING).
Returns
An abstract TextureHandle to the newly created texture, or nullptr on failure.

Implements yaze::gfx::IRenderer.

Definition at line 94 of file metal_renderer.mm.

References CreateTexture().

Here is the call graph for this function:

◆ UpdateTexture()

void yaze::gfx::MetalRenderer::UpdateTexture ( TextureHandle texture,
const Bitmap & bitmap )
overridevirtual

Updates a texture with the pixel data from a Bitmap.

Parameters
textureThe handle of the texture to update.
bitmapThe Bitmap containing the new pixel data.

Implements yaze::gfx::IRenderer.

Definition at line 102 of file metal_renderer.mm.

References yaze::platform::ConvertSurfaceFormat(), and yaze::gfx::Bitmap::surface().

Here is the call graph for this function:

◆ DestroyTexture()

void yaze::gfx::MetalRenderer::DestroyTexture ( TextureHandle texture)
overridevirtual

Destroys a texture and frees its associated resources.

Parameters
textureThe handle of the texture to destroy.

Implements yaze::gfx::IRenderer.

Definition at line 136 of file metal_renderer.mm.

References render_target_.

◆ LockTexture()

bool yaze::gfx::MetalRenderer::LockTexture ( TextureHandle texture,
SDL_Rect * rect,
void ** pixels,
int * pitch )
overridevirtual

Implements yaze::gfx::IRenderer.

Definition at line 150 of file metal_renderer.mm.

◆ UnlockTexture()

void yaze::gfx::MetalRenderer::UnlockTexture ( TextureHandle texture)
overridevirtual

Implements yaze::gfx::IRenderer.

Definition at line 159 of file metal_renderer.mm.

◆ Clear()

void yaze::gfx::MetalRenderer::Clear ( )
overridevirtual

Clears the entire render target with the current draw color.

Implements yaze::gfx::IRenderer.

Definition at line 163 of file metal_renderer.mm.

◆ Present()

void yaze::gfx::MetalRenderer::Present ( )
overridevirtual

Presents the back buffer to the screen, making the rendered content visible.

Implements yaze::gfx::IRenderer.

Definition at line 166 of file metal_renderer.mm.

◆ RenderCopy()

void yaze::gfx::MetalRenderer::RenderCopy ( TextureHandle texture,
const SDL_Rect * srcrect,
const SDL_Rect * dstrect )
overridevirtual

Copies a portion of a texture to the current render target.

Parameters
textureThe source texture handle.
srcrectA pointer to the source rectangle, or nullptr for the entire texture.
dstrectA pointer to the destination rectangle, or nullptr for the entire render target.

Implements yaze::gfx::IRenderer.

Definition at line 169 of file metal_renderer.mm.

References command_queue_, and render_target_.

◆ SetRenderTarget()

void yaze::gfx::MetalRenderer::SetRenderTarget ( TextureHandle texture)
overridevirtual

Sets the render target for subsequent drawing operations.

Parameters
textureThe texture to set as the render target, or nullptr to set it back to the default (the window).

Implements yaze::gfx::IRenderer.

Definition at line 226 of file metal_renderer.mm.

References render_target_.

◆ SetDrawColor()

void yaze::gfx::MetalRenderer::SetDrawColor ( SDL_Color color)
overridevirtual

Sets the color used for drawing operations (e.g., Clear).

Parameters
colorThe SDL_Color to use.

Implements yaze::gfx::IRenderer.

Definition at line 230 of file metal_renderer.mm.

◆ GetBackendRenderer()

void * yaze::gfx::MetalRenderer::GetBackendRenderer ( )
overridevirtual

Provides an escape hatch to get the underlying, concrete renderer object.

This is necessary for integrating with third-party libraries like ImGui that are tied to a specific rendering backend (e.g., SDL_Renderer*, ID3D11Device*).

Returns
A void pointer to the backend-specific renderer object. The caller is responsible for casting it to the correct type.

Implements yaze::gfx::IRenderer.

Definition at line 234 of file metal_renderer.mm.

References command_queue_.

◆ SetMetalView()

void yaze::gfx::MetalRenderer::SetMetalView ( void * view)

Definition at line 238 of file metal_renderer.mm.

References metal_view_.

Referenced by yaze::platform::IOSWindowBackend::InitializeRenderer().

Member Data Documentation

◆ metal_view_

void* yaze::gfx::MetalRenderer::metal_view_ = nullptr
private

Definition at line 36 of file metal_renderer.h.

Referenced by CreateTexture(), Initialize(), and SetMetalView().

◆ command_queue_

void* yaze::gfx::MetalRenderer::command_queue_ = nullptr
private

Definition at line 37 of file metal_renderer.h.

Referenced by GetBackendRenderer(), Initialize(), RenderCopy(), and Shutdown().

◆ render_target_

TextureHandle yaze::gfx::MetalRenderer::render_target_ = nullptr
private

Definition at line 38 of file metal_renderer.h.

Referenced by DestroyTexture(), RenderCopy(), SetRenderTarget(), and Shutdown().


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