yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::gfx::IRenderer Interface Referenceabstract

Defines an abstract interface for all rendering operations. More...

#include <irenderer.h>

Inheritance diagram for yaze::gfx::IRenderer:

Public Member Functions

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

Detailed Description

Defines an abstract interface for all rendering operations.

This interface decouples the application from any specific rendering API (like SDL2, SDL3, OpenGL, etc.). It provides a contract for creating textures, managing their lifecycle, and performing primitive drawing operations. The goal is to program against this interface, allowing the concrete rendering backend to be swapped out with minimal changes to the application code.

Definition at line 35 of file irenderer.h.

Constructor & Destructor Documentation

◆ ~IRenderer()

virtual yaze::gfx::IRenderer::~IRenderer ( )
virtualdefault

Member Function Documentation

◆ Initialize()

virtual bool yaze::gfx::IRenderer::Initialize ( SDL_Window *  window)
pure virtual

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.

Implemented in yaze::gfx::SDL2Renderer.

Referenced by yaze::core::CreateWindow().

◆ Shutdown()

virtual void yaze::gfx::IRenderer::Shutdown ( )
pure virtual

Shuts down the renderer and releases all associated resources.

Implemented in yaze::gfx::SDL2Renderer.

◆ CreateTexture()

virtual TextureHandle yaze::gfx::IRenderer::CreateTexture ( int  width,
int  height 
)
pure virtual

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.

Implemented in yaze::gfx::SDL2Renderer.

Referenced by yaze::gfx::AtlasRenderer::CreateNewAtlas(), and yaze::gfx::Arena::ProcessTextureQueue().

◆ CreateTextureWithFormat()

virtual TextureHandle yaze::gfx::IRenderer::CreateTextureWithFormat ( int  width,
int  height,
uint32_t  format,
int  access 
)
pure virtual

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.

Implemented in yaze::gfx::SDL2Renderer.

Referenced by yaze::emu::Emulator::Run().

◆ UpdateTexture()

virtual void yaze::gfx::IRenderer::UpdateTexture ( TextureHandle  texture,
const Bitmap bitmap 
)
pure virtual

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.

Implemented in yaze::gfx::SDL2Renderer.

Referenced by yaze::gfx::Arena::ProcessTextureQueue().

◆ DestroyTexture()

virtual void yaze::gfx::IRenderer::DestroyTexture ( TextureHandle  texture)
pure virtual

Destroys a texture and frees its associated resources.

Parameters
textureThe handle of the texture to destroy.

Implemented in yaze::gfx::SDL2Renderer.

Referenced by yaze::gfx::AtlasRenderer::Clear(), and yaze::gfx::Arena::ProcessTextureQueue().

◆ LockTexture()

virtual bool yaze::gfx::IRenderer::LockTexture ( TextureHandle  texture,
SDL_Rect *  rect,
void **  pixels,
int *  pitch 
)
pure virtual

◆ UnlockTexture()

virtual void yaze::gfx::IRenderer::UnlockTexture ( TextureHandle  texture)
pure virtual

◆ Clear()

virtual void yaze::gfx::IRenderer::Clear ( )
pure virtual

Clears the entire render target with the current draw color.

Implemented in yaze::gfx::SDL2Renderer.

Referenced by yaze::gfx::AtlasRenderer::RebuildAtlas().

◆ Present()

virtual void yaze::gfx::IRenderer::Present ( )
pure virtual

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

Implemented in yaze::gfx::SDL2Renderer.

◆ RenderCopy()

virtual void yaze::gfx::IRenderer::RenderCopy ( TextureHandle  texture,
const SDL_Rect *  srcrect,
const SDL_Rect *  dstrect 
)
pure virtual

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.

Implemented in yaze::gfx::SDL2Renderer.

Referenced by yaze::gfx::AtlasRenderer::AddBitmap(), yaze::gfx::AtlasRenderer::RebuildAtlas(), yaze::gfx::AtlasRenderer::RenderBatch(), yaze::gfx::AtlasRenderer::RenderBatchWithBppOptimization(), and yaze::gfx::AtlasRenderer::RenderBitmap().

◆ SetRenderTarget()

virtual void yaze::gfx::IRenderer::SetRenderTarget ( TextureHandle  texture)
pure virtual

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).

Implemented in yaze::gfx::SDL2Renderer.

Referenced by yaze::gfx::AtlasRenderer::AddBitmap(), and yaze::gfx::AtlasRenderer::RebuildAtlas().

◆ SetDrawColor()

virtual void yaze::gfx::IRenderer::SetDrawColor ( SDL_Color  color)
pure virtual

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

Parameters
colorThe SDL_Color to use.

Implemented in yaze::gfx::SDL2Renderer.

Referenced by yaze::gfx::AtlasRenderer::RebuildAtlas().

◆ GetBackendRenderer()

virtual void * yaze::gfx::IRenderer::GetBackendRenderer ( )
pure virtual

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.

Implemented in yaze::gfx::SDL2Renderer.

Referenced by yaze::core::CreateWindow().


The documentation for this interface was generated from the following file: