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

A concrete implementation of the IRenderer interface using SDL2. More...

#include <sdl2_renderer.h>

Inheritance diagram for yaze::gfx::SDL2Renderer:
Collaboration diagram for yaze::gfx::SDL2Renderer:

Public Member Functions

 SDL2Renderer ()
 
 ~SDL2Renderer () override
 
bool Initialize (SDL_Window *window) override
 Initializes the SDL2 renderer. This function creates an accelerated SDL2 renderer and attaches it to the given window.
 
void Shutdown () override
 Shuts down the renderer. The underlying SDL_Renderer is managed by a unique_ptr, so its destruction is handled automatically.
 
TextureHandle CreateTexture (int width, int height) override
 Creates an SDL_Texture. The texture is created with streaming access, which is suitable for textures that are updated frequently.
 
TextureHandle CreateTextureWithFormat (int width, int height, uint32_t format, int access) override
 Creates an SDL_Texture with a specific pixel format and access pattern. This is useful for specialized textures like emulator PPU output.
 
void UpdateTexture (TextureHandle texture, const Bitmap &bitmap) override
 Updates an SDL_Texture with data from a Bitmap. This involves converting the bitmap's surface to the correct format and updating the texture.
 
void DestroyTexture (TextureHandle texture) override
 Destroys an SDL_Texture.
 
bool LockTexture (TextureHandle texture, SDL_Rect *rect, void **pixels, int *pitch) override
 
void UnlockTexture (TextureHandle texture) override
 
void Clear () override
 Clears the screen with the current draw color.
 
void Present () override
 Presents the rendered frame to the screen.
 
void RenderCopy (TextureHandle texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect) override
 Copies a texture to the render target.
 
void SetRenderTarget (TextureHandle texture) override
 Sets the render target.
 
void SetDrawColor (SDL_Color color) override
 Sets the draw color.
 
void * GetBackendRenderer () override
 Provides access to the underlying SDL_Renderer*.
 
- Public Member Functions inherited from yaze::gfx::IRenderer
virtual ~IRenderer ()=default
 

Private Attributes

std::unique_ptr< SDL_Renderer, util::SDL_Deleterrenderer_
 

Detailed Description

A concrete implementation of the IRenderer interface using SDL2.

This class encapsulates all rendering logic that is specific to the SDL2_render API. It translates the abstract calls from the IRenderer interface into concrete SDL2 commands. This is the first step in abstracting the renderer, allowing the rest of the application to be independent of SDL2.

Definition at line 18 of file sdl2_renderer.h.

Constructor & Destructor Documentation

◆ SDL2Renderer()

yaze::gfx::SDL2Renderer::SDL2Renderer ( )
default

◆ ~SDL2Renderer()

yaze::gfx::SDL2Renderer::~SDL2Renderer ( )
override

Definition at line 12 of file sdl2_renderer.cc.

References Shutdown().

Here is the call graph for this function:

Member Function Documentation

◆ Initialize()

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

Initializes the SDL2 renderer. This function creates an accelerated SDL2 renderer and attaches it to the given window.

Implements yaze::gfx::IRenderer.

Definition at line 21 of file sdl2_renderer.cc.

References yaze::platform::CreateRenderer(), renderer_, and yaze::platform::SetRenderVSync().

Here is the call graph for this function:

◆ Shutdown()

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

Shuts down the renderer. The underlying SDL_Renderer is managed by a unique_ptr, so its destruction is handled automatically.

Implements yaze::gfx::IRenderer.

Definition at line 45 of file sdl2_renderer.cc.

References renderer_.

Referenced by ~SDL2Renderer().

◆ CreateTexture()

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

Creates an SDL_Texture. The texture is created with streaming access, which is suitable for textures that are updated frequently.

Implements yaze::gfx::IRenderer.

Definition at line 54 of file sdl2_renderer.cc.

References renderer_.

◆ CreateTextureWithFormat()

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

Creates an SDL_Texture with a specific pixel format and access pattern. This is useful for specialized textures like emulator PPU output.

Implements yaze::gfx::IRenderer.

Definition at line 73 of file sdl2_renderer.cc.

References renderer_.

◆ UpdateTexture()

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

Updates an SDL_Texture with data from a Bitmap. This involves converting the bitmap's surface to the correct format and updating the texture.

Implements yaze::gfx::IRenderer.

Definition at line 85 of file sdl2_renderer.cc.

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

Here is the call graph for this function:

◆ DestroyTexture()

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

Destroys an SDL_Texture.

Implements yaze::gfx::IRenderer.

Definition at line 116 of file sdl2_renderer.cc.

◆ LockTexture()

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

Implements yaze::gfx::IRenderer.

Definition at line 122 of file sdl2_renderer.cc.

◆ UnlockTexture()

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

Implements yaze::gfx::IRenderer.

Definition at line 128 of file sdl2_renderer.cc.

◆ Clear()

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

Clears the screen with the current draw color.

Implements yaze::gfx::IRenderer.

Definition at line 135 of file sdl2_renderer.cc.

References renderer_.

◆ Present()

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

Presents the rendered frame to the screen.

Implements yaze::gfx::IRenderer.

Definition at line 142 of file sdl2_renderer.cc.

References renderer_.

◆ RenderCopy()

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

Copies a texture to the render target.

Implements yaze::gfx::IRenderer.

Definition at line 149 of file sdl2_renderer.cc.

References renderer_, and yaze::platform::RenderTexture().

Here is the call graph for this function:

◆ SetRenderTarget()

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

Sets the render target.

Implements yaze::gfx::IRenderer.

Definition at line 158 of file sdl2_renderer.cc.

References renderer_.

◆ SetDrawColor()

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

Sets the draw color.

Implements yaze::gfx::IRenderer.

Definition at line 165 of file sdl2_renderer.cc.

References renderer_.

◆ GetBackendRenderer()

void * yaze::gfx::SDL2Renderer::GetBackendRenderer ( )
inlineoverridevirtual

Provides access to the underlying SDL_Renderer*.

Returns
A void pointer that can be safely cast to an SDL_Renderer*.

Implements yaze::gfx::IRenderer.

Definition at line 51 of file sdl2_renderer.h.

References renderer_.

Member Data Documentation

◆ renderer_

std::unique_ptr<SDL_Renderer, util::SDL_Deleter> yaze::gfx::SDL2Renderer::renderer_
private

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